Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
kehengzhong authored Feb 17, 2022
1 parent 5f8005b commit 71bae42
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 41 deletions.
4 changes: 2 additions & 2 deletions src/http_cgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,7 @@ int AddReqContentPtr (void * vmsg, void * body, int64 bodylen)
if (bodylen < 0) bodylen = str_len(body);
if (bodylen <= 0) return -3;

chunk_add_bufptr(msg->req_body_chunk, body, bodylen, NULL);
chunk_add_bufptr(msg->req_body_chunk, body, bodylen, NULL, NULL);
return 0;
}

Expand Down Expand Up @@ -1856,7 +1856,7 @@ int AddResContentPtr (void * vmsg, void * body, int64 bodylen)
if (bodylen < 0) bodylen = str_len(body);
if (bodylen <= 0) return -3;

chunk_add_bufptr(msg->res_body_chunk, body, bodylen, NULL);
chunk_add_bufptr(msg->res_body_chunk, body, bodylen, NULL, NULL);
return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions src/http_chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ int http_chunk_add_bufptr (void * vchk, void * vbgn, int len, int * rmlen)
chk->recvsize += restlen;
chk->recvlen += restlen - 2;

chunk_add_bufptr(chk->chunk, poct, restlen - 2, NULL);
chunk_add_bufptr(chk->chunk, poct, restlen - 2, NULL, NULL);

arr_push(chk->item_list, item);
chk->curitem = NULL;
Expand All @@ -328,7 +328,7 @@ int http_chunk_add_bufptr (void * vchk, void * vbgn, int len, int * rmlen)
item->recvlen += min(restnum, restlen);
chk->recvlen += min(restnum, restlen);

chunk_add_bufptr(chk->chunk, poct, min(restnum, restlen), NULL);
chunk_add_bufptr(chk->chunk, poct, min(restnum, restlen), NULL, NULL);

if (rmlen) *rmlen = len;

Expand Down
6 changes: 3 additions & 3 deletions src/http_cli_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,21 +594,21 @@ int http_cli_reqbody_parse (void * vcon, void * vmsg)
} else {
chunk_add_bufptr(msg->req_body_chunk,
frameP(msg->req_body_stream),
frameL(msg->req_body_stream), NULL);
frameL(msg->req_body_stream), NULL, NULL);
}

http_form_multipart_parse(msg, NULL);

