示例#1
0
int
Ns_ParseHeader(Ns_Set *set, char *line, Ns_HeaderCaseDisposition disp)
{
    char           *key, *sep;
    char           *value;
    int             index;
    Ns_DString	    ds;

    /* 
     * Header lines are first checked if they continue a previous
     * header indicated by any preceeding white space.  Otherwise,
     * they must be in well form key: value form.
     */

    if (isspace(UCHAR(*line))) {
        index = Ns_SetLast(set);
        if (index < 0) {
	    return NS_ERROR;	/* Continue before first header. */
        }
        while (isspace(UCHAR(*line))) {
            ++line;
        }
        if (*line != '\0') {
	    value = Ns_SetValue(set, index);
	    Ns_DStringInit(&ds);
	    Ns_DStringVarAppend(&ds, value, " ", line, NULL);
	    Ns_SetPutValue(set, index, ds.string);
	    Ns_DStringFree(&ds);
	}
    } else {
        sep = strchr(line, ':');
        if (sep == NULL) {
	    return NS_ERROR;	/* Malformed header. */
	}
        *sep = '\0';
        value = sep + 1;
        while (*value != '\0' && isspace(UCHAR(*value))) {
            ++value;
        }
        index = Ns_SetPut(set, line, value);
        key = Ns_SetKey(set, index);
	if (disp == ToLower) {
            while (*key != '\0') {
	        if (isupper(UCHAR(*key))) {
            	    *key = tolower(UCHAR(*key));
		}
            	++key;
	    }
	} else if (disp == ToUpper) {
            while (*key != '\0') {
	        if (islower(UCHAR(*key))) {
		    *key = toupper(UCHAR(*key));
		}
		++key;
	    }
        }
        *sep = ':';
    }
    return NS_OK;
}
示例#2
0
void
NsUpdateMimeTypes(void)
{
    Ns_Set *set;
    int     i;

    set = Ns_ConfigGetSection("ns/mimetypes");
    if (set == NULL) {
	return;
    }

    defaultType = Ns_SetIGet(set, "default");
    if (defaultType == NULL) {
	defaultType = TYPE_DEFAULT;
    }

    noextType = Ns_SetIGet(set, "noextension");
    if (noextType == NULL) {
	noextType = defaultType;
    }

    for (i=0; i < Ns_SetSize(set); i++) {
        AddType(Ns_SetKey(set, i), Ns_SetValue(set, i));
    }
}
示例#3
0
static void
php_ns_sapi_register_variables(zval *track_vars_array)
{
	int i;
	char buf[NS_BUF_SIZE + 1];
	char *tmp;

	for(i = 0; i < Ns_SetSize(NSG(conn->headers)); i++) {
		char *key = Ns_SetKey(NSG(conn->headers), i);
		char *value = Ns_SetValue(NSG(conn->headers), i);
		char *p;
		char c;

		snprintf(buf, NS_BUF_SIZE, "HTTP_%s", key);
		
		for(p = buf + 5; (c = *p); p++) {
			c = toupper(c);
			if(c < 'A' || c > 'Z') {
				c = '_';
			}
			*p = c;
		}

		ADD_STRINGX(buf, value);
	}
	
	snprintf(buf, NS_BUF_SIZE, "%s/%s", Ns_InfoServerName(), Ns_InfoServerVersion());
	ADD_STRING("SERVER_SOFTWARE");
	snprintf(buf, NS_BUF_SIZE, "HTTP/%1.1f", NSG(conn)->request->version);
	ADD_STRING("SERVER_PROTOCOL");

	ADD_STRINGX("REQUEST_METHOD", NSG(conn)->request->method);

	if(NSG(conn)->request->query)
		ADD_STRINGX("QUERY_STRING", NSG(conn)->request->query);
	
	ADD_STRINGX("SERVER_BUILDDATE", Ns_InfoBuildDate());

	ADD_STRINGX("REMOTE_ADDR", Ns_ConnPeer(NSG(conn)));

	snprintf(buf, NS_BUF_SIZE, "%d", Ns_ConnPeerPort(NSG(conn)));
	ADD_STRING("REMOTE_PORT");

	snprintf(buf, NS_BUF_SIZE, "%d", Ns_ConnPort(NSG(conn)));
	ADD_STRING("SERVER_PORT");

	tmp = Ns_ConnHost(NSG(conn));
	if (tmp)
		ADD_STRINGX("SERVER_NAME", tmp);

	ADD_STRINGX("PATH_TRANSLATED", SG(request_info).path_translated);
	ADD_STRINGX("REQUEST_URI", SG(request_info).request_uri);
	ADD_STRINGX("PHP_SELF", SG(request_info).request_uri);

	ADD_STRINGX("GATEWAY_INTERFACE", "CGI/1.1");

	snprintf(buf, NS_BUF_SIZE, "%d", Ns_InfoBootTime());
	ADD_STRING("SERVER_BOOTTIME");
}
示例#4
0
static char *php_ns_sapi_read_cookies(void)
{
	int i;
	char *http_cookie = NULL;
	
	i = Ns_SetIFind(NSG(conn->headers), "cookie");
	if(i != -1) {
		http_cookie = Ns_SetValue(NSG(conn->headers), i);
	}

	return http_cookie;
}
示例#5
0
static void 
php_ns_config(php_ns_context *ctx, char global)
{
	int i;
	char *path;
	Ns_Set *set;

	path = Ns_ConfigGetPath(ctx->ns_server, ctx->ns_module, NULL);
	set = Ns_ConfigGetSection(path);

	for (i = 0; set && i < Ns_SetSize(set); i++) {
		char *key = Ns_SetKey(set, i);
		char *value = Ns_SetValue(set, i);

		if (global && !strcasecmp(key, "map")) {
			Ns_Log(Notice, "Registering PHP for \"%s\"", value);
			Ns_RegisterRequest(ctx->ns_server, "GET", value, php_ns_request_handler, NULL, ctx, 0);
			Ns_RegisterRequest(ctx->ns_server, "POST", value, php_ns_request_handler, NULL, ctx, 0);
			Ns_RegisterRequest(ctx->ns_server, "HEAD", value, php_ns_request_handler, NULL, ctx, 0);

	/* 
	 * Deactivated for now. The ini system will cause random crashes when 
	 * accessed from here (since there are no locks to protect the global 
	 * known_directives) 
	 */

		} else if (!global && !strcasecmp(key, "php_value")) {
			Ns_Log(Notice, "php_value has been deactivated temporarily. Please use a php.ini file to pass directives to PHP. Thanks.");
#if 0
			char *val;

			val = strchr(value, ' ');
			if (val) {
				char *new_key;
				
				new_key = estrndup(value, val - value);
				
				do { 
					val++; 
				} while(*val == ' ');

				Ns_Log(Debug, "PHP configuration option '%s=%s'", new_key, val);
				zend_alter_ini_entry(new_key, strlen(new_key) + 1, val, 
						strlen(val) + 1, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
				
				efree(new_key);
			}
#endif
		}
		
	}
}
示例#6
0
static void php_info_aolserver(ZEND_MODULE_INFO_FUNC_ARGS)
{
	char buf[512];
	int uptime = Ns_InfoUptime();
	int i;
	
	php_info_print_table_start();
	php_info_print_table_row(2, "SAPI module version", "$Id$");
	php_info_print_table_row(2, "Build date", Ns_InfoBuildDate());
	php_info_print_table_row(2, "Config file path", Ns_InfoConfigFile());
	php_info_print_table_row(2, "Error Log path", Ns_InfoErrorLog());
	php_info_print_table_row(2, "Installation path", Ns_InfoHomePath());
	php_info_print_table_row(2, "Hostname of server", Ns_InfoHostname());
	php_info_print_table_row(2, "Source code label", Ns_InfoLabel());
	php_info_print_table_row(2, "Server platform", Ns_InfoPlatform());
	snprintf(buf, 511, "%s/%s", Ns_InfoServerName(), Ns_InfoServerVersion());
	php_info_print_table_row(2, "Server version", buf);
	snprintf(buf, 511, "%d day(s), %02d:%02d:%02d", 
			uptime / 86400,
			(uptime / 3600) % 24,
			(uptime / 60) % 60,
			uptime % 60);
	php_info_print_table_row(2, "Server uptime", buf);
	php_info_print_table_end();

	SECTION("HTTP Headers Information");
	php_info_print_table_start();
	php_info_print_table_colspan_header(2, "HTTP Request Headers");
	php_info_print_table_row(2, "HTTP Request", NSG(conn)->request->line);
	for (i = 0; i < Ns_SetSize(NSG(conn)->headers); i++) {
		php_info_print_table_row(2, Ns_SetKey(NSG(conn)->headers, i), Ns_SetValue(NSG(conn)->headers, i));
	}

	php_info_print_table_colspan_header(2, "HTTP Response Headers");
	for (i = 0; i < Ns_SetSize(NSG(conn)->outputheaders); i++) {
		php_info_print_table_row(2, Ns_SetKey(NSG(conn)->outputheaders, i), Ns_SetValue(NSG(conn)->outputheaders, i));
	}
	php_info_print_table_end();
}
示例#7
0
static void 
php_ns_request_ctor(void)
{
	char *server;
	Ns_DString ds;
	char *root;
	int index;
	char *tmp;
	
	server = Ns_ConnServer(NSG(conn));
	
#define safe_strdup(x) ((x)?strdup((x)):NULL)
	SG(request_info).query_string = safe_strdup(NSG(conn->request->query));

	Ns_DStringInit(&ds);
	Ns_UrlToFile(&ds, server, NSG(conn->request->url));
	
	/* path_translated is the absolute path to the file */
	SG(request_info).path_translated = safe_strdup(Ns_DStringValue(&ds));
	Ns_DStringFree(&ds);
	root = Ns_PageRoot(server);
	SG(request_info).request_uri = strdup(SG(request_info).path_translated + strlen(root));
	SG(request_info).request_method = NSG(conn)->request->method;
	if(NSG(conn)->request->version > 1.0) SG(request_info).proto_num = 1001;
	else SG(request_info).proto_num = 1000;
	SG(request_info).content_length = Ns_ConnContentLength(NSG(conn));
	index = Ns_SetIFind(NSG(conn)->headers, "content-type");
	SG(request_info).content_type = index == -1 ? NULL : 
		Ns_SetValue(NSG(conn)->headers, index);
	SG(sapi_headers).http_response_code = 200;

	tmp = Ns_ConnAuthUser(NSG(conn));
	if (tmp)
		tmp = estrdup(tmp);
	SG(request_info).auth_user = tmp;

	tmp = Ns_ConnAuthPasswd(NSG(conn));
	if (tmp)
		tmp = estrdup(tmp);
	SG(request_info).auth_password = tmp;

	NSG(data_avail) = SG(request_info).content_length;
}
示例#8
0
int
Ns_ExecArgv(char *exec, char *dir, int fdin, int fdout,
	    char **argv, Ns_Set *env)
{
#ifdef _WIN32
    /*
     * Win32 ExecArgv simply calls ExecArgblk.
     */
    int             pid;     
    Ns_DString      ads;
    char	   *args;
    int		    i;

    Ns_DStringInit(&ads);
    if (argv == NULL) {
        args = NULL;
    } else {
        for (i = 0; argv[i] != NULL; ++i) {
            Ns_DStringNAppend(&ads, argv[i], strlen(argv[i]) + 1);
        }
        args = ads.string;
    }
    pid = Ns_ExecArgblk(exec, dir, fdin, fdout, args, env);
    Ns_DStringFree(&ads);
    return pid;
#else
    Ns_DString eds;
    char *argvSh[4], **envp;
    int i, pid;
    
    if (exec == NULL) {
        return -1;
    }
    if (argv == NULL) {
        argv = argvSh;
        argv[0] = "/bin/sh";
        argv[1] = "-c";
        argv[2] = exec;
        argv[3] = NULL;
        exec = argv[0];
    }
    Ns_DStringInit(&eds);
    if (env == NULL) {
	envp = Ns_CopyEnviron(&eds);
    } else {
	for (i = 0; i < Ns_SetSize(env); ++i) {
            Ns_DStringVarAppend(&eds,
		Ns_SetKey(env, i), "=", Ns_SetValue(env, i), NULL);
            Ns_DStringNAppend(&eds, "", 1);
	}
	Ns_DStringNAppend(&eds, "", 1);
	envp = Ns_DStringAppendArgv(&eds);
    }
    if (fdin < 0) {
	fdin = 0;
    }
    if (fdout < 0) {
	fdout = 1;
    }
    pid = ExecProc(exec, dir, fdin, fdout, argv, envp);
    Ns_DStringFree(&eds);
    return pid;
#endif
}