6 static void usage (char *program_name) {
7 printf(" usage: %s mode url ckey tkey csec tsec\n", program_name);
14 * gcc -loauth -o oauthsign oauthsign.c
16 int main (int argc, char **argv) {
18 char *url; //< the url to sign
19 char *c_key; //< consumer key
20 char *c_secret; //< consumer secret
21 char *t_key; //< token key
22 char *t_secret ; //< token secret
24 int mode = 0; //< mode: 0=GET 1=POST
26 // TODO: use getopt to parse parameters
28 // FIXME: read secrets from stdin - they show up in ps(1)
29 // also overwrite memory of secrets before freeing it.
31 if (argc !=7) usage(argv[0]);
33 if ( atoi(argv[1]) > 0 ) mode=atoi(argv[1]);// questionable numeric shortcut
34 else if (!strcasecmp(argv[1],"GET")) mode=1;
35 else if (!strcasecmp(argv[1],"POST")) mode=2;
36 else if (!strcasecmp(argv[1],"POSTREQUEST")) mode=4;
47 geturl = oauth_sign_url2(url, NULL, OA_HMAC, NULL, c_key, c_secret, t_key, t_secret);
49 printf("%s\n", geturl);
53 char *postargs = NULL, *post = NULL;
54 post = oauth_sign_url2(url, &postargs, OA_HMAC, NULL, c_key, c_secret, t_key, t_secret);
55 if (!post || !postargs) {
58 if (mode==2) { // print postargs only
59 if (postargs) printf("%s\n", postargs);
60 } else if (mode==3) { // print url and postargs
61 if (post && postargs) printf("%s\n%s\n", post, postargs);
62 } else if (post && postargs) {
63 char *reply = oauth_http_post(post,postargs);
65 //write(STDOUT, reply, strlen(reply))
66 printf("%s\n", reply);
71 if(postargs) free(postargs);