/* void createnonce(char nonce[NONCE_LENGTH]) { int i,j; srand(time(NULL)); for(i=0; i < NONCE_LENGTH; i++) { j = random() % NONCE_CHARS; if(j < 10) nonce[i] = j + 48; else if(j < 36) nonce[i] = j + 55; else nonce[i] = j + 61; } } */ int post(const char *msg) { const char *request_uri = "http://api.twitter.com/1/statuses/update.json"; char *req_url = NULL; char *postarg = NULL; int argc = 2; char argv_utf8[BUF_SIZE]; char **argv = (char**)malloc(sizeof(char*) * 2); argv[0] = strdup(request_uri); snprintf(argv_utf8, sizeof(argv_utf8), "status= %s", msg); tcstrcututf(argv_utf8, MSG_SIZE); //** convert string to UTF-8 format (required by twitter API) argv[1] = strdup(argv_utf8); req_url = oauth_sign_array2(&argc, &argv, &postarg, OA_HMAC, NULL, consumer_key, consumer_secret, access_token, access_token_secret); free(argv[0]); free(argv[1]); free(argv); oauth_http_post2(req_url, postarg, "Expect: \r\n"); return 0; }
/* perform export command */ static int procexport(const char *dbpath, int64_t id, const char *dirpath){ TCTDB *tdb = tctdbnew(); if(!tctdbopen(tdb, dbpath, TDBOREADER)){ printdberr(tdb); tctdbdel(tdb); return 1; } bool err = false; if(id > 0){ char pkbuf[NUMBUFSIZ]; int pksiz = sprintf(pkbuf, "%lld", (long long)id); TCMAP *cols = tctdbget(tdb, pkbuf, pksiz); if(cols){ TCXSTR *rbuf = tcxstrnew3(IOBUFSIZ); wikidump(rbuf, cols); fwrite(tcxstrptr(rbuf), 1, tcxstrsize(rbuf), stdout); tcxstrdel(rbuf); tcmapdel(cols); } else { printdberr(tdb); err = true; } } else { if(!dirpath) dirpath = "."; if(!tctdbiterinit(tdb)){ printdberr(tdb); err = true; } char *pkbuf; int pksiz; while((pkbuf = tctdbiternext(tdb, &pksiz)) != NULL){ TCMAP *cols = tctdbget(tdb, pkbuf, pksiz); if(cols){ char *name = tcstrdup(tcmapget4(cols, "name", "")); tcstrcututf(name, 32); char *enc = pathencode(name); char *path = tcsprintf("%s/%s-%s.tpw", dirpath, pkbuf, enc); TCXSTR *rbuf = tcxstrnew3(IOBUFSIZ); wikidump(rbuf, cols); if(tcwritefile(path, tcxstrptr(rbuf), tcxstrsize(rbuf))){ printf("%s: exported: id=%s name=%s\n", path, pkbuf, name); } else { printf("%s: writing failed\n", path); err = true; } tcxstrdel(rbuf); tcfree(path); tcfree(enc); tcfree(name); tcmapdel(cols); } else { printdberr(tdb); err = true; } tcfree(pkbuf); } } if(!tctdbclose(tdb)){ printdberr(tdb); err = true; } tctdbdel(tdb); return err ? 1 : 0; }