static void http_printquery(const struct req *req) { printf("&expr="); http_print(req->q.expr ? req->q.expr : ""); printf("&sec="); http_print(req->q.sec ? req->q.sec : ""); printf("&arch="); http_print(req->q.arch ? req->q.arch : ""); }
void form_cgi_post(FILE *fp) { int i; for (i = 0; i < nvar; i++) { http_print(fp, fvar[i].name); putc('=', fp); http_print(fp, fvar[i].value); } }
bool Twitter::query_time(void) { EthernetClient http; if (!http.connect(ip, port)) { println(PSTR("query_time: could not connect to server")); return false; } http_print(&http, PSTR("HEAD ")); if (proxy) { http_print(&http, PSTR("http://")); http_print(&http, server); } http_println(&http, PSTR("/ HTTP/1.1")); http_print(&http, PSTR("Host: ")); http_print(&http, server); http_newline(&http); http_println(&http, PSTR("Connection: close")); http_newline(&http); while (http.connected()) { if (!read_line(&http, buffer, buffer_len)) break; if (buffer[0] == '\0') break; if (process_date_header(buffer)) break; } http.stop(); return basetime != 0L; }
static void http_printquery(const struct req *req, const char *sep) { if (NULL != req->q.query) { printf("query="); http_print(req->q.query); } if (0 == req->q.equal) printf("%sapropos=1", sep); if (NULL != req->q.sec) { printf("%ssec=", sep); http_print(req->q.sec); } if (NULL != req->q.arch) { printf("%sarch=", sep); http_print(req->q.arch); } if (strcmp(req->q.manpath, req->p[0])) { printf("%smanpath=", sep); http_print(req->q.manpath); } }
void Twitter::http_println(Client *client, const prog_char str[]) { http_print(client, str); http_newline(client); }
bool Twitter::post_status(const char *message) { char *cp; int i; timestamp = get_time(); create_nonce(); compute_authorization(message); /* Post message to twitter. */ EthernetClient http; if (!http.connect(ip, port)) { println(PSTR("Could not connect to server")); return false; } http_print(&http, PSTR("POST ")); if (proxy) { http_print(&http, PSTR("http://")); http_print(&http, server); } http_print(&http, uri); http_println(&http, PSTR(" HTTP/1.1")); http_print(&http, PSTR("Host: ")); http_print(&http, server); http_newline(&http); http_println(&http, PSTR("Content-Type: application/x-www-form-urlencoded")); http_println(&http, PSTR("Connection: close")); /* Authorization header. */ http_print(&http, PSTR("Authorization: OAuth oauth_consumer_key=\"")); url_encode_pgm(buffer, consumer_key); http.write(buffer); http_print(&http, PSTR("\",oauth_signature_method=\"HMAC-SHA1")); http_print(&http, PSTR("\",oauth_timestamp=\"")); sprintf(buffer, "%ld", timestamp); http.write(buffer); http_print(&http, PSTR("\",oauth_nonce=\"")); hex_encode(buffer, nonce, sizeof(nonce)); http.write(buffer); http_print(&http, PSTR("\",oauth_version=\"1.0\",oauth_token=\"")); if (access_token_pgm) url_encode_pgm(buffer, access_token.pgm); else url_encode_eeprom(buffer, access_token.eeprom); http.write(buffer); http_print(&http, PSTR("\",oauth_signature=\"")); cp = base64_encode(buffer, signature, HASH_LENGTH); url_encode(cp + 1, buffer); http.write(cp + 1); http_println(&http, PSTR("\"")); /* Encode content. */ cp = url_encode(buffer, "status"); *cp++ = '='; cp = url_encode(cp, message); int content_length = cp - buffer; sprintf(cp + 1, "%d", content_length); http_print(&http, PSTR("Content-Length: ")); http.write(cp + 1); http_newline(&http); /* Header-body separator. */ http_newline(&http); /* And finally content. */ http.write(buffer); /* Read response status line. */ if (!read_line(&http, buffer, buffer_len) || buffer[0] == '\0') { http.stop(); return false; } int response_code; /* HTTP/1.1 200 Success */ for (i = 0; buffer[i] && buffer[i] != ' '; i++) ; if (buffer[i]) response_code = atoi(buffer + i + 1); else response_code = 0; bool success = (200 <= response_code && response_code < 300); if (!success) Serial.println(buffer); /* Skip header. */ while (true) { if (!read_line(&http, buffer, buffer_len)) { http.stop(); return false; } if (buffer[0] == '\0') break; /* Update our system basetime from the response `Date' header. */ process_date_header(buffer); } /* Handle content. */ while (http.connected()) { while (http.available() > 0) { uint8_t byte = http.read(); if (!success) Serial.write(byte); } delay(100); } http.stop(); if (!success) println(PSTR("")); return success; }