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