OAuth library functions  1.0.3
oauth.h
Go to the documentation of this file.
1 
27 #ifndef _OAUTH_H
28 #define _OAUTH_H 1
29 
30 #ifndef DOXYGEN_IGNORE
31 // liboauth version
32 #define LIBOAUTH_VERSION "1.0.3"
33 #define LIBOAUTH_VERSION_MAJOR 1
34 #define LIBOAUTH_VERSION_MINOR 0
35 #define LIBOAUTH_VERSION_MICRO 3
36 
37 //interface revision number
38 //http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
39 #define LIBOAUTH_CUR 8
40 #define LIBOAUTH_REV 7
41 #define LIBOAUTH_AGE 8
42 
43 #ifdef __GNUC__
44 # define OA_GCC_VERSION_AT_LEAST(x,y) (__GNUC__ > x || __GNUC__ == x && __GNUC_MINOR__ >= y)
45 #else
46 # define OA_GCC_VERSION_AT_LEAST(x,y) 0
47 #endif
48 
49 #ifndef attribute_deprecated
50 #if OA_GCC_VERSION_AT_LEAST(3,1)
51 # define attribute_deprecated __attribute__((deprecated))
52 #else
53 # define attribute_deprecated
54 #endif
55 #endif
56 
57 #endif /* doxygen ignore */
58 
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62 
66 typedef enum {
67  OA_HMAC=0,
71 
80 char *oauth_encode_base64(int size, const unsigned char *src);
81 
92 int oauth_decode_base64(unsigned char *dest, const char *src);
93 
102 char *oauth_url_escape(const char *string);
103 
112 char *oauth_url_unescape(const char *string, size_t *olen);
113 
114 
126 char *oauth_sign_hmac_sha1 (const char *m, const char *k);
127 
138 char *oauth_sign_hmac_sha1_raw (const char *m, const size_t ml, const char *k, const size_t kl);
139 
149 char *oauth_sign_plaintext (const char *m, const char *k);
150 
159 char *oauth_sign_rsa_sha1 (const char *m, const char *k);
160 
172 int oauth_verify_rsa_sha1 (const char *m, const char *c, const char *s);
173 
186 char *oauth_catenc(int len, ...);
187 
201 int oauth_split_url_parameters(const char *url, char ***argv);
202 
217 int oauth_split_post_paramters(const char *url, char ***argv, short qesc);
218 
228 char *oauth_serialize_url (int argc, int start, char **argv);
229 
243 char *oauth_serialize_url_sep (int argc, int start, char **argv, char *sep, int mod);
244 
256 char *oauth_serialize_url_parameters (int argc, char **argv);
257 
266 
273 int oauth_cmpstringp(const void *p1, const void *p2);
274 
275 
284 int oauth_param_exists(char **argv, int argc, char *key);
285 
293 void oauth_add_param_to_array(int *argcp, char ***argvp, const char *addparam);
294 
301 void oauth_free_array(int *argcp, char ***argvp);
302 
315 int oauth_time_independent_equals_n(const char* a, const char* b, size_t len_a, size_t len_b);
316 
320 int oauth_time_indepenent_equals_n(const char* a, const char* b, size_t len_a, size_t len_b) attribute_deprecated;
321 
332 int oauth_time_independent_equals(const char* a, const char* b);
333 
337 int oauth_time_indepenent_equals(const char* a, const char* b) attribute_deprecated;
338 
371 char *oauth_sign_url2 (const char *url, char **postargs,
372  OAuthMethod method,
373  const char *http_method, //< HTTP request method
374  const char *c_key, //< consumer key - posted plain text
375  const char *c_secret, //< consumer secret - used as 1st part of secret-key
376  const char *t_key, //< token key - posted plain text in URL
377  const char *t_secret //< token secret - used as 2st part of secret-key
378  );
379 
383 char *oauth_sign_url (const char *url, char **postargs,
384  OAuthMethod method,
385  const char *c_key, //< consumer key - posted plain text
386  const char *c_secret, //< consumer secret - used as 1st part of secret-key
387  const char *t_key, //< token key - posted plain text in URL
388  const char *t_secret //< token secret - used as 2st part of secret-key
389  ) attribute_deprecated;
390 
391 
429 void oauth_sign_array2_process (int *argcp, char***argvp,
430  char **postargs,
431  OAuthMethod method,
432  const char *http_method, //< HTTP request method
433  const char *c_key, //< consumer key - posted plain text
434  const char *c_secret, //< consumer secret - used as 1st part of secret-key
435  const char *t_key, //< token key - posted plain text in URL
436  const char *t_secret //< token secret - used as 2st part of secret-key
437  );
438 
467 char *oauth_sign_array2 (int *argcp, char***argvp,
468  char **postargs,
469  OAuthMethod method,
470  const char *http_method, //< HTTP request method
471  const char *c_key, //< consumer key - posted plain text
472  const char *c_secret, //< consumer secret - used as 1st part of secret-key
473  const char *t_key, //< token key - posted plain text in URL
474  const char *t_secret //< token secret - used as 2st part of secret-key
475  );
476 
480 char *oauth_sign_array (int *argcp, char***argvp,
481  char **postargs,
482  OAuthMethod method,
483  const char *c_key, //< consumer key - posted plain text
484  const char *c_secret, //< consumer secret - used as 1st part of secret-key
485  const char *t_key, //< token key - posted plain text in URL
486  const char *t_secret //< token secret - used as 2st part of secret-key
487  ) attribute_deprecated;
488 
489 
502 char *oauth_body_hash_file(char *filename);
503 
519 char *oauth_body_hash_data(size_t length, const char *data);
520 
532 char *oauth_body_hash_encode(size_t len, unsigned char *digest);
533 
537 char *oauth_sign_xmpp (const char *xml,
538  OAuthMethod method,
539  const char *c_secret, //< consumer secret - used as 1st part of secret-key
540  const char *t_secret //< token secret - used as 2st part of secret-key
541  );
542 
572 char *oauth_http_get (const char *u, const char *q) attribute_deprecated;
573 
595 char *oauth_http_get2 (const char *u, const char *q, const char *customheader) attribute_deprecated;
596 
597 
629 char *oauth_http_post (const char *u, const char *p) attribute_deprecated;
630 
651 char *oauth_http_post2 (const char *u, const char *p, const char *customheader) attribute_deprecated;
652 
653 
670 char *oauth_post_file (const char *u, const char *fn, const size_t len, const char *customheader) attribute_deprecated;
671 
688 char *oauth_post_data (const char *u, const char *data, size_t len, const char *customheader) attribute_deprecated;
689 
713 char *oauth_post_data_with_callback (const char *u,
714  const char *data,
715  size_t len,
716  const char *customheader,
717  void (*callback)(void*,int,size_t,size_t),
718  void *callback_data) attribute_deprecated;
719 
739 char *oauth_send_data (const char *u,
740  const char *data,
741  size_t len,
742  const char *customheader,
743  const char *httpMethod) attribute_deprecated;
744 
769 char *oauth_send_data_with_callback (const char *u,
770  const char *data,
771  size_t len,
772  const char *customheader,
773  void (*callback)(void*,int,size_t,size_t),
774  void *callback_data,
775  const char *httpMethod) attribute_deprecated;
776 
777 #ifdef __cplusplus
778 } /* extern "C" */
779 #endif /* __cplusplus */
780 
781 #endif
782 /* vi:set ts=8 sts=2 sw=2: */
int oauth_verify_rsa_sha1(const char *m, const char *c, const char *s)
verify RSA-SHA1 signature.
int oauth_time_indepenent_equals_n(const char *a, const char *b, size_t len_a, size_t len_b) attribute_deprecated
char * oauth_encode_base64(int size, const unsigned char *src)
Base64 encode and return size data in 'src'.
int oauth_cmpstringp(const void *p1, const void *p2)
string compare function for oauth parameters.
char * oauth_sign_plaintext(const char *m, const char *k)
returns plaintext signature for the given key.
int oauth_param_exists(char **argv, int argc, char *key)
search array for parameter key.
char * oauth_send_data_with_callback(const char *u, const char *data, size_t len, const char *customheader, void(*callback)(void *, int, size_t, size_t), void *callback_data, const char *httpMethod) attribute_deprecated
http post raw data, with callback.
char * oauth_http_get(const char *u, const char *q) attribute_deprecated
do a HTTP GET request, wait for it to finish and return the content of the reply.
int oauth_decode_base64(unsigned char *dest, const char *src)
Decode the base64 encoded string 'src' into the memory pointed to by 'dest'.
char * oauth_gen_nonce()
generate a random string between 15 and 32 chars length and return a pointer to it.
OAuthMethod
signature method to used for signing the request.
Definition: oauth.h:66
@ OA_HMAC
use HMAC-SHA1 request signing method
Definition: oauth.h:67
@ OA_RSA
use RSA signature
Definition: oauth.h:68
@ OA_PLAINTEXT
use plain text signature (for testing only)
Definition: oauth.h:69
char * oauth_post_data_with_callback(const char *u, const char *data, size_t len, const char *customheader, void(*callback)(void *, int, size_t, size_t), void *callback_data) attribute_deprecated
http post raw data, with callback.
char * oauth_post_file(const char *u, const char *fn, const size_t len, const char *customheader) attribute_deprecated
http post raw data from file.
char * oauth_serialize_url_parameters(int argc, char **argv)
build a query parameter string from an array.
char * oauth_http_post(const char *u, const char *p) attribute_deprecated
do a HTTP POST request, wait for it to finish and return the content of the reply.
char * oauth_sign_url(const char *url, char **postargs, OAuthMethod method, const char *c_key, const char *c_secret, const char *t_key, const char *t_secret) attribute_deprecated
char * oauth_body_hash_file(char *filename)
calculate body hash (sha1sum) of given file and return a oauth_body_hash=xxxx parameter to be added t...
int oauth_split_url_parameters(const char *url, char ***argv)
splits the given url into a parameter array.
char * oauth_sign_hmac_sha1(const char *m, const char *k)
returns base64 encoded HMAC-SHA1 signature for given message and key.
char * oauth_sign_array(int *argcp, char ***argvp, char **postargs, OAuthMethod method, const char *c_key, const char *c_secret, const char *t_key, const char *t_secret) attribute_deprecated
int oauth_time_indepenent_equals(const char *a, const char *b) attribute_deprecated
char * oauth_send_data(const char *u, const char *data, size_t len, const char *customheader, const char *httpMethod) attribute_deprecated
http send raw data.
int oauth_time_independent_equals(const char *a, const char *b)
compare two strings in constant-time.
char * oauth_sign_rsa_sha1(const char *m, const char *k)
returns RSA-SHA1 signature for given data.
char * oauth_serialize_url(int argc, int start, char **argv)
build a url query string from an array.
char * oauth_http_get2(const char *u, const char *q, const char *customheader) attribute_deprecated
do a HTTP GET request, wait for it to finish and return the content of the reply.
char * oauth_url_escape(const char *string)
Escape 'string' according to RFC3986 and http://oauth.net/core/1.0/#encoding_parameters.
char * oauth_http_post2(const char *u, const char *p, const char *customheader) attribute_deprecated
do a HTTP POST request, wait for it to finish and return the content of the reply.
void oauth_sign_array2_process(int *argcp, char ***argvp, char **postargs, OAuthMethod method, const char *http_method, const char *c_key, const char *c_secret, const char *t_key, const char *t_secret)
the back-end behind by /ref oauth_sign_array2.
char * oauth_sign_xmpp(const char *xml, OAuthMethod method, const char *c_secret, const char *t_secret)
xep-0235 - TODO
int oauth_time_independent_equals_n(const char *a, const char *b, size_t len_a, size_t len_b)
compare two strings in constant-time (as to not let an attacker guess how many leading chars are corr...
int oauth_split_post_paramters(const char *url, char ***argv, short qesc)
splits the given url into a parameter array.
char * oauth_url_unescape(const char *string, size_t *olen)
Parse RFC3986 encoded 'string' back to unescaped version.
char * oauth_catenc(int len,...)
url-escape strings and concatenate with '&' separator.
char * oauth_body_hash_encode(size_t len, unsigned char *digest)
base64 encode digest, free it and return a URL parameter with the oauth_body_hash.
void oauth_free_array(int *argcp, char ***argvp)
free array args
char * oauth_sign_hmac_sha1_raw(const char *m, const size_t ml, const char *k, const size_t kl)
same as oauth_sign_hmac_sha1 but allows one to specify length of message and key (in case they contai...
char * oauth_sign_url2(const char *url, char **postargs, OAuthMethod method, const char *http_method, const char *c_key, const char *c_secret, const char *t_key, const char *t_secret)
calculate OAuth-signature for a given HTTP request URL, parameters and oauth-tokens.
char * oauth_body_hash_data(size_t length, const char *data)
calculate body hash (sha1sum) of given data and return a oauth_body_hash=xxxx parameter to be added t...
void oauth_add_param_to_array(int *argcp, char ***argvp, const char *addparam)
add query parameter to array
char * oauth_serialize_url_sep(int argc, int start, char **argv, char *sep, int mod)
encode query parameters from an array.
char * oauth_sign_array2(int *argcp, char ***argvp, char **postargs, OAuthMethod method, const char *http_method, const char *c_key, const char *c_secret, const char *t_key, const char *t_secret)
same as /ref oauth_sign_url with the url already split into parameter array
char * oauth_post_data(const char *u, const char *data, size_t len, const char *customheader) attribute_deprecated
http post raw data the returned string needs to be freed by the caller (requires libcurl)