Beispiel #1
0
// honors bit 1 (2) GET/POST
//        bit 8 (256) irregular escape
//        bit 9 (512) curl output
void format_array(int mode, int argc, char **argv) {
    if (argc<1 || !argv) return;

    if (mode&512) {
        format_array_curl(mode, argc, argv);
        return;
    }

    if ((mode&258) == 2) {
        printf("%s\n", argv[0]);
        array_format_raw(argc, 1, argv, "&");
    } else if ((mode&258) == 258) { // -- encoded POST parameters!
#if LIBOAUTH_VERSION_MAJOR >= 0 && LIBOAUTH_VERSION_MINOR >= 4  && LIBOAUTH_VERSION_MICRO >= 1
        char *result = oauth_serialize_url_sep(argc, 1, argv, "&", 0);
        printf("%s\n", result);
        free (result);
#else
        if (!no_warnings)
            fprintf(stderr, "ERROR: encoded parameter output is not supported by this version of liboauth.\n" );
#endif
    } else if ((mode&258) == 256) { // irregular GET
        printf("%s?", argv[0]);
        array_format_raw(argc, 1, argv, "&");
    } else {
        char *result = oauth_serialize_url(argc, (mode&2?1:0), argv);
        printf("%s\n", result);
        free (result);
    }
}
Beispiel #2
0
// basically oauth_sign_url() from liboauth in steps..
char *oauthrequest_ext (int mode, oauthparam *op, int oauthargc, char **oauthargv, char *sign) {
    int argc=0;
    char **argv = NULL;
    char *request=NULL;

    append_parameters(&argc, &argv, oauthargc, oauthargv);

    if (sign) {
        add_kv_to_array(&argc, &argv, "oauth_signature", sign);
    }

    // build URL params
    request = oauth_serialize_url(argc, (mode&2?1:0), argv);

    char *reply = NULL;
    if(request) {
        if (mode&2) { // POST
            reply = oauth_http_post(argv[0],request);
        } else { // GET
            reply= oauth_http_get(request, NULL);
        }
        free(request);
    }
    free_array(argc,argv);
    return reply;
}
Beispiel #3
0
// basically oauth_sign_url() from liboauth in steps..
char *oauthsign_ext (int mode, char *method, oauthparam *op, int optargc, char **optargv, int *saveargcp, char ***saveargvp) {
    int argc=0;
    char **argv = NULL;
    char *sign=NULL;

    url_to_array(&argc, &argv, mode, op->url);
    append_parameters(&argc, &argv, optargc, optargv);
    add_oauth_params_to_array(&argc, &argv, op);
    if (saveargvp && saveargcp) {
        clear_parameters(saveargcp, saveargvp);
        append_parameters(saveargcp, saveargvp, argc, argv);
    }

    sign=process_array(argc, argv, method, mode, op);
    free_array(argc,argv);
    return (sign); // needs to be free()d.

#if 0 // cruft
    if (sign) {
        add_kv_to_array(&argc, &argv, "oauth_signature", sign);
        free(sign);
    }
    char *result;
    result = oauth_serialize_url(argc, (mode&2?1:0), argv);
    return (result);
#endif
}
Beispiel #4
0
/*
 * test request normalization
 */
int test_normalize(char *param, char *expected) {
  int rv=2;
  int  i, argc;
  char **argv = NULL;
  char *testcase;

  argc = oauth_split_url_parameters(param, &argv);
  qsort(argv, argc, sizeof(char *), oauth_cmpstringp);
  testcase= oauth_serialize_url(argc,0, argv);

  rv=strcmp(testcase,expected);
  if (rv) {
    printf("parameter normalization test failed for: '%s'.\n"
           " got: '%s' expected: '%s'\n", param, testcase, expected);
  }
  else if (loglevel) printf("parameter normalization ok. ('%s')\n", testcase);
  for (i=0;i<argc;i++) free(argv[i]);
  if (argv) free(argv);
  if (testcase) free(testcase);
  return (rv);
}
Beispiel #5
0
/*
 * test request concatenation
 */
int test_request(char *http_method, char *request, char *expected) {
  int rv=2;
  int  i, argc;
  char **argv = NULL;
  char *query, *testcase;

  argc = oauth_split_url_parameters(request, &argv);
  qsort(&argv[1], argc-1, sizeof(char *), oauth_cmpstringp);
  query= oauth_serialize_url(argc,1, argv);
  testcase = oauth_catenc(3, http_method, argv[0], query);

  rv=strcmp(testcase,expected);
  if (rv) {
    printf("request concatenation test failed for: '%s'.\n"
           " got:      '%s'\n expected: '%s'\n", request, testcase, expected);
  }
  else if (loglevel) printf("request concatenation ok.\n");
  for (i=0;i<argc;i++) free(argv[i]);
  if (argv) free(argv);
  if (query) free(query);
  if (testcase) free(testcase);
  return (rv);
}