Shinichi Fuchita / Twitter

Twitter with OAuth Example.\\ see also http://www.soramimi.jp/twicpp/index.html

Dependencies:   mbed HTTPClient NTPClient_NetServices EthernetNetIf

Committer:
soramimi
Date:
Thu Nov 15 00:51:45 2012 +0000
Revision:
1:c3f74457cad4
Twitter API address changed.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
soramimi0:7ddb56bfde0c 1/**
soramimi0:7ddb56bfde0c 2 * @brief OAuth.net implementation in POSIX-C.
soramimi0:7ddb56bfde0c 3 * @file oauth.h
soramimi0:7ddb56bfde0c 4 * @author Robin Gareus <robin@gareus.org>
soramimi0:7ddb56bfde0c 5 *
soramimi0:7ddb56bfde0c 6 * Copyright 2007-2010 Robin Gareus <robin@gareus.org>
soramimi0:7ddb56bfde0c 7 *
soramimi0:7ddb56bfde0c 8 * Permission is hereby granted, free of charge, to any person obtaining a copy
soramimi0:7ddb56bfde0c 9 * of this software and associated documentation files (the "Software"), to deal
soramimi0:7ddb56bfde0c 10 * in the Software without restriction, including without limitation the rights
soramimi0:7ddb56bfde0c 11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
soramimi0:7ddb56bfde0c 12 * copies of the Software, and to permit persons to whom the Software is
soramimi0:7ddb56bfde0c 13 * furnished to do so, subject to the following conditions:
soramimi0:7ddb56bfde0c 14 *
soramimi0:7ddb56bfde0c 15 * The above copyright notice and this permission notice shall be included in
soramimi0:7ddb56bfde0c 16 * all copies or substantial portions of the Software.
soramimi0:7ddb56bfde0c 17 *
soramimi0:7ddb56bfde0c 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
soramimi0:7ddb56bfde0c 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
soramimi0:7ddb56bfde0c 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
soramimi0:7ddb56bfde0c 21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
soramimi0:7ddb56bfde0c 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
soramimi0:7ddb56bfde0c 23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
soramimi0:7ddb56bfde0c 24 * THE SOFTWARE.
soramimi0:7ddb56bfde0c 25 *
soramimi0:7ddb56bfde0c 26 */
soramimi0:7ddb56bfde0c 27#ifndef _OAUTH_H
soramimi0:7ddb56bfde0c 28#define _OAUTH_H 1
soramimi0:7ddb56bfde0c 29
soramimi0:7ddb56bfde0c 30#include <vector>
soramimi0:7ddb56bfde0c 31#include <string>
soramimi0:7ddb56bfde0c 32
soramimi0:7ddb56bfde0c 33#include <stdlib.h>
soramimi0:7ddb56bfde0c 34
soramimi0:7ddb56bfde0c 35#ifndef DOXYGEN_IGNORE
soramimi0:7ddb56bfde0c 36// liboauth version
soramimi0:7ddb56bfde0c 37#define LIBOAUTH_VERSION "0.8.9"
soramimi0:7ddb56bfde0c 38#define LIBOAUTH_VERSION_MAJOR 0
soramimi0:7ddb56bfde0c 39#define LIBOAUTH_VERSION_MINOR 8
soramimi0:7ddb56bfde0c 40#define LIBOAUTH_VERSION_MICRO 9
soramimi0:7ddb56bfde0c 41
soramimi0:7ddb56bfde0c 42//interface revision number
soramimi0:7ddb56bfde0c 43//http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
soramimi0:7ddb56bfde0c 44#define LIBOAUTH_CUR 7
soramimi0:7ddb56bfde0c 45#define LIBOAUTH_REV 0
soramimi0:7ddb56bfde0c 46#define LIBOAUTH_AGE 7
soramimi0:7ddb56bfde0c 47#endif
soramimi0:7ddb56bfde0c 48
soramimi0:7ddb56bfde0c 49#ifdef __GNUC__
soramimi0:7ddb56bfde0c 50# define OA_GCC_VERSION_AT_LEAST(x,y) (__GNUC__ > x || __GNUC__ == x && __GNUC_MINOR__ >= y)
soramimi0:7ddb56bfde0c 51#else
soramimi0:7ddb56bfde0c 52# define OA_GCC_VERSION_AT_LEAST(x,y) 0
soramimi0:7ddb56bfde0c 53#endif
soramimi0:7ddb56bfde0c 54
soramimi0:7ddb56bfde0c 55#ifndef attribute_deprecated
soramimi0:7ddb56bfde0c 56#if OA_GCC_VERSION_AT_LEAST(3,1)
soramimi0:7ddb56bfde0c 57# define attribute_deprecated __attribute__((deprecated))
soramimi0:7ddb56bfde0c 58#else
soramimi0:7ddb56bfde0c 59# define attribute_deprecated
soramimi0:7ddb56bfde0c 60#endif
soramimi0:7ddb56bfde0c 61#endif
soramimi0:7ddb56bfde0c 62
soramimi0:7ddb56bfde0c 63/** \enum OAuthMethod
soramimi0:7ddb56bfde0c 64 * signature method to used for signing the request.
soramimi0:7ddb56bfde0c 65 */
soramimi0:7ddb56bfde0c 66typedef enum {
soramimi0:7ddb56bfde0c 67 OA_HMAC=0, ///< use HMAC-SHA1 request signing method
soramimi0:7ddb56bfde0c 68 OA_RSA, ///< use RSA signature
soramimi0:7ddb56bfde0c 69 OA_PLAINTEXT ///< use plain text signature (for testing only)
soramimi0:7ddb56bfde0c 70 } OAuthMethod;
soramimi0:7ddb56bfde0c 71
soramimi0:7ddb56bfde0c 72/**
soramimi0:7ddb56bfde0c 73 * Base64 encode and return size data in 'src'. The caller must free the
soramimi0:7ddb56bfde0c 74 * returned string.
soramimi0:7ddb56bfde0c 75 *
soramimi0:7ddb56bfde0c 76 * @param size The size of the data in src
soramimi0:7ddb56bfde0c 77 * @param src The data to be base64 encode
soramimi0:7ddb56bfde0c 78 * @return encoded string otherwise NULL
soramimi0:7ddb56bfde0c 79 */
soramimi0:7ddb56bfde0c 80std::string oauth_encode_base64(const unsigned char *src, int size);
soramimi0:7ddb56bfde0c 81
soramimi0:7ddb56bfde0c 82/**
soramimi0:7ddb56bfde0c 83 * Decode the base64 encoded string 'src' into the memory pointed to by
soramimi0:7ddb56bfde0c 84 * 'dest'.
soramimi0:7ddb56bfde0c 85 *
soramimi0:7ddb56bfde0c 86 * @param dest Pointer to memory for holding the decoded string.
soramimi0:7ddb56bfde0c 87 * Must be large enough to receive the decoded string.
soramimi0:7ddb56bfde0c 88 * @param src A base64 encoded string.
soramimi0:7ddb56bfde0c 89 * @return the length of the decoded string if decode
soramimi0:7ddb56bfde0c 90 * succeeded otherwise 0.
soramimi0:7ddb56bfde0c 91 */
soramimi0:7ddb56bfde0c 92std::string oauth_decode_base64(const char *src);
soramimi0:7ddb56bfde0c 93
soramimi0:7ddb56bfde0c 94/**
soramimi0:7ddb56bfde0c 95 * Escape 'string' according to RFC3986 and
soramimi0:7ddb56bfde0c 96 * http://oauth.net/core/1.0/#encoding_parameters.
soramimi0:7ddb56bfde0c 97 *
soramimi0:7ddb56bfde0c 98 * @param string The data to be encoded
soramimi0:7ddb56bfde0c 99 * @return encoded string otherwise NULL
soramimi0:7ddb56bfde0c 100 * The caller must free the returned string.
soramimi0:7ddb56bfde0c 101 */
soramimi0:7ddb56bfde0c 102std::string oauth_url_escape(const char *string);
soramimi0:7ddb56bfde0c 103
soramimi0:7ddb56bfde0c 104/**
soramimi0:7ddb56bfde0c 105 * Parse RFC3986 encoded 'string' back to unescaped version.
soramimi0:7ddb56bfde0c 106 *
soramimi0:7ddb56bfde0c 107 * @param string The data to be unescaped
soramimi0:7ddb56bfde0c 108 * @param olen unless NULL the length of the returned string is stored there.
soramimi0:7ddb56bfde0c 109 * @return decoded string or NULL
soramimi0:7ddb56bfde0c 110 * The caller must free the returned string.
soramimi0:7ddb56bfde0c 111 */
soramimi0:7ddb56bfde0c 112std::string oauth_url_unescape(const char *string);
soramimi0:7ddb56bfde0c 113
soramimi0:7ddb56bfde0c 114
soramimi0:7ddb56bfde0c 115/**
soramimi0:7ddb56bfde0c 116 * returns base64 encoded HMAC-SHA1 signature for
soramimi0:7ddb56bfde0c 117 * given message and key.
soramimi0:7ddb56bfde0c 118 * both data and key need to be urlencoded.
soramimi0:7ddb56bfde0c 119 *
soramimi0:7ddb56bfde0c 120 * the returned string needs to be freed by the caller
soramimi0:7ddb56bfde0c 121 *
soramimi0:7ddb56bfde0c 122 * @param m message to be signed
soramimi0:7ddb56bfde0c 123 * @param k key used for signing
soramimi0:7ddb56bfde0c 124 * @return signature string.
soramimi0:7ddb56bfde0c 125 */
soramimi0:7ddb56bfde0c 126std::string oauth_sign_hmac_sha1 (const char *m, const char *k);
soramimi0:7ddb56bfde0c 127
soramimi0:7ddb56bfde0c 128/**
soramimi0:7ddb56bfde0c 129 * same as \ref oauth_sign_hmac_sha1 but allows
soramimi0:7ddb56bfde0c 130 * to specify length of message and key (in case they contain null chars).
soramimi0:7ddb56bfde0c 131 *
soramimi0:7ddb56bfde0c 132 * @param m message to be signed
soramimi0:7ddb56bfde0c 133 * @param ml length of message
soramimi0:7ddb56bfde0c 134 * @param k key used for signing
soramimi0:7ddb56bfde0c 135 * @param kl length of key
soramimi0:7ddb56bfde0c 136 * @return signature string.
soramimi0:7ddb56bfde0c 137 */
soramimi0:7ddb56bfde0c 138std::string oauth_sign_hmac_sha1_raw(const char *m, const size_t ml, const char *k, const size_t kl);
soramimi0:7ddb56bfde0c 139
soramimi0:7ddb56bfde0c 140/**
soramimi0:7ddb56bfde0c 141 * returns plaintext signature for the given key.
soramimi0:7ddb56bfde0c 142 *
soramimi0:7ddb56bfde0c 143 * the returned string needs to be freed by the caller
soramimi0:7ddb56bfde0c 144 *
soramimi0:7ddb56bfde0c 145 * @param m message to be signed
soramimi0:7ddb56bfde0c 146 * @param k key used for signing
soramimi0:7ddb56bfde0c 147 * @return signature string
soramimi0:7ddb56bfde0c 148 */
soramimi0:7ddb56bfde0c 149std::string oauth_sign_plaintext(const char *m, const char *k);
soramimi0:7ddb56bfde0c 150
soramimi0:7ddb56bfde0c 151/**
soramimi0:7ddb56bfde0c 152 * returns RSA-SHA1 signature for given data.
soramimi0:7ddb56bfde0c 153 * the returned signature needs to be freed by the caller.
soramimi0:7ddb56bfde0c 154 *
soramimi0:7ddb56bfde0c 155 * @param m message to be signed
soramimi0:7ddb56bfde0c 156 * @param k private-key PKCS and Base64-encoded
soramimi0:7ddb56bfde0c 157 * @return base64 encoded signature string.
soramimi0:7ddb56bfde0c 158 */
soramimi0:7ddb56bfde0c 159//std::string oauth_sign_rsa_sha1 (const char *m, const char *k);
soramimi0:7ddb56bfde0c 160
soramimi0:7ddb56bfde0c 161/**
soramimi0:7ddb56bfde0c 162 * verify RSA-SHA1 signature.
soramimi0:7ddb56bfde0c 163 *
soramimi0:7ddb56bfde0c 164 * returns the output of EVP_VerifyFinal() for a given message,
soramimi0:7ddb56bfde0c 165 * cert/pubkey and signature.
soramimi0:7ddb56bfde0c 166 *
soramimi0:7ddb56bfde0c 167 * @param m message to be verified
soramimi0:7ddb56bfde0c 168 * @param c public-key or x509 certificate
soramimi0:7ddb56bfde0c 169 * @param s base64 encoded signature
soramimi0:7ddb56bfde0c 170 * @return 1 for a correct signature, 0 for failure and -1 if some other error occurred
soramimi0:7ddb56bfde0c 171 */
soramimi0:7ddb56bfde0c 172int oauth_verify_rsa_sha1(const char *m, const char *c, const char *s);
soramimi0:7ddb56bfde0c 173
soramimi0:7ddb56bfde0c 174/**
soramimi0:7ddb56bfde0c 175 * url-escape strings and concatenate with '&' separator.
soramimi0:7ddb56bfde0c 176 * The number of strings to be concatenated must be
soramimi0:7ddb56bfde0c 177 * given as first argument.
soramimi0:7ddb56bfde0c 178 * all arguments thereafter must be of type (char *)
soramimi0:7ddb56bfde0c 179 *
soramimi0:7ddb56bfde0c 180 * @param len the number of arguments to follow this parameter
soramimi0:7ddb56bfde0c 181 *
soramimi0:7ddb56bfde0c 182 * @return pointer to memory holding the concatenated
soramimi0:7ddb56bfde0c 183 * strings - needs to be free(d) by the caller. or NULL
soramimi0:7ddb56bfde0c 184 * in case we ran out of memory.
soramimi0:7ddb56bfde0c 185 */
soramimi0:7ddb56bfde0c 186std::string oauth_catenc(int len, ...);
soramimi0:7ddb56bfde0c 187
soramimi0:7ddb56bfde0c 188/**
soramimi0:7ddb56bfde0c 189 * splits the given url into a parameter array.
soramimi0:7ddb56bfde0c 190 * (see \ref oauth_serialize_url and \ref oauth_serialize_url_parameters for the reverse)
soramimi0:7ddb56bfde0c 191 * (see \ref oauth_split_post_paramters for a more generic version)
soramimi0:7ddb56bfde0c 192 *
soramimi0:7ddb56bfde0c 193 * @param url the url or query-string to parse; may be NULL
soramimi0:7ddb56bfde0c 194 * @param argv pointer to a (char *) array where the results are stored.
soramimi0:7ddb56bfde0c 195 * The array is re-allocated to match the number of parameters and each
soramimi0:7ddb56bfde0c 196 * parameter-string is allocated with strdup. - The memory needs to be freed
soramimi0:7ddb56bfde0c 197 * by the caller.
soramimi0:7ddb56bfde0c 198 *
soramimi0:7ddb56bfde0c 199 * @return number of parameter(s) in array.
soramimi0:7ddb56bfde0c 200 */
soramimi0:7ddb56bfde0c 201void oauth_split_url_parameters(const char *url, char ***argv);
soramimi0:7ddb56bfde0c 202
soramimi0:7ddb56bfde0c 203/**
soramimi0:7ddb56bfde0c 204 * splits the given url into a parameter array.
soramimi0:7ddb56bfde0c 205 * (see \ref oauth_serialize_url and \ref oauth_serialize_url_parameters for the reverse)
soramimi0:7ddb56bfde0c 206 *
soramimi0:7ddb56bfde0c 207 * @param url the url or query-string to parse.
soramimi0:7ddb56bfde0c 208 * @param argv pointer to a (char *) array where the results are stored.
soramimi0:7ddb56bfde0c 209 * The array is re-allocated to match the number of parameters and each
soramimi0:7ddb56bfde0c 210 * parameter-string is allocated with strdup. - The memory needs to be freed
soramimi0:7ddb56bfde0c 211 * by the caller.
soramimi0:7ddb56bfde0c 212 * @param qesc use query parameter escape (vs post-param-escape) - if set
soramimi0:7ddb56bfde0c 213 * to 1 all '+' are treated as spaces ' '
soramimi0:7ddb56bfde0c 214 *
soramimi0:7ddb56bfde0c 215 * @return number of parameter(s) in array.
soramimi0:7ddb56bfde0c 216 */
soramimi0:7ddb56bfde0c 217void oauth_split_post_paramters(const char *url, char ***argv, short qesc);
soramimi0:7ddb56bfde0c 218
soramimi0:7ddb56bfde0c 219/**
soramimi0:7ddb56bfde0c 220 * build a url query string from an array.
soramimi0:7ddb56bfde0c 221 *
soramimi0:7ddb56bfde0c 222 * @param argc the total number of elements in the array
soramimi0:7ddb56bfde0c 223 * @param start element in the array at which to start concatenating.
soramimi0:7ddb56bfde0c 224 * @param argv parameter-array to concatenate.
soramimi0:7ddb56bfde0c 225 * @return url string needs to be freed by the caller.
soramimi0:7ddb56bfde0c 226 *
soramimi0:7ddb56bfde0c 227 */
soramimi0:7ddb56bfde0c 228std::string oauth_serialize_url (std::vector<std::string> const &argv, int start);
soramimi0:7ddb56bfde0c 229
soramimi0:7ddb56bfde0c 230/**
soramimi0:7ddb56bfde0c 231 * encode query parameters from an array.
soramimi0:7ddb56bfde0c 232 *
soramimi0:7ddb56bfde0c 233 * @param argc the total number of elements in the array
soramimi0:7ddb56bfde0c 234 * @param start element in the array at which to start concatenating.
soramimi0:7ddb56bfde0c 235 * @param argv parameter-array to concatenate.
soramimi0:7ddb56bfde0c 236 * @param sep separator for parameters (usually "&")
soramimi0:7ddb56bfde0c 237 * @param mod - bitwise modifiers:
soramimi0:7ddb56bfde0c 238 * 1: skip all values that start with "oauth_"
soramimi0:7ddb56bfde0c 239 * 2: skip all values that don't start with "oauth_"
soramimi0:7ddb56bfde0c 240 * 4: double quotation marks are added around values (use with sep ", " for HTTP Authorization header).
soramimi0:7ddb56bfde0c 241 * @return url string needs to be freed by the caller.
soramimi0:7ddb56bfde0c 242 */
soramimi0:7ddb56bfde0c 243std::string oauth_serialize_url_sep (std::vector<std::string> const &argv, int start, char const *sep, int mod);
soramimi0:7ddb56bfde0c 244
soramimi0:7ddb56bfde0c 245/**
soramimi0:7ddb56bfde0c 246 * build a query parameter string from an array.
soramimi0:7ddb56bfde0c 247 *
soramimi0:7ddb56bfde0c 248 * This function is a shortcut for \ref oauth_serialize_url (argc, 1, argv).
soramimi0:7ddb56bfde0c 249 * It strips the leading host/path, which is usually the first
soramimi0:7ddb56bfde0c 250 * element when using oauth_split_url_parameters on an URL.
soramimi0:7ddb56bfde0c 251 *
soramimi0:7ddb56bfde0c 252 * @param argc the total number of elements in the array
soramimi0:7ddb56bfde0c 253 * @param argv parameter-array to concatenate.
soramimi0:7ddb56bfde0c 254 * @return url string needs to be freed by the caller.
soramimi0:7ddb56bfde0c 255 */
soramimi0:7ddb56bfde0c 256std::string oauth_serialize_url_parameters (std::vector<std::string> const &argv);
soramimi0:7ddb56bfde0c 257
soramimi0:7ddb56bfde0c 258/**
soramimi0:7ddb56bfde0c 259 * generate a random string between 15 and 32 chars length
soramimi0:7ddb56bfde0c 260 * and return a pointer to it. The value needs to be freed by the
soramimi0:7ddb56bfde0c 261 * caller
soramimi0:7ddb56bfde0c 262 *
soramimi0:7ddb56bfde0c 263 * @return zero terminated random string.
soramimi0:7ddb56bfde0c 264 */
soramimi0:7ddb56bfde0c 265std::string oauth_gen_nonce();
soramimi0:7ddb56bfde0c 266
soramimi0:7ddb56bfde0c 267/**
soramimi0:7ddb56bfde0c 268 * string compare function for oauth parameters.
soramimi0:7ddb56bfde0c 269 *
soramimi0:7ddb56bfde0c 270 * used with qsort. needed to normalize request parameters.
soramimi0:7ddb56bfde0c 271 * see http://oauth.net/core/1.0/#anchor14
soramimi0:7ddb56bfde0c 272 */
soramimi0:7ddb56bfde0c 273int oauth_cmpstringp(const void *p1, const void *p2);
soramimi0:7ddb56bfde0c 274
soramimi0:7ddb56bfde0c 275
soramimi0:7ddb56bfde0c 276/**
soramimi0:7ddb56bfde0c 277 * search array for parameter key.
soramimi0:7ddb56bfde0c 278 * @param argv length of array to search
soramimi0:7ddb56bfde0c 279 * @param argc parameter array to search
soramimi0:7ddb56bfde0c 280 * @param key key of parameter to check.
soramimi0:7ddb56bfde0c 281 *
soramimi0:7ddb56bfde0c 282 * @return FALSE (0) if array does not contain a parameter with given key, TRUE (1) otherwise.
soramimi0:7ddb56bfde0c 283 */
soramimi0:7ddb56bfde0c 284bool oauth_param_exists(std::vector<std::string> const &argv, char const *key);
soramimi0:7ddb56bfde0c 285
soramimi0:7ddb56bfde0c 286/**
soramimi0:7ddb56bfde0c 287 * free array args
soramimi0:7ddb56bfde0c 288 *
soramimi0:7ddb56bfde0c 289 * @param argcp pointer to array length int
soramimi0:7ddb56bfde0c 290 * @param argvp pointer to array values to be free()d
soramimi0:7ddb56bfde0c 291 */
soramimi0:7ddb56bfde0c 292void oauth_free_array(int *argcp, std::vector<std::string> *argvp);
soramimi0:7ddb56bfde0c 293
soramimi0:7ddb56bfde0c 294/**
soramimi0:7ddb56bfde0c 295 * calculate OAuth-signature for a given HTTP request URL, parameters and oauth-tokens.
soramimi0:7ddb56bfde0c 296 *
soramimi0:7ddb56bfde0c 297 * if 'postargs' is NULL a "GET" request is signed and the
soramimi0:7ddb56bfde0c 298 * signed URL is returned. Else this fn will modify 'postargs'
soramimi0:7ddb56bfde0c 299 * to point to memory that contains the signed POST-variables
soramimi0:7ddb56bfde0c 300 * and returns the base URL.
soramimi0:7ddb56bfde0c 301 *
soramimi0:7ddb56bfde0c 302 * both, the return value and (if given) 'postargs' need to be freed
soramimi0:7ddb56bfde0c 303 * by the caller.
soramimi0:7ddb56bfde0c 304 *
soramimi0:7ddb56bfde0c 305 * @param url The request URL to be signed. append all GET or POST
soramimi0:7ddb56bfde0c 306 * query-parameters separated by either '?' or '&' to this parameter.
soramimi0:7ddb56bfde0c 307 *
soramimi0:7ddb56bfde0c 308 * @param postargs This parameter points to an area where the return value
soramimi0:7ddb56bfde0c 309 * is stored. If 'postargs' is NULL, no value is stored.
soramimi0:7ddb56bfde0c 310 *
soramimi0:7ddb56bfde0c 311 * @param method specify the signature method to use. It is of type
soramimi0:7ddb56bfde0c 312 * \ref OAuthMethod and most likely \ref OA_HMAC.
soramimi0:7ddb56bfde0c 313 *
soramimi0:7ddb56bfde0c 314 * @param http_method The HTTP request method to use (ie "GET", "PUT",..)
soramimi0:7ddb56bfde0c 315 * If NULL is given as 'http_method' this defaults to "GET" when
soramimi0:7ddb56bfde0c 316 * 'postargs' is also NULL and when postargs is not NULL "POST" is used.
soramimi0:7ddb56bfde0c 317 *
soramimi0:7ddb56bfde0c 318 * @param c_key consumer key
soramimi0:7ddb56bfde0c 319 * @param c_secret consumer secret
soramimi0:7ddb56bfde0c 320 * @param t_key token key
soramimi0:7ddb56bfde0c 321 * @param t_secret token secret
soramimi0:7ddb56bfde0c 322 *
soramimi0:7ddb56bfde0c 323 * @return the signed url or NULL if an error occurred.
soramimi0:7ddb56bfde0c 324 *
soramimi0:7ddb56bfde0c 325 */
soramimi0:7ddb56bfde0c 326std::string oauth_sign_url2 (const char *url, std::string *postargs,
soramimi0:7ddb56bfde0c 327 OAuthMethod method,
soramimi0:7ddb56bfde0c 328 const char *http_method, //< HTTP request method
soramimi0:7ddb56bfde0c 329 const char *c_key, //< consumer key - posted plain text
soramimi0:7ddb56bfde0c 330 const char *c_secret, //< consumer secret - used as 1st part of secret-key
soramimi0:7ddb56bfde0c 331 const char *t_key, //< token key - posted plain text in URL
soramimi0:7ddb56bfde0c 332 const char *t_secret //< token secret - used as 2st part of secret-key
soramimi0:7ddb56bfde0c 333 );
soramimi0:7ddb56bfde0c 334
soramimi0:7ddb56bfde0c 335/**
soramimi0:7ddb56bfde0c 336 * @deprecated Use oauth_sign_url2() instead.
soramimi0:7ddb56bfde0c 337 */
soramimi0:7ddb56bfde0c 338std::string oauth_sign_url (const char *url, std::string *postargs,
soramimi0:7ddb56bfde0c 339 OAuthMethod method,
soramimi0:7ddb56bfde0c 340 const char *c_key, //< consumer key - posted plain text
soramimi0:7ddb56bfde0c 341 const char *c_secret, //< consumer secret - used as 1st part of secret-key
soramimi0:7ddb56bfde0c 342 const char *t_key, //< token key - posted plain text in URL
soramimi0:7ddb56bfde0c 343 const char *t_secret //< token secret - used as 2st part of secret-key
soramimi0:7ddb56bfde0c 344 ) attribute_deprecated;
soramimi0:7ddb56bfde0c 345
soramimi0:7ddb56bfde0c 346
soramimi0:7ddb56bfde0c 347/**
soramimi0:7ddb56bfde0c 348 * the back-end behind by /ref oauth_sign_array2.
soramimi0:7ddb56bfde0c 349 * however it does not serialize the signed URL again.
soramimi0:7ddb56bfde0c 350 * The user needs to call /ref oauth_serialize_url (oA)
soramimi0:7ddb56bfde0c 351 * and /ref oauth_free_array to do so.
soramimi0:7ddb56bfde0c 352 *
soramimi0:7ddb56bfde0c 353 * This allows to split parts of the URL to be used for
soramimi0:7ddb56bfde0c 354 * OAuth HTTP Authorization header:
soramimi0:7ddb56bfde0c 355 * see http://oauth.net/core/1.0a/#consumer_req_param
soramimi0:7ddb56bfde0c 356 * the oauthtest2 example code does so.
soramimi0:7ddb56bfde0c 357 *
soramimi0:7ddb56bfde0c 358 *
soramimi0:7ddb56bfde0c 359 * @param argcp pointer to array length int
soramimi0:7ddb56bfde0c 360 * @param argvp pointer to array values
soramimi0:7ddb56bfde0c 361 * (argv[0]="http://example.org:80/" argv[1]="first=QueryParamater" ..
soramimi0:7ddb56bfde0c 362 * the array is modified: fi. oauth_ parameters are added)
soramimi0:7ddb56bfde0c 363 * These arrays can be generated with /ref oauth_split_url_parameters
soramimi0:7ddb56bfde0c 364 * or /ref oauth_split_post_paramters.
soramimi0:7ddb56bfde0c 365 *
soramimi0:7ddb56bfde0c 366 * @param postargs This parameter points to an area where the return value
soramimi0:7ddb56bfde0c 367 * is stored. If 'postargs' is NULL, no value is stored.
soramimi0:7ddb56bfde0c 368 *
soramimi0:7ddb56bfde0c 369 * @param method specify the signature method to use. It is of type
soramimi0:7ddb56bfde0c 370 * \ref OAuthMethod and most likely \ref OA_HMAC.
soramimi0:7ddb56bfde0c 371 *
soramimi0:7ddb56bfde0c 372 * @param http_method The HTTP request method to use (ie "GET", "PUT",..)
soramimi0:7ddb56bfde0c 373 * If NULL is given as 'http_method' this defaults to "GET" when
soramimi0:7ddb56bfde0c 374 * 'postargs' is also NULL and when postargs is not NULL "POST" is used.
soramimi0:7ddb56bfde0c 375 *
soramimi0:7ddb56bfde0c 376 * @param c_key consumer key
soramimi0:7ddb56bfde0c 377 * @param c_secret consumer secret
soramimi0:7ddb56bfde0c 378 * @param t_key token key
soramimi0:7ddb56bfde0c 379 * @param t_secret token secret
soramimi0:7ddb56bfde0c 380 *
soramimi0:7ddb56bfde0c 381 * @return void
soramimi0:7ddb56bfde0c 382 *
soramimi0:7ddb56bfde0c 383 */
soramimi0:7ddb56bfde0c 384void oauth_sign_array2_process (std::vector<std::string> *argvp,
soramimi0:7ddb56bfde0c 385 std::string *postargs,
soramimi0:7ddb56bfde0c 386 OAuthMethod method,
soramimi0:7ddb56bfde0c 387 const char *http_method, //< HTTP request method
soramimi0:7ddb56bfde0c 388 const char *c_key, //< consumer key - posted plain text
soramimi0:7ddb56bfde0c 389 const char *c_secret, //< consumer secret - used as 1st part of secret-key
soramimi0:7ddb56bfde0c 390 const char *t_key, //< token key - posted plain text in URL
soramimi0:7ddb56bfde0c 391 const char *t_secret //< token secret - used as 2st part of secret-key
soramimi0:7ddb56bfde0c 392 );
soramimi0:7ddb56bfde0c 393
soramimi0:7ddb56bfde0c 394/**
soramimi0:7ddb56bfde0c 395 * same as /ref oauth_sign_url
soramimi0:7ddb56bfde0c 396 * with the url already split into parameter array
soramimi0:7ddb56bfde0c 397 *
soramimi0:7ddb56bfde0c 398 * @param argcp pointer to array length int
soramimi0:7ddb56bfde0c 399 * @param argvp pointer to array values
soramimi0:7ddb56bfde0c 400 * (argv[0]="http://example.org:80/" argv[1]="first=QueryParamater" ..
soramimi0:7ddb56bfde0c 401 * the array is modified: fi. oauth_ parameters are added)
soramimi0:7ddb56bfde0c 402 * These arrays can be generated with /ref oauth_split_url_parameters
soramimi0:7ddb56bfde0c 403 * or /ref oauth_split_post_paramters.
soramimi0:7ddb56bfde0c 404 *
soramimi0:7ddb56bfde0c 405 * @param postargs This parameter points to an area where the return value
soramimi0:7ddb56bfde0c 406 * is stored. If 'postargs' is NULL, no value is stored.
soramimi0:7ddb56bfde0c 407 *
soramimi0:7ddb56bfde0c 408 * @param method specify the signature method to use. It is of type
soramimi0:7ddb56bfde0c 409 * \ref OAuthMethod and most likely \ref OA_HMAC.
soramimi0:7ddb56bfde0c 410 *
soramimi0:7ddb56bfde0c 411 * @param http_method The HTTP request method to use (ie "GET", "PUT",..)
soramimi0:7ddb56bfde0c 412 * If NULL is given as 'http_method' this defaults to "GET" when
soramimi0:7ddb56bfde0c 413 * 'postargs' is also NULL and when postargs is not NULL "POST" is used.
soramimi0:7ddb56bfde0c 414 *
soramimi0:7ddb56bfde0c 415 * @param c_key consumer key
soramimi0:7ddb56bfde0c 416 * @param c_secret consumer secret
soramimi0:7ddb56bfde0c 417 * @param t_key token key
soramimi0:7ddb56bfde0c 418 * @param t_secret token secret
soramimi0:7ddb56bfde0c 419 *
soramimi0:7ddb56bfde0c 420 * @return the signed url or NULL if an error occurred.
soramimi0:7ddb56bfde0c 421 */
soramimi0:7ddb56bfde0c 422std::string oauth_sign_array2 (std::vector<std::string> *argvp,
soramimi0:7ddb56bfde0c 423 std::string *postargs,
soramimi0:7ddb56bfde0c 424 OAuthMethod method,
soramimi0:7ddb56bfde0c 425 const char *http_method, //< HTTP request method
soramimi0:7ddb56bfde0c 426 const char *c_key, //< consumer key - posted plain text
soramimi0:7ddb56bfde0c 427 const char *c_secret, //< consumer secret - used as 1st part of secret-key
soramimi0:7ddb56bfde0c 428 const char *t_key, //< token key - posted plain text in URL
soramimi0:7ddb56bfde0c 429 const char *t_secret //< token secret - used as 2st part of secret-key
soramimi0:7ddb56bfde0c 430 );
soramimi0:7ddb56bfde0c 431
soramimi0:7ddb56bfde0c 432/**
soramimi0:7ddb56bfde0c 433 * @deprecated Use oauth_sign_array2() instead.
soramimi0:7ddb56bfde0c 434 */
soramimi0:7ddb56bfde0c 435char *oauth_sign_array(
soramimi0:7ddb56bfde0c 436 std::vector<std::string> *argvp,
soramimi0:7ddb56bfde0c 437 char **postargs,
soramimi0:7ddb56bfde0c 438 OAuthMethod method,
soramimi0:7ddb56bfde0c 439 const char *c_key, //< consumer key - posted plain text
soramimi0:7ddb56bfde0c 440 const char *c_secret, //< consumer secret - used as 1st part of secret-key
soramimi0:7ddb56bfde0c 441 const char *t_key, //< token key - posted plain text in URL
soramimi0:7ddb56bfde0c 442 const char *t_secret //< token secret - used as 2st part of secret-key
soramimi0:7ddb56bfde0c 443 ) attribute_deprecated;
soramimi0:7ddb56bfde0c 444
soramimi0:7ddb56bfde0c 445/**
soramimi0:7ddb56bfde0c 446 * do a HTTP POST request, wait for it to finish
soramimi0:7ddb56bfde0c 447 * and return the content of the reply.
soramimi0:7ddb56bfde0c 448 * (requires libcurl or a command-line HTTP client)
soramimi0:7ddb56bfde0c 449 *
soramimi0:7ddb56bfde0c 450 * If compiled <b>without</b> libcurl this function calls
soramimi0:7ddb56bfde0c 451 * a command-line executable defined in the environment variable
soramimi0:7ddb56bfde0c 452 * OAUTH_HTTP_CMD - it defaults to
soramimi0:7ddb56bfde0c 453 * <tt>curl -sA 'liboauth-agent/0.1' -d '%%p' '%%u'</tt>
soramimi0:7ddb56bfde0c 454 * where %%p is replaced with the postargs and %%u is replaced with
soramimi0:7ddb56bfde0c 455 * the URL.
soramimi0:7ddb56bfde0c 456 *
soramimi0:7ddb56bfde0c 457 * bash & wget example:
soramimi0:7ddb56bfde0c 458 * <tt>export OAUTH_HTTP_CMD="wget -q -U 'liboauth-agent/0.1' --post-data='%p' '%u' "</tt>
soramimi0:7ddb56bfde0c 459 *
soramimi0:7ddb56bfde0c 460 * NOTE: This function uses the curl's default HTTP-POST Content-Type:
soramimi0:7ddb56bfde0c 461 * application/x-www-form-urlencoded which is the only option allowed
soramimi0:7ddb56bfde0c 462 * by oauth core 1.0 spec. Experimental code can use the Environment variable
soramimi0:7ddb56bfde0c 463 * to transmit custom HTTP headers or parameters.
soramimi0:7ddb56bfde0c 464 *
soramimi0:7ddb56bfde0c 465 * WARNING: this is a tentative function. it's convenient and handy for testing
soramimi0:7ddb56bfde0c 466 * or developing OAuth code. But don't rely on this function
soramimi0:7ddb56bfde0c 467 * to become a stable part of this API. It does not do
soramimi0:7ddb56bfde0c 468 * much error checking for one thing..
soramimi0:7ddb56bfde0c 469 *
soramimi0:7ddb56bfde0c 470 * @param u url to query
soramimi0:7ddb56bfde0c 471 * @param p postargs to send along with the HTTP request.
soramimi0:7ddb56bfde0c 472 * @return replied content from HTTP server. needs to be freed by caller.
soramimi0:7ddb56bfde0c 473 */
soramimi0:7ddb56bfde0c 474std::string oauth_http_post(const char *u, const char *p);
soramimi0:7ddb56bfde0c 475
soramimi0:7ddb56bfde0c 476#endif