static int alter(void) { ne_buffer *s = ne_buffer_create(); char *d; ON(s == NULL); ne_buffer_zappend(s, "abcdefg"); d = s->data; ON(d == NULL); d[2] = '\0'; ne_buffer_altered(s); ONCMP(s->data, "ab"); ON(ne_buffer_size(s) != 2); ne_buffer_zappend(s, "hijkl"); ONCMP(s->data, "abhijkl"); ne_buffer_destroy(s); return OK; }
static ne_request *s3_new_request(const S3 *s3,const char *method,const char *bucket,const char *key,const char *params,const char *content_type) { ne_buffer *date, *signing_string, *request_str; ne_request *req; char *sig, *p; time_t t; if(!s3) return NULL; if(!method) return NULL; if(!bucket) return NULL; if(!s3->session) return NULL; // create some string buffers date = ne_buffer_create(); signing_string = ne_buffer_create(); request_str = ne_buffer_create(); // get the time t = time(NULL); ne_buffer_zappend(date,asctime(gmtime(&t))); if(date->data[date->used - 2] == '\n') date->data[date->used - 2] = 0; ne_buffer_altered(date); // create request if(key) ne_buffer_concat(request_str,"/",bucket,"/",key,NULL); else ne_buffer_concat(request_str,"/",bucket,NULL); if(params && params[0] != 0) { ne_buffer_zappend(request_str,"?"); ne_buffer_zappend(request_str,params); } req = ne_request_create(s3->session,method,request_str->data); // Add date header ne_add_request_header(req,"Date",date->data); // Add content-type header if(content_type) ne_add_request_header(req,"Content-Type",content_type); else content_type = ""; // construct signing string p = strrchr(request_str->data,'?'); if(p) { *p = 0; ne_buffer_altered(request_str); } ne_buffer_concat(signing_string,method,"\n\n",content_type,"\n",date->data,"\n",request_str->data,NULL); // sign the string sig = s3_sign_string(s3,signing_string->data); // construct signed header ne_print_request_header(req,"Authorization","AWS %s:%s",s3->access_id,sig); ne_buffer_destroy(date); ne_buffer_destroy(signing_string); ne_buffer_destroy(request_str); free(sig); return req; }