if (msg->req_content_type && msg->req_contype_len > 0) {
if (strncasecmp(msg->req_content_type, "application/x-www-form-urlencoded", 33) == 0) {
if (str_ncasecmp(msg->req_content_type, "application/x-www-form-urlencoded", 33) == 0) {
if (!msg->req_form_kvobj) {
msg->req_form_kvobj = kvpair_init(37, "&", "=");
}

chunk_ptr(msg->req_body_chunk, 0, NULL, (void **)&pbody, &restlen);
kvpair_decode(msg->req_form_kvobj, pbody, restlen);

} else if (strncasecmp(msg->req_content_type, "application/json", 16) == 0) {
} else if (str_ncasecmp(msg->req_content_type, "application/json", 16) == 0) {
if (!msg->req_form_json) {
msg->req_form_json = json_init(0, 0, 0);
}
Expand Down
8 changes: 8 additions & 0 deletions src/http_do.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ void * do_http_get_msg (void * vmgmt, char * url, int urllen,
msg->SetMethod(msg, "GET", 3);
msg->SetURL(msg, url, urllen, 1);

str_secpy(msg->req_ver, sizeof(msg->req_ver)-1, "HTTP/1.1", 8);
msg->req_ver_major = 1;
msg->req_ver_minor = 1;

msg->req_body_flag = BC_NONE;

msg->dstport = msg->req_port;
Expand Down Expand Up @@ -234,6 +238,10 @@ void * do_http_post_msg (void * vmgmt, char * url, int urllen, char * mime,
msg->SetMethod(msg, "POST", 4);
msg->SetURL(msg, url, urllen, 1);

str_secpy(msg->req_ver, sizeof(msg->req_ver)-1, "HTTP/1.1", 8);
msg->req_ver_major = 1;
msg->req_ver_minor = 1;

msg->req_body_flag = BC_CONTENT_LENGTH;

msg->dstport = msg->req_port;
Expand Down
16 changes: 8 additions & 8 deletions src/http_fcgi_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ int http_fcgi_recv_forward (void * vcon)

if (pbyte + 4 <= ppar[0] + arlen[0]) {
/* add all STDOUT body into httpmsg->res_body_chunk */
chunk_add_bufptr(httpmsg->res_body_chunk, pbody, bodylen, frm);
chunk_add_bufptr(httpmsg->res_body_chunk, pbody, bodylen, frm, NULL);

} else {
/* header trailer \r\n\r\n across the 2 buffer, move them
Expand All @@ -528,7 +528,7 @@ int http_fcgi_recv_forward (void * vcon)
frame_put_nlast(httpmsg->res_header_stream, pbody, len);

/* add STDOUT body into httpmsg->res_body_chunk */
chunk_add_bufptr(httpmsg->res_body_chunk, pbody + len, bodylen - len, frm);
chunk_add_bufptr(httpmsg->res_body_chunk, pbody + len, bodylen - len, frm, NULL);
}

/* move the pointer to the end of first FastCGI pdu */
Expand All @@ -540,7 +540,7 @@ int http_fcgi_recv_forward (void * vcon)

if (bodylen > len) {
/* add STDOUT body into httpmsg->res_body_chunk */
chunk_add_bufptr(httpmsg->res_body_chunk, pbody + len, bodylen - len, frm);
chunk_add_bufptr(httpmsg->res_body_chunk, pbody + len, bodylen - len, frm, NULL);
}

/* move the pointer to the end of first FastCGI pdu */
Expand Down Expand Up @@ -584,7 +584,7 @@ int http_fcgi_recv_forward (void * vcon)

} else { //STDOUT header has been got before
/* add all STDOUT body into httpmsg->res_body_chunk */
chunk_add_bufptr(httpmsg->res_body_chunk, pbody, bodylen, frm);
chunk_add_bufptr(httpmsg->res_body_chunk, pbody, bodylen, frm, NULL);

/* move the pointer to the end of first FastCGI pdu */
iter = (pend - pbgn);
Expand Down Expand Up @@ -655,16 +655,16 @@ int http_fcgi_handle (void * vmsg)
HTTPMgmt * mgmt = NULL;
FcgiSrv * cgisrv = NULL;
char url[512];

if (!msg) return -1;

mgmt = (HTTPMgmt *)msg->httpmgmt;
if (!mgmt) return -2;

/* check the request if it's to be transformed to FCGI server */
if (http_fcgi_check(msg, url, sizeof(url)-1) <= 0)
return -100;

msg->fastcgi = 1;

cgisrv = http_fcgisrv_open(mgmt, url, 100);
Expand Down
7 changes: 4 additions & 3 deletions src/http_fcgi_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ void * http_fcgimsg_open (void * vsrv, void * vhttpmsg)
http_fcgimsg_request_encode(msg);
http_fcgimsg_abort_encode(msg);

chunk_prepend_bufptr(msg->req_body_chunk, frameP(msg->fcgi_request), frameL(msg->fcgi_request), 1);
chunk_prepend_bufptr(msg->req_body_chunk, frameP(msg->fcgi_request),
frameL(msg->fcgi_request), NULL, NULL, 1);

return msg;
}
Expand Down Expand Up @@ -410,7 +411,7 @@ void fcgi_predefined_param_encode (frame_p frm, HTTPMsg * httpmsg)

num = json_num(jpara);
for (i = 0; i < num; i++) {
ret = json_iter(jpara, i, (void **)&name, &namelen, (void **)&value, &valuelen, NULL);
ret = json_iter(jpara, i, 0, (void **)&name, &namelen, (void **)&value, &valuelen, NULL);
if (ret < 0) continue;

if (!name || namelen <= 0) continue;
Expand Down Expand Up @@ -675,7 +676,7 @@ int http_fcgimsg_stdin_encode_chunk (void * vmsg, void * pbyte, int bytelen, voi
fcgi_header_encode2(hdrbuf, FCGI_STDIN, /*msg->msgid*/1, contlen);
chunk_add_buffer(msg->req_body_chunk, hdrbuf, 8);

chunk_add_bufptr(msg->req_body_chunk, (uint8 *)pbyte + pos, contlen, porig);
chunk_add_bufptr(msg->req_body_chunk, (uint8 *)pbyte + pos, contlen, porig, NULL);

padding = contlen % 8;
if (padding > 0) padding = 8 - padding;
Expand Down
2 changes: 1 addition & 1 deletion src/http_listen.c
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ int http_host_build (void * vhl, void * jhl)

num = json_num(jerrpage);
for (j = 0; j < num; j++) {
ret = json_iter(jerrpage, j, (void **)&hname, &keylen,
ret = json_iter(jerrpage, j, 0, (void **)&hname, &keylen,
(void **)&value, &valuelen, NULL);
if (ret > 0 && hname && keylen > 0) {
code = strtol(hname, NULL, 10);
Expand Down
2 changes: 1 addition & 1 deletion src/http_mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ int http_conf_mime_init (void * vmgmt)

num = json_num(mimeobj);
for (i = 0; i < num; i++) {
json_iter(mimeobj, i, (void **)&mime, &mimelen, (void **)&ext, &extlen, NULL);
json_iter(mimeobj, i, 0, (void **)&mime, &mimelen, (void **)&ext, &extlen, NULL);
if (!mime || mimelen <= 0 || !ext || extlen <= 0)
continue;

Expand Down
16 changes: 12 additions & 4 deletions src/http_proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ void * http_proxy_srvmsg_open (void * vmsg, char * url, int urllen)
proxymsg->SetURL(proxymsg, url, urllen, 1);
proxymsg->req_url_type = msg->req_url_type;

str_cpy(proxymsg->req_ver, msg->req_ver);
proxymsg->req_ver_major = msg->req_ver_major;
proxymsg->req_ver_minor = msg->req_ver_minor;

proxymsg->dstport = proxymsg->req_port;

str_cpy(proxymsg->srcip, msg->srcip);
Expand Down Expand Up @@ -355,7 +359,7 @@ int http_proxy_srv_send (void * vsrvcon, void * vsrvmsg)
isend = srvmsg->req_body_iolen >= climsg->req_body_length;

if (rcvslen > 0) {
chunk_add_bufptr(srvmsg->req_body_chunk, pbgn, rcvslen, frm);
chunk_add_bufptr(srvmsg->req_body_chunk, pbgn, rcvslen, frm, NULL);
}

} else if (climsg->req_body_flag == BC_TE && num > 0) {
Expand All @@ -365,7 +369,7 @@ int http_proxy_srv_send (void * vsrvcon, void * vsrvmsg)
isend = chunk->gotall;

if (ret >= 0 && rcvslen > 0) {
chunk_add_bufptr(srvmsg->req_body_chunk, pbgn, rcvslen, frm);
chunk_add_bufptr(srvmsg->req_body_chunk, pbgn, rcvslen, frm, NULL);
}

climsg->req_body_iolen += rcvslen;
Expand Down Expand Up @@ -511,7 +515,7 @@ int http_proxy_cli_send (void * vclicon, void * vclimsg)
isend = climsg->res_body_iolen >= srvmsg->res_body_length ? 1 : 0;

if (rcvslen > 0) {
chunk_add_bufptr(climsg->res_body_chunk, pbgn, rcvslen, frm);
chunk_add_bufptr(climsg->res_body_chunk, pbgn, rcvslen, frm, NULL);
}

} else if (srvmsg->res_body_flag == BC_TE && num > 0) {
Expand All @@ -521,7 +525,7 @@ int http_proxy_cli_send (void * vclicon, void * vclimsg)
isend = chunk->gotall;

if (ret >= 0 && rcvslen > 0) {
chunk_add_bufptr(climsg->res_body_chunk, pbgn, rcvslen, frm);
chunk_add_bufptr(climsg->res_body_chunk, pbgn, rcvslen, frm, NULL);
}

srvmsg->res_body_iolen += rcvslen;
Expand Down Expand Up @@ -1060,6 +1064,10 @@ void * http_proxy_srv_cache_send (void * vmsg)
srvmsg->SetURL(srvmsg, msg->fwdurl, msg->fwdurllen, 1);
srvmsg->req_url_type = msg->req_url_type;

str_cpy(srvmsg->req_ver, msg->req_ver);
srvmsg->req_ver_major = msg->req_ver_major;
srvmsg->req_ver_minor = msg->req_ver_minor;

srvmsg->dstport = srvmsg->req_port;

str_cpy(srvmsg->srcip, msg->srcip);
Expand Down
3 changes: 2 additions & 1 deletion src/http_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,8 @@ int http_req_encoding (void * vmsg, int encode)
msg->reqsent = 0;
msg->req_stream_sent = 0;

chunk_prepend_bufptr(msg->req_body_chunk, frameP(msg->req_stream), frameL(msg->req_stream), 1);
chunk_prepend_bufptr(msg->req_body_chunk, frameP(msg->req_stream),
frameL(msg->req_stream), NULL, NULL, 1);

return 0;
}
Expand Down
3 changes: 2 additions & 1 deletion src/http_response.c
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,8 @@ int http_res_encoding (void * vmsg)

msg->res_header_length = frameL(msg->res_stream);

chunk_prepend_bufptr(msg->res_body_chunk, frameP(msg->res_stream), frameL(msg->res_stream), 1);
chunk_prepend_bufptr(msg->res_body_chunk, frameP(msg->res_stream),
frameL(msg->res_stream), NULL, NULL, 1);

#if defined _DEBUG
print_response(msg, stderr);
Expand Down
2 changes: 1 addition & 1 deletion src/http_sndpxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ int http_send_proxy_init (void * vmgmt)

num = json_num(jsndpxy);
for (i = 0; i < num; i++) {
ret = json_iter(jsndpxy, i, (void **)&key, &keylen, (void **)&data, &datalen, NULL);
ret = json_iter(jsndpxy, i, 0, (void **)&key, &keylen, (void **)&data, &datalen, NULL);
if (ret <= 0) continue;
if (!key || keylen <= 0) continue;
if (!data || datalen <= 0) continue;
Expand Down
24 changes: 12 additions & 12 deletions src/http_srv.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,20 +345,20 @@ void * http_srv_open (void * vmgmt, char * ip, int port, int ssl_link, int maxco

strncpy(srv->ip, ip, sizeof(srv->ip)-1);
srv->port = port;
}

srv->ssl_link = ssl_link;
if (srv->ssl_link) {
srv->ssl_link = ssl_link;
if (srv->ssl_link) {
#ifdef HAVE_OPENSSL
if (mgmt->srv_sslctx) {
srv->sslctx = mgmt->srv_sslctx;
srv->sslctx_alloc = 0;
} else {
srv->sslctx = http_ssl_client_ctx_init(mgmt->srv_con_cert,
mgmt->srv_con_prikey, mgmt->srv_con_cacert);
srv->sslctx_alloc = 1;
}
#endif
if (mgmt->srv_sslctx) {
srv->sslctx = mgmt->srv_sslctx;
srv->sslctx_alloc = 0;
} else {
srv->sslctx = http_ssl_client_ctx_init(mgmt->srv_con_cert,
mgmt->srv_con_prikey, mgmt->srv_con_cacert);
srv->sslctx_alloc = 1;
}
#endif
}

srv->maxcon = maxcon;
Expand Down Expand Up @@ -512,7 +512,7 @@ int http_srv_msg_dns (void * vmsg, void * cb)
if (!dnscb) dnscb = http_srv_msg_dns_cb;

if (msg->proxy && msg->proxyport > 0) {
ret = dns_query(mgmt->pcore, msg->proxy, msg->proxyport, dnscb, msg);
ret = dns_query(mgmt->pcore, msg->proxy, -1, dnscb, msg);
} else {
ret = dns_query(mgmt->pcore, msg->req_host, msg->req_hostlen, dnscb, msg);
}
Expand Down
2 changes: 1 addition & 1 deletion src/http_srv_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ int http_srv_resbody_parse (void * vcon, void * vmsg, int64 * offset, int64 * sa
} else {
chunk_add_bufptr(msg->res_body_chunk,
frameP(msg->res_body_stream),
frameL(msg->res_body_stream), NULL);
frameL(msg->res_body_stream), NULL, NULL);
}

return 1;
Expand Down
2 changes: 1 addition & 1 deletion src/http_uri.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ int http_uri_parse (void * vuri)
uri->scheme = pbgn;
uri->schemelen = p - 1 - pbgn;

if (uri->schemelen == 5 && strncasecmp(uri->scheme, "https", 8) == 0)
if (uri->schemelen == 5 && strncasecmp(uri->scheme, "https", 5) == 0)
uri->ssl_link = 1;
else
uri->ssl_link = 0;
Expand Down

0 comments on commit 71bae42

Please sign in to comment.