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 Apr 8, 2021
1 parent b92ae72 commit 378ccb4
Show file tree
Hide file tree
Showing 29 changed files with 2,275 additions and 484 deletions.
2 changes: 1 addition & 1 deletion src/http_cache.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003-2020 Ke Hengzhong <[email protected]>
* Copyright (c) 2003-2021 Ke Hengzhong <[email protected]>
* All rights reserved. See MIT LICENSE for redistribution.
*/

Expand Down
69 changes: 49 additions & 20 deletions src/http_cgi.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003-2020 Ke Hengzhong <[email protected]>
* Copyright (c) 2003-2021 Ke Hengzhong <[email protected]>
* All rights reserved. See MIT LICENSE for redistribution.
*/

Expand Down Expand Up @@ -85,6 +85,15 @@ int RecycleFrame (void * vmsg, frame_p frame)
return 0;
}

int GetMethodInd (void * vmsg)
{
HTTPMsg * msg = (HTTPMsg *)vmsg;

if (!msg) return 0;

return msg->req_methind;
}

char * GetMethod (void * vmsg)
{
HTTPMsg * msg = (HTTPMsg *)vmsg;
Expand Down Expand Up @@ -253,32 +262,40 @@ int GetReqPath (void * vmsg, char * path, int pathlen)
char * GetRootPath (void * vmsg)
{
HTTPMsg * msg = (HTTPMsg *)vmsg;
HTTPLoc * ploc = NULL;
HTTPHost * phost = NULL;
HTTPLoc * ploc = NULL;

if (!msg || !msg->ploc) return ".";
if (!msg) return ".";

if (!msg->ploc) {
if (msg->phost) {
phost = (HTTPHost *)msg->phost;
return phost->root;
}
return ".";
}

ploc = (HTTPLoc *)msg->ploc;
ploc = (HTTPLoc *)msg->ploc;

return ploc->root;
}

int GetRealPath (void * vmsg, char * path, int len)
{
HTTPMsg * msg = (HTTPMsg *)vmsg;
HTTPLoc * ploc = NULL;
char * root = NULL;
int slen = 0;
int retlen = 0;

if (!msg || !msg->ploc) return -1;
if (!msg) return -1;
if (!path || len <= 0) return -2;

ploc = (HTTPLoc *)msg->ploc;

retlen = strlen(ploc->root);
root = GetRootPath(msg);
retlen = str_len(root);

if (path && len > 0)
str_secpy(path, len, ploc->root, retlen);
str_secpy(path, len, root, retlen);

if (path) {
slen = strlen(path);
uri_decode(msg->docuri->dir, msg->docuri->dirlen, path + slen, len - slen);
Expand All @@ -294,19 +311,19 @@ int GetRealFile (void * vmsg, char * path, int len)
{
HTTPMsg * msg = (HTTPMsg *)vmsg;
HTTPLoc * ploc = NULL;
int slen = 0;
char * root = NULL;
int i, slen = 0;
int retlen = 0;

if (!msg || !msg->ploc) return -1;
if (!msg) return -1;
if (!path || len <= 0) return -2;

ploc = (HTTPLoc *)msg->ploc;

retlen = strlen(ploc->root);
root = GetRootPath(msg);
retlen = str_len(root);

if (path && len > 0)
str_secpy(path, len, ploc->root, retlen);
str_secpy(path, len, root, retlen);

if (msg->docuri->path && msg->docuri->pathlen > 0) {
if (path) {
slen = strlen(path);
Expand All @@ -322,7 +339,19 @@ int GetRealFile (void * vmsg, char * path, int len)
retlen += 1;
}

if (path && file_is_dir(path) && (ploc = msg->ploc)) {
slen = strlen(path);
for (i = 0; i < ploc->indexnum; i++) {
snprintf(path + slen, len - slen, "%s", ploc->index[i]);
if (file_is_regular(path)) {
return strlen(path);
}
}
path[slen] = '\0';
}

if (path) return strlen(path);

return retlen;
}

Expand Down Expand Up @@ -1935,7 +1964,7 @@ int AddResFile (void * vmsg, char * filename, int64 startpos, int64 len)
}

addfile:
if (startpos >= st.st_size && st.st_size > 0) return -100;
if (startpos >= st.st_size) return -100;
if (len < 0 || len > st.st_size - startpos)
len = st.st_size - startpos;

Expand Down
2 changes: 1 addition & 1 deletion src/http_chunk.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003-2020 Ke Hengzhong <[email protected]>
* Copyright (c) 2003-2021 Ke Hengzhong <[email protected]>
* All rights reserved. See MIT LICENSE for redistribution.
*/

Expand Down
27 changes: 17 additions & 10 deletions src/http_cli_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ int http_cli_accept (void * vmgmt, void * listendev)

#ifdef HAVE_OPENSSL
if (pcon->ssl_link) {
pcon->sslctx = http_listen_ssl_ctx_get(hl, pcon);
pcon->sslctx = http_listen_ssl_ctx_get(hl);
pcon->ssl = http_ssl_new(pcon->sslctx, pcon);
pcon->ssl_handshaked = 0;
pcon->rcv_state = HTTP_CON_SSL_HANDSHAKING;
Expand Down Expand Up @@ -250,6 +250,7 @@ int http_cli_recv_parse (void * vcon)
int64 hdrlen = 0;
uint8 * pbyte = NULL;
uint8 * pbgn = NULL;
char buf[2048];

HTTPMsg * proxymsg = NULL;
FcgiMsg * cgimsg = NULL;
Expand Down Expand Up @@ -381,6 +382,12 @@ int http_cli_recv_parse (void * vcon)
http_req_set_docuri(msg, frameP(msg->uri->uri), frameL(msg->uri->uri), 0, 0);
}

/* if set the check callback, all requests including proxy mode will be checked */
if (mgmt->req_check) {
msg->GetRealFile(msg, buf, sizeof(buf)-1);
(*mgmt->req_check)(mgmt->req_checkobj, msg, buf);
}

/* determine if request body is following, set the rcv_state of HTTPCon */
if ( ( msg->req_body_flag == BC_CONTENT_LENGTH &&
msg->req_body_length > 0 ) ||
Expand All @@ -396,7 +403,7 @@ int http_cli_recv_parse (void * vcon)

if (http_fcgi_handle(msg) >= 0)
return 0;

return http_reqbody_handle(msg);
}

Expand All @@ -408,20 +415,20 @@ int http_reqbody_handle (void * vmsg)
HTTPMsg * msg = (HTTPMsg *)vmsg;
HTTPCon * pcon = NULL;
int ret = 0;

if (!msg) return -1;

pcon = (HTTPCon *)msg->pcon;
if (!pcon) return -2;

/* HTTP POST/PUT request body may be encoded as following enctype:
(1) application/x-www-form-urlencoded
(2) multipart/form-data
(3) application/json
(4) text/xml
(5) application/octet-stream
*/

switch (msg->req_body_flag) {
case BC_CONTENT_LENGTH:
case BC_TE:
Expand All @@ -432,23 +439,23 @@ int http_reqbody_handle (void * vmsg)
pcon->rcv_state = HTTP_CON_WAITING_BODY;
} else {
pcon->rcv_state = HTTP_CON_READY;

return 1;
}
break;

case BC_TE_INVALID:
case BC_UNKNOWN:
return -108;

case BC_NONE:
case BC_TUNNEL:
default:
pcon->rcv_state = HTTP_CON_READY;
return 2;
break;
}

return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/http_con.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003-2020 Ke Hengzhong <[email protected]>
* Copyright (c) 2003-2021 Ke Hengzhong <[email protected]>
* All rights reserved. See MIT LICENSE for redistribution.
*/

Expand Down
5 changes: 3 additions & 2 deletions src/http_cookie.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003-2020 Ke Hengzhong <[email protected]>
* Copyright (c) 2003-2021 Ke Hengzhong <[email protected]>
* All rights reserved. See MIT LICENSE for redistribution.
*/

Expand Down Expand Up @@ -281,10 +281,11 @@ int cookie_mgmt_read (void * vmgmt, char * cookiefile)

mgmt->cookie_file = cookiefile;

buf[0] = '\0';
for ( ; !feof(fp); ) {
fgets(buf, sizeof(buf)-1, fp);
p = str_trim(buf);
len = strlen(buf);
len = strlen(p);

if (len <= 0 || *p == '#')
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/http_dispdir.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003-2020 Ke Hengzhong <[email protected]>
* Copyright (c) 2003-2021 Ke Hengzhong <[email protected]>
* All rights reserved. See MIT LICENSE for redistribution.
*/

Expand Down
4 changes: 2 additions & 2 deletions src/http_do.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void * do_http_get_msg (void * vmgmt, char * url, int urllen,

msg->dstport = msg->req_port;

msg->SetResponseHandle(msg, resfunc, para, cbval, resfile, resoff, rcvprocfunc, funcpara);
msg->SetResponseNotify(msg, resfunc, para, cbval, resfile, resoff, rcvprocfunc, funcpara);

http_header_append(msg, 0, "Accept", -1, hdr_accept, strlen(hdr_accept));
http_header_append(msg, 0, "Accept-Charset", -1, hdr_accept_charset, strlen(hdr_accept_charset));
Expand Down Expand Up @@ -228,7 +228,7 @@ void * do_http_post_msg (void * vmgmt, char * url, int urllen, char * mime,

msg->dstport = msg->req_port;

msg->SetResponseHandle(msg, resfunc, para, cbval, resfile, resoff, rcvprocfunc, rcvpara);
msg->SetResponseNotify(msg, resfunc, para, cbval, resfile, resoff, rcvprocfunc, rcvpara);

http_header_append(msg, 0, "Accept", -1, hdr_accept, strlen(hdr_accept));
http_header_append(msg, 0, "Accept-Charset", -1, hdr_accept_charset, strlen(hdr_accept_charset));
Expand Down
2 changes: 1 addition & 1 deletion src/http_fcgi_con.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003-2020 Ke Hengzhong <[email protected]>
* Copyright (c) 2003-2021 Ke Hengzhong <[email protected]>
* All rights reserved. See MIT LICENSE for redistribution.
*/

Expand Down
2 changes: 1 addition & 1 deletion src/http_fcgi_srv.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003-2020 Ke Hengzhong <[email protected]>
* Copyright (c) 2003-2021 Ke Hengzhong <[email protected]>
* All rights reserved. See MIT LICENSE for redistribution.
*/

Expand Down
23 changes: 22 additions & 1 deletion src/http_form.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003-2020 Ke Hengzhong <[email protected]>
* Copyright (c) 2003-2021 Ke Hengzhong <[email protected]>
* All rights reserved. See MIT LICENSE for redistribution.
*/

Expand Down Expand Up @@ -95,6 +95,27 @@ void http_form_free (void * vform)
kfree(form);
}

void * http_form_node (void * vmsg, char * key)
{
HTTPMsg * msg = (HTTPMsg *)vmsg;
http_form_t * form = NULL;
int i, num;

if (!msg || !key) return NULL;

num = arr_num(msg->req_formlist);
for (i = 0; i < num; i++) {
form = arr_value(msg->req_formlist, i);
if (!form) continue;

if (form->name && strcasecmp(key, form->name) == 0) {
return form;
}
}

return NULL;
}

int http_form_get (void * vmsg, char * key, char ** ctype, uint8 * formtype, char ** fname, int64 * valuelen)
{
HTTPMsg * msg = (HTTPMsg *)vmsg;
Expand Down
Loading

0 comments on commit 378ccb4

Please sign in to comment.