Sat, 29 Oct 2016 20:02:26 +0200
adds more CGI stuff
sets more env vars
fixes response parser
NSAPIRequest contains host and port now
--- a/src/server/daemon/httprequest.c Fri Oct 28 19:29:38 2016 +0200 +++ b/src/server/daemon/httprequest.c Sat Oct 29 20:02:26 2016 +0200 @@ -28,6 +28,7 @@ #include <stdio.h> #include <stdlib.h> +#include <limits.h> #include <arpa/inet.h> @@ -277,6 +278,20 @@ rq->rq.headers); } + // get host and port + char *hosthdr = pblock_findkeyval(pb_key_host, rq->rq.headers); + if(hosthdr) { + char *host = pool_strdup(pool, hosthdr); + char *portstr = strchr(host, ':'); + if(portstr) { + *portstr = '\0'; + } + rq->host = host; + } else { + rq->host = NULL; // TODO: value from listener + } + rq->port = request->connection->listener->port; + // parse connection header rq->rq.rq_attr.keep_alive = (rq->rq.protv_num >= PROTOCOL_VERSION_HTTP11); char *conn_str = pblock_findkeyval(pb_key_connection, rq->rq.headers);
--- a/src/server/daemon/protocol.c Fri Oct 28 19:29:38 2016 +0200 +++ b/src/server/daemon/protocol.c Sat Oct 29 20:02:26 2016 +0200 @@ -28,13 +28,18 @@ #include "protocol.h" +#include "session.h" +#include "httplistener.h" +#include "request.h" + #include "../util/pblock.h" #include "../util/pool.h" -#include "session.h" #include "../util/io.h" #include "../util/util.h" #include "../util/strbuf.h" +#define HTTP_SCHEME "http" +#define HTTPS_SCHEME "https" void protocol_status(Session *sn, Request *rq, int n, const char *m) { rq->status_num = n; @@ -396,3 +401,30 @@ // TODO: implement return NULL; } + +void http_get_scheme_host_port( + Session *sn, + Request *rq, + char **scheme, + char **host, + uint16_t *port) +{ + Connection *con = ((NSAPISession*)sn)->connection; + + if(con->ssl) { + *scheme = HTTPS_SCHEME; + } else { + *scheme = HTTP_SCHEME; + } + + NSAPIRequest *request = (NSAPIRequest*)rq; + + if(request->host) { + *host = request->host; + } else { + *host = "localhost"; + } + + *port = request->port; + +}
--- a/src/server/daemon/protocol.h Fri Oct 28 19:29:38 2016 +0200 +++ b/src/server/daemon/protocol.h Sat Oct 29 20:02:26 2016 +0200 @@ -48,6 +48,13 @@ int request_header(char *name, char **value, Session *sn, Request *rq); +void http_get_scheme_host_port( + Session *sn, + Request *rq, + char **scheme, + char **host, + uint16_t *port); + #define sbuf_write(out, buf, len) sbuf_append(out, sstrn(buf, len)) #ifdef __cplusplus
--- a/src/server/daemon/request.c Fri Oct 28 19:29:38 2016 +0200 +++ b/src/server/daemon/request.c Sat Oct 29 20:02:26 2016 +0200 @@ -96,6 +96,9 @@ nrq->context.objset_index = -1; nrq->context.dtable_index = 0; + // host and port + + nrq->jvm_context = NULL; @@ -103,7 +106,7 @@ rq->status_num = -1; rq->vfs = NULL; rq->davCollection = NULL; - + return 0; }
--- a/src/server/daemon/request.h Fri Oct 28 19:29:38 2016 +0200 +++ b/src/server/daemon/request.h Sat Oct 29 20:02:26 2016 +0200 @@ -42,6 +42,8 @@ Request rq; RequestStage phase; VirtualServer *vs; + char *host; + uint16_t port; NSAPIContext context; void *jvm_context; };
--- a/src/server/safs/cgi.c Fri Oct 28 19:29:38 2016 +0200 +++ b/src/server/safs/cgi.c Sat Oct 29 20:02:26 2016 +0200 @@ -239,7 +239,7 @@ line_begin = i+1; value_begin = line_begin; space = TRUE; - } else if(c != ' ') { + } else if(!isspace(c)) { space = FALSE; } }
--- a/src/server/safs/cgiutils.c Fri Oct 28 19:29:38 2016 +0200 +++ b/src/server/safs/cgiutils.c Sat Oct 29 20:02:26 2016 +0200 @@ -38,9 +38,11 @@ #include <stdio.h> #include <stdlib.h> +#include <inttypes.h> #include "../util/util.h" #include "../util/pblock.h" +#include "../daemon/protocol.h" //----------------------------------------------------------------------------- @@ -284,33 +286,38 @@ //----------------------------------------------------------------------------- char** cgi_common_vars(Session *sn, Request *rq, char **env) -{ - // TODO: enable code and add cgi_client_auth_vars() - return env; -#if 0 +{ char *t; int x; env = util_env_create(env, MAX_CGI_COMMON_VARS, &x); + /* if (!_env_initialized) cgi_env_init(); if (_env_path) env[x++] = util_env_str("PATH", _env_path); if (_env_tz) env[x++] = util_env_str("TZ", _env_tz); if (_env_lang) env[x++] = util_env_str("LANG", _env_lang); if (_env_ldpath) env[x++] = util_env_str(LIBRARY_PATH, _env_ldpath); env[x++] = util_env_str("SERVER_SOFTWARE", PRODUCT_HEADER_ID"/"PRODUCT_VERSION_ID); + */ // TODO: enable - NSString srvName, portStr; - char buf1[256], buf2[64]; - srvName.useStatic(buf1, sizeof(buf1), 0); - portStr.useStatic(buf2, sizeof(buf2), 0); - GetServerHostnameAndPort(*rq, *sn, srvName, portStr); - env[x++] = util_env_str("SERVER_PORT", (char*)(const char*)portStr); - env[x++] = util_env_str("SERVER_NAME", (char*)(const char*)srvName); - - t = http_uri2url_dynamic("","",sn,rq); - env[x++] = util_env_str("SERVER_URL", t); - FREE(t); + //NSString srvName, portStr; + //char buf1[256], buf2[64]; + //srvName.useStatic(buf1, sizeof(buf1), 0); + //portStr.useStatic(buf2, sizeof(buf2), 0); + //GetServerHostnameAndPort(*rq, *sn, srvName, portStr); + char *scheme; + char *host; + uint16_t port; + http_get_scheme_host_port(sn, rq, &scheme, &host, &port); + char portstr[8]; + snprintf(portstr, 8, "%" PRIu16, (int)port); + env[x++] = util_env_str("SERVER_PORT", host); + env[x++] = util_env_str("SERVER_NAME", portstr); + + //t = http_uri2url_dynamic("","",sn,rq); + //env[x++] = util_env_str("SERVER_URL", t); + //FREE(t); char *ip; ip = pblock_findval("ip", sn->client); @@ -342,6 +349,7 @@ } } +#if 0 if (GetSecurity(sn)) { env[x++] = util_env_str("HTTPS", "ON"); @@ -369,11 +377,12 @@ } else { env[x++] = util_env_str("HTTPS", "OFF"); } +#endif env[x] = NULL; - env = cgi_client_auth_vars(sn, rq, env); + //env = cgi_client_auth_vars(sn, rq, env); // TODO: enable return env; -#endif + }