Exemplo n.º 1
0
static inline ListCell *parseQS(char *path) {
    ListCell *qs = NULL;

    char *copy = bsNew(path);
    char *segment, *key, *value;

    bool s = true;

    for (;;) {
        if (s) {segment = strtok(copy, "="); s = false;}
        else   {segment = strtok(NULL, "=");}

        if (segment == NULL) break;
        if (*(segment + strlen(segment) + 1) == '&') continue;

        key     = segment;
        segment = strtok(NULL, "&\0");

        if (segment == NULL) break;

        key   = urldecode(key);
        value = urldecode(segment);
        qs    = listCons(kvNew(key, value), sizeof(KV), qs);

        bsDel(key);
        bsDel(value);
    }

    bsDel(copy);

    return qs;
}
Exemplo n.º 2
0
static int http_parse_arguments(struct http_request *r, NMEM nmem,
                                const char *args)
{
    const char *p2 = args;

    while (*p2)
    {
        struct http_argument *a;
        const char *equal = strchr(p2, '=');
        const char *eoa = strchr(p2, '&');
        if (!equal)
        {
            yaz_log(YLOG_WARN, "Expected '=' in argument");
            return -1;
        }
        if (!eoa)
            eoa = equal + strlen(equal); // last argument
        else if (equal > eoa)
        {
            yaz_log(YLOG_WARN, "Missing '&' in argument");
            return -1;
        }
        a = nmem_malloc(nmem, sizeof(struct http_argument));
        a->name = nmem_strdupn(nmem, p2, equal - p2);
        a->value = nmem_strdupn(nmem, equal+1, eoa - equal - 1);
        urldecode(a->name, a->name);
        urldecode(a->value, a->value);
        a->next = r->arguments;
        r->arguments = a;
        p2 = eoa;
        while (*p2 == '&')
            p2++;
    }
    return 0;
}
Exemplo n.º 3
0
static void insert(nvlist_t *vars, struct qstr *name, struct qstr *val)
{
	urldecode(name->buf, name->idx, name->buf);
	urldecode(val->buf, val->idx, val->buf);

	/* now, {name,val}->buf are null-terminated strings */

	nvl_set_str(vars, name->buf, val->buf);
}
Exemplo n.º 4
0
/* 处理模块 */
void httpcws_handler(struct evhttp_request *req, void *arg)
{	
        struct evbuffer *buf;
        buf = evbuffer_new();
		
		/* 分析URL参数 */
		struct evkeyvalq httpcws_http_query;
		evhttp_parse_query(evhttp_request_uri(req), &httpcws_http_query);
		
		/* 接收POST表单信息 */
		const char *tcsql_input_postbuffer = (const char*) EVBUFFER_DATA(req->input_buffer);		
		
		/* 接收GET表单参数 */
		const char *httpcws_input_words = evhttp_find_header (&httpcws_http_query, "w");

		const char *httpcws_output_tmp = NULL;
		char *httpcws_output_words = "\0";
		if (tcsql_input_postbuffer != NULL) {
			char *tcsql_input_postbuffer_tmp = (char *) malloc(EVBUFFER_LENGTH(req->input_buffer)+1);
			memset (tcsql_input_postbuffer_tmp, '\0', EVBUFFER_LENGTH(req->input_buffer)+1);
			strncpy(tcsql_input_postbuffer_tmp, tcsql_input_postbuffer, EVBUFFER_LENGTH(req->input_buffer));
			char *decode_uri = urldecode(tcsql_input_postbuffer_tmp);
			free(tcsql_input_postbuffer_tmp);
			httpcws_output_tmp = ICTCLAS_ParagraphProcess(decode_uri, 0);
			free(decode_uri);
			httpcws_output_words = strdup(httpcws_output_tmp);
			trim (httpcws_output_words);
		} else if (httpcws_input_words != NULL) {
			char *httpcws_input_words_tmp = strdup(httpcws_input_words);
			char *decode_uri = urldecode(httpcws_input_words_tmp);
			free(httpcws_input_words_tmp);
			httpcws_output_tmp = ICTCLAS_ParagraphProcess(decode_uri, 0);
			free(decode_uri);
			httpcws_output_words = strdup(httpcws_output_tmp);
			trim (httpcws_output_words);
		} else {
			httpcws_output_words = strdup("");
		}
		
		/* 输出内容给客户端 */
		evhttp_add_header(req->output_headers, "Server", "HTTPCWS/1.0.0");
		evhttp_add_header(req->output_headers, "Content-Type", "text/plain; charset=GB2312");
		evhttp_add_header(req->output_headers, "Connection", "close");
		evbuffer_add_printf(buf, "%s", httpcws_output_words);
        evhttp_send_reply(req, HTTP_OK, "OK", buf);
		
		free(httpcws_output_words);
		evhttp_clear_headers(&httpcws_http_query);
		evbuffer_free(buf);	
}
Exemplo n.º 5
0
static struct lh_kv_elem* parse_url_params(char *sparams) {
    if (!sparams)
        return NULL;
    struct lh_kv_elem *param = NULL;
    char *key = sparams;
    while (1) {
        char *eq_mark = strchr(key, '=');
        if (eq_mark == NULL)
            break;
        char *value = eq_mark + 1;
        struct lh_kv_elem *newparam = malloc(sizeof(struct lh_kv_elem));
        newparam->next = param;
        newparam->key = key;
        newparam->value = value;
        param = newparam;
        
        char *and_mark = strchr(value, '&');
        *eq_mark = 0;
        //urldecode(key);
        if (and_mark)
            *and_mark = 0;
        urldecode(value);
        if (and_mark == NULL)
            break;
        key = and_mark + 1;
    }
    return param;
}
Exemplo n.º 6
0
static int
pkg_string(struct pkg *pkg, ucl_object_t *obj, int attr)
{
	int ret = EPKG_OK;
	const char *str;
	str = ucl_object_tostring_forced(obj);

	switch (attr)
	{
	case PKG_LICENSE_LOGIC:
		if (!strcmp(str, "single"))
			pkg_set(pkg, PKG_LICENSE_LOGIC, (int64_t) LICENSE_SINGLE);
		else if (!strcmp(str, "or") ||
		         !strcmp(str, "dual"))
			pkg_set(pkg, PKG_LICENSE_LOGIC, (int64_t)LICENSE_OR);
		else if (!strcmp(str, "and") ||
		         !strcmp(str, "multi"))
			pkg_set(pkg, PKG_LICENSE_LOGIC, (int64_t)LICENSE_AND);
		else {
			pkg_emit_error("Unknown license logic: %s", str);
			ret = EPKG_FATAL;
		}
		break;
	default:
		if (attr == PKG_DESC)
			ret = urldecode(str, &pkg->fields[attr]);
		else
			ret = pkg_set(pkg, attr, str);
		break;
	}

	return (ret);
}
Exemplo n.º 7
0
		/// Parse some data. The enum return value is good when a complete request has
		/// been parsed, bad if the data is invalid, indeterminate when more data is
		/// required. The InputIterator return value indicates how much of the input
		/// has been consumed.
		result_type parse(boost::asio::streambuf& buf)
		{
			int c = EOF;
			while ((c = buf.sbumpc()) != EOF)
			{
				result_type result = consume(c);
				if (result == good || result == bad)
				{
					std::string url = urldecode(url_);
					std::string::size_type qmak_pos = url.find("?");
					if (qmak_pos == std::string::npos)
					{
						path_ = url;
					}
					else
					{
						path_ = url.substr(0, qmak_pos);
						std::string quert_str = url.substr(qmak_pos + 1, url.size());
						query_ = query_parser(quert_str);
					}
					return result;
				}
			}
			return indeterminate;
		}
Exemplo n.º 8
0
int extract_query_string(struct form_t *form, const char *query_string){
    int count = 0;
    if (!query_string){
        return count;
    }
    query_string = urldecode(query_string);
    while (query_string && *query_string){
        const char *name;
        const char *value;
        char *eq = strchr(query_string, '=');
        if (eq){
            name = strndup(query_string, (size_t)(eq - query_string));
            query_string = eq + 1;
            char *amp = strchr(query_string, '&');
            if (amp){
                value = strndup(query_string, (size_t)(amp - query_string));
                query_string = amp + 1;
            } else {
                value = strdup(query_string);
                query_string = strchr(query_string, '\0');
            }
        } else {
            name = strdup(query_string);
            value = NULL;
            query_string = strchr(query_string, '\0');
        }
        if (strlen(name) > 0){
            add_var_to_form(form, name, value);
            count++;
        }
    }
    return count;
}
Exemplo n.º 9
0
static int parse_request(struct fd_state *state) {
    assert(state && state->read_buf);
	//printf("%s", state->read_buf);
    char *path = strchr(state->read_buf, '/');
    if (path == NULL)
        return -1;
    
    char *scookies = strstr(path, "Cookie: ");
    if (scookies)
        scookies += 8;
    char *space = strchr(path, ' ');
    if (space) {
        *space = 0;
    }
    char *question = strchr(path, '?');
    if (question)
        *question = 0;
    urldecode(path);
    
    char *sparams = NULL;
    if (question)
        sparams = question + 1;
    
    int iscalled = call_callback(state, path, sparams, scookies);
    if (iscalled) {
        return 0;
    }
    const char *dot = strrchr(path, '.');
    if (dot) {  //file
        const char *ext = dot + 1;
        const char *mime = "text/plain";
        if (strcmp(ext, "html") == 0 || strcmp(ext, "htm") == 0) {
            mime = "text/html";
        } else if (strcmp(ext, "css") == 0) {
            mime = "text/css";
        } else if (strcmp(ext, "js") == 0) {
            mime = "text/javascript";
        } else if (strcmp(ext, "png") == 0) {
            mime = "image/png";
        } else if (strcmp(ext, "jpeg") == 0 || strcmp(ext, "jpg") == 0 || strcmp(ext, "jpe") == 0 ) {
            mime = "image/jpeg";
        } else if (strcmp(ext, "gif") == 0) {
            mime = "image/gif";
        }
        char abspath[1024];
        strncpy(abspath, _root_dir, sizeof(abspath));
        strncat(abspath, path, sizeof(abspath)-strlen(path));
        state->pf = fopen(abspath, "r");
        if (state->pf) {
            fseek(state->pf, 0, SEEK_END);
            write_response_header(state, mime, ftell(state->pf), "");
            rewind(state->pf);
        } else {
            write_response_error(state);
        }
    } else { //func
        write_response_error(state);
    }
    return 0;
}
Exemplo n.º 10
0
int http_parse_query(char *url, KeyValuePair *params, const int max_count)
{
	KeyValuePair *pCurrent;
	KeyValuePair *pEnd;
	char *pParamStart;
	char *p;
	char *pStrEnd;
	int value_len;

	pParamStart = strchr(url, '?');
	if (pParamStart == NULL)
	{
		return 0;
	}

	*pParamStart = '\0';

	pEnd = params + max_count;
	pCurrent = params;
	p = pParamStart + 1;
	while (p != NULL && *p != '\0')
	{
		if (pCurrent >= pEnd)
		{
			return pCurrent - params;
		}

		pCurrent->key = p;
		pStrEnd = strchr(p, '&');
		if (pStrEnd == NULL)
		{
			p = NULL;
		}
		else
		{
			*pStrEnd = '\0';
			p = pStrEnd + 1;
		}

		pStrEnd = strchr(pCurrent->key, '=');
		if (pStrEnd == NULL)
		{
			continue;
		}

		*pStrEnd = '\0';
		pCurrent->value = pStrEnd + 1;
		if (*pCurrent->key == '\0')
		{
			continue;
		}

		urldecode(pCurrent->value, strlen(pCurrent->value), \
			pCurrent->value, &value_len);
		pCurrent++;
	}

	return pCurrent - params;
}
Exemplo n.º 11
0
int llspaux::lua_urldecode(lua_State* L)
{
    size_t len=0;

    const char* p=lua_tolstring(L,1,&len);

    return urldecode(L,p,len);
}
Exemplo n.º 12
0
    void test_urldecode()
    {
        std::string ia("");
        urldecode(ia);
        assert_equal(ia, "");

        std::string ib("abc def");
        urldecode(ib);
        assert_equal(ib, "abc def");

        std::string ic("+%20");
        urldecode(ic);
        assert_equal(ic, "  ");

        std::string id("%41+string+ending+in+%");
        urldecode(id);
        assert_equal(id, "A string ending in %");
    }
Exemplo n.º 13
0
static int
set_path(PyObject *env, char *buf, int len)
{
    int c, c1, slen;
    char *s0, *t;
    PyObject *obj;

    t = s0 = buf;
    while(len > 0){
        c = *buf++;
        if(c == '%' && len > 2){
            c = *buf++;
            c1 = c;
            c = *buf++;
            c = hex2int(c1) * 16 + hex2int(c);
            len -= 2;
        }else if(c == '?'){
            //stop
            if(set_query(env, buf, len) == -1){
                //Error
                return -1;
            }
            break;
        }else if(c == '#'){
            //stop 
            //ignore fragment
            break;
        }
        *t++ = c;
        len--;
    }
    //*t = 0;
    slen = t - s0;
    slen = urldecode(s0, slen);

    obj = PyBytes_FromStringAndSize(s0, slen);
    /* DEBUG("path:%.*s", (int)slen, PyBytes_AS_STRING(obj)); */

    if(likely(obj != NULL)){
#ifdef PY3
        //TODO CHECK ERROR 
        char *c2 = PyBytes_AS_STRING(obj);
        PyObject *v = PyUnicode_DecodeUTF8(c2, strlen(c2), NULL);
        PyDict_SetItem(env, path_info_key, v);
        Py_DECREF(v);
#else
        PyDict_SetItem(env, path_info_key, obj);
#endif
        Py_DECREF(obj);
        return slen;
    }else{
        return -1;
    }

}
Exemplo n.º 14
0
int llspaux::args(lua_State* L,const char* p,size_t len)
{
    lua_newtable(L);
    
    size_t offset1=0,length1=0;
    size_t offset2=0,length2=0;

    size_t i;

    for(i=0;i<len;++i)
    {    
	if(p[i]=='=')
	{
	    length1=i-offset1;
	    offset2=i+1;
	}else if(p[i]=='&')
	{
	    length2=i-offset2;
	    
	    if(length1 && length2)
	    {	    
		lua_pushlstring(L,p+offset1,length1);
		urldecode(L,p+offset2,length2);
		lua_rawset(L,-3);
	    }
	    
	    offset1=i+1;
	    length1=offset2=length2=0;
	}
    }

    length2=i-offset2;

    if(length1 && length2)
    {	    
	lua_pushlstring(L,p+offset1,length1);
	urldecode(L,p+offset2,length2);
	lua_rawset(L,-3);
    }

    return 1;
}
Exemplo n.º 15
0
static int L_urldecode( lua_State* L ) 
{
    const char* param;
    char* data;
    PARAM_STRING( param );
    data = strdup( param );
    urldecode( data );
    RETURN_STRING( data );
    free( data );
    return 1;
}
Exemplo n.º 16
0
static int parse_query(char* query, int ql, char* params[], char* values[]) {
  int count=0;
  int i,pi,vi;

  for(i=0;i<ql;i++) {
    pi=i;
    for(;i<ql;i++) {
      if (query[i]=='=') { query[i]=0; break; }
    }
    i++;
    if (i>=ql) return -1;
    vi=i;
    for(;i<ql;i++) {
      if (query[i]=='&') { query[i]=0; break; }
    }
    if (count>=MAXPARAMS) return -1;
    params[count]=urldecode(query+pi,query+pi);
    values[count]=urldecode(query+vi,query+vi);
    count++;
  }
  return count;
}
Exemplo n.º 17
0
int CompileWork::GetTextAreaValue()
{
	string textareaname = Config::GetInstance()->GetValue("TEXTAREANAME");
	if(textareaname.empty())
		textareaname = TEXTAREANAME;
	textAreaValue = requestHttp->GetQueryParamValue(TEXTAREANAME);
	if(textAreaValue == RT_INFO[RT_ERR])
	{
		return RT_ERR;
	}
	textAreaValue = urldecode(textAreaValue);

	return RT_OK;
}
Exemplo n.º 18
0
int main ( int argc, char **argv ) {

	assert(argc > 1 );

	char in[BUF_SIZE];
	char out[BUF_SIZE];

	sprintf(in, "%s", argv[1]);
	printf("in: %s\n", in);
	urldecode(in, out);
	printf("out: %s\n", out);

	return 0;
}
Exemplo n.º 19
0
int winargs(int argc, char **argv, char *buffer)
{
    if (argc == 2)
    {
        if (!(strlen(argv[1]) < MaxBuffer - 1))
            return 0;

        if (strstr(argv[1], "garglk:///"))
            return urldecode(buffer, MaxBuffer, argv[1]+10);

        strcpy(buffer, argv[1]);
    }

    return (argc == 2);
}
Exemplo n.º 20
0
static int
pkg_set_from_node(struct pkg *pkg, yaml_node_t *val, __unused yaml_document_t *doc, int attr)
{
	int ret = EPKG_OK;

	while (val->data.scalar.length > 0 &&
			val->data.scalar.value[val->data.scalar.length - 1] == '\n') {
		val->data.scalar.value[val->data.scalar.length - 1] = '\0';
		val->data.scalar.length--;
	}

	ret = urldecode(val->data.scalar.value, &pkg->fields[attr]);

	return (ret);
}
Exemplo n.º 21
0
/* Parse url parameters and save them to params array. The pch pointer is increased to the position where parsing stopped. */
void parseParams(struct uriparams *params, char *pch)
{
	char *pch2;
	// parsemode = 1 means parsing next param, parsemode = -1 parsing next
	//value; pch2 points to the beginning of the currently parsed string, pch is the current position
	int32_t parsemode = 1;

	pch2 = pch;
	while(pch[0] != '\0')
	{
		if((parsemode == 1 && pch[0] == '=') || (parsemode == -1 && pch[0] == '&'))
		{
			pch[0] = '\0';
			urldecode(pch2);
			if(parsemode == 1)
			{
				if(params->paramcount >= MAXGETPARAMS) { break; }
				++params->paramcount;
				params->params[params->paramcount - 1] = pch2;
			}
			else
			{
				params->values[params->paramcount - 1] = pch2;
			}
			parsemode = -parsemode;
			pch2 = pch + 1;
		}
		++pch;
	}
	/* last value wasn't processed in the loop yet... */
	if(parsemode == -1 && params->paramcount <= MAXGETPARAMS)
	{
		urldecode(pch2);
		params->values[params->paramcount - 1] = pch2;
	}
}
Exemplo n.º 22
0
static int
set_path(PyObject *env, char *buf, int len)
{
    int c, c1, slen;
    char *s0, *t;
    PyObject *obj;

    t = s0 = buf;
    while(len > 0){
        c = *buf++;
        if(c == '%' && len > 2){
            c = *buf++;
            c1 = c;
            c = *buf++;
            c = hex2int(c1) * 16 + hex2int(c);
            len -= 2;
        }else if(c == '?'){
            //stop
            if(set_query(env, buf, len) == -1){
                //Error
                return -1;
            }
            break;
        }else if(c == '#'){
            //stop 
            //ignore fragment
            break;
        }
        *t++ = c;
        len--;
    }
    //*t = 0;
    slen = t - s0;
    slen = urldecode(s0, slen);

#ifdef PY3
    obj = PyUnicode_DecodeLatin1(s0, slen, "strict");
#else
    obj = PyBytes_FromStringAndSize(s0, slen);
#endif
    if (likely(obj != NULL)) {
        PyDict_SetItem(env, path_info_key, obj);
        Py_DECREF(obj);
        return slen;
    } else {
        return -1;
    }
}
Exemplo n.º 23
0
static int
pkg_set_files_from_object(struct pkg *pkg, ucl_object_t *obj)
{
	ucl_object_t *cur;
	ucl_object_iter_t it = NULL;
	const char *sum = NULL;
	const char *uname = NULL;
	const char *gname = NULL;
	void *set = NULL;
	mode_t perm = 0;
	struct sbuf *fname = NULL;
	const char *key, *okey;

	okey = ucl_object_key(obj);
	if (okey == NULL)
		return (EPKG_FATAL);
	urldecode(okey, &fname);
	while ((cur = ucl_iterate_object(obj, &it, true))) {
		key = ucl_object_key(cur);
		if (key == NULL)
			continue;
		if (!strcasecmp(key, "uname") && cur->type == UCL_STRING)
			uname = ucl_object_tostring(cur);
		else if (!strcasecmp(key, "gname") && cur->type == UCL_STRING)
			gname = ucl_object_tostring(cur);
		else if (!strcasecmp(key, "sum") && cur->type == UCL_STRING &&
		    strlen(ucl_object_tostring(cur)) == 64)
			sum = ucl_object_tostring(cur);
		else if (!strcasecmp(key, "perm") &&
		    (cur->type == UCL_STRING || cur->type == UCL_INT)) {
			if ((set = setmode(ucl_object_tostring_forced(cur))) == NULL)
				pkg_emit_error("Not a valid mode: %s",
				    ucl_object_tostring(cur));
			else
				perm = getmode(set, 0);
		} else {
			pkg_emit_error("Skipping unknown key for file(%s): %s",
			    sbuf_data(fname), ucl_object_tostring(cur));
		}
	}

	pkg_addfile_attr(pkg, sbuf_data(fname), sum, uname, gname, perm, false);
	sbuf_delete(fname);

	return (EPKG_OK);
}
Exemplo n.º 24
0
Arquivo: Client.cpp Projeto: Damax/zia
void	Client::setPathFromUri(Transaction&  trans)
{
  std::string uri = trans.getRequest().getUri();
  std::string res;

  if (uri.substr(0, 7) == "http://")
    {
      size_t slash_pos = uri.find("/", 8);
      if (slash_pos == std::string::npos)
	res = "/";
      else
	res = uri.substr(slash_pos);
    }
  else
    res = uri;
  res = urldecode(res);
  std::string final;
  std::string port = inttostr(trans.getClientEndPoint().getPort());
  std::string host = trans.getRequest().getHeaders()["HOST"];
  final = Conf::Inst().get("documentroot", "/var/www", port, host);
Exemplo n.º 25
0
int main(int argc, char **argv)
{
    char data[4096];
    ssize_t bytes;
    
    decoder_state state;
    state.state = ST_SYM;
    while ((bytes = read(0, data, sizeof(data))) > 0)
    {
        bytes = urldecode(&state, data, bytes);
        if (bytes > 0)
        {
            write(1, data, bytes);
        }
        else
        {
            return 1;
        }
    }
    return 0;
}
Exemplo n.º 26
0
static int
pkg_set_dirs_from_object(struct pkg *pkg, ucl_object_t *obj)
{
	ucl_object_t *cur;
	ucl_object_iter_t it = NULL;
	const char *uname = NULL;
	const char *gname = NULL;
	void *set;
	mode_t perm = 0;
	bool try = false;
	struct sbuf *dirname = NULL;
	const char *key, *okey;

	okey = ucl_object_key(obj);
	if (okey == NULL)
		return (EPKG_FATAL);
	urldecode(okey, &dirname);
	while ((cur = ucl_iterate_object(obj, &it, true))) {
		key = ucl_object_key(cur);
		if (key == NULL)
			continue;
		if (!strcasecmp(key, "uname") && cur->type == UCL_STRING)
			uname = ucl_object_tostring(cur);
		else if (!strcasecmp(key, "gname") && cur->type == UCL_STRING)
			gname = ucl_object_tostring(cur);
		else if (!strcasecmp(key, "perm") &&
		    (cur->type == UCL_STRING || cur->type == UCL_INT)) {
			if ((set = setmode(ucl_object_tostring_forced(cur))) == NULL)
				pkg_emit_error("Not a valid mode: %s",
				    ucl_object_tostring(cur));
			else
				perm = getmode(set, 0);
		} else if (!strcasecmp(key, "try") && cur->type == UCL_BOOLEAN) {
				try = ucl_object_toint(cur);
		} else {
			pkg_emit_error("Skipping unknown key for dir(%s): %s",
			    sbuf_data(dirname), key);
		}
	}
Exemplo n.º 27
0
int main(int argc,char*argv[]) {
	char *data = NULL;
	int len,nel;
	char *q,*value,*name;
	char cmd[80];
        char username[80][80] ;
	printf("%s%c%c\n","Content-Type:text/html;charset=utf-8",13,10);
	printf("<TITLE>Uploading</TITLE>\n");
	data = getenv("QUERY_STRING");
	printf("%s",data);
	urldecode(data);

	printf("%s",data);
	q = data;
	nel = 0;
	len = strlen(data);
	int i = 0;
	if (data == NULL)
		printf("<p>Error!Error in passing data from form to script.");
	else {
	while(strsep(&q,"&"))
			nel++;
		for(q=data;q<(data+len);){
			value=name=q;
			for(q+=strlen(q);q<(data+len)&&!*q;q++);
			name=strsep(&value,"=");
			printf("%s\n",name);
			printf("%s\n",value);
			printf("<br/>");
			sprintf(cmd,"sh upload.sh %s",value);
			printf("%s",cmd);
	//		system("ls");
				system(cmd);
		}
	}
	return 0; 
}
Exemplo n.º 28
0
		result_type parse(InputIterator begin, InputIterator end)
		{
			while (begin != end)
			{
				result_type result = consume(*begin++);
				if (result == good || result == bad)
				{
					std::string url = urldecode(url_);
					std::string::size_type qmak_pos = url.find("?");
					if (qmak_pos == std::string::npos)
					{
						path_ = url;
					}
					else
					{
						path_ = url.substr(0, qmak_pos);
						std::string quert_str = url.substr(qmak_pos + 1, url.size());
						query_ = query_parser(quert_str);
					}
					return result;
				}
			}
			return indeterminate;
		}
Exemplo n.º 29
0
void EtherShield::ES_urldecode(char *urlbuf) {
	urldecode(urlbuf);
}
Exemplo n.º 30
0
int main(int argc, char* argv[])
{
    // a global variable defined in errno.h that's "set by system 
    // calls and some library functions [to a nonzero value]
    // in the event of an error to indicate what went wrong"
    errno = 0;

    // default to port 8080
    int port = 8080;

    // usage
    const char* usage = "Usage: server [-p port] /path/to/root";

    // parse command-line arguments
    int opt;
    while ((opt = getopt(argc, argv, "hp:")) != -1)
    {
        switch (opt)
        {
            // -h
            case 'h':
                printf("%s\n", usage);
                return 0;

            // -p port
            case 'p':
                port = atoi(optarg);
                break;
        }
    }

    // ensure port is a non-negative short and path to server's root is specified
    if (port < 0 || port > SHRT_MAX || argv[optind] == NULL || strlen(argv[optind]) == 0)
    {
        // announce usage
        printf("%s\n", usage);

        // return 2 just like bash's builtins
        return 2;
    }

    // start server
    start(port, argv[optind]);

    // listen for SIGINT (aka control-c)
    struct sigaction act;
    act.sa_handler = handler;
    act.sa_flags = 0;
    sigemptyset(&act.sa_mask);
    sigaction(SIGINT, &act, NULL);

    // a message and its length
    char* message = NULL;
    size_t length = 0;

    // path requested
    char* path = NULL;

    // accept connections one at a time
    while (true)
    {
        // free last path, if any
        if (path != NULL)
        {
            free(path);
            path = NULL;
        }

        // free last message, if any
        if (message != NULL)
        {
            free(message);
            message = NULL;
        }
        length = 0;

        // close last client's socket, if any
        if (cfd != -1)
        {
            close(cfd);
            cfd = -1;
        }

        // check for control-c
        if (signaled)
        {
            stop();
        }

        // check whether client has connected
        if (connected())
        {
            // check for request
            if (request(&message, &length))
            {
                // extract message's request-line
                // http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html
                const char* haystack = message;
                const char* needle = strstr(haystack, "\r\n");
                if (needle == NULL)
                {
                    error(500);
                    continue;
                }
                char line[needle - haystack + 2 + 1];
                strncpy(line, haystack, needle - haystack + 2);
                line[needle - haystack + 2] = '\0';

                // log request-line
                printf("%s", line);

                // parse request-line
                char abs_path[LimitRequestLine + 1];
                char query[LimitRequestLine + 1];
                if (parse(line, abs_path, query))
                {
                    // URL-decode absolute-path
                    char* p = urldecode(abs_path);
                    if (p == NULL)
                    {
                        error(500);
                        continue;
                    }

                    // resolve absolute-path to local path
                    path = malloc(strlen(root) + strlen(p) + 1);
                    if (path == NULL)
                    {
                        error(500);
                        continue;
                    }
                    strcpy(path, root);
                    strcat(path, p);
                    free(p);

                    // ensure path exists
                    if (access(path, F_OK) == -1)
                    {
                        error(404);
                        continue;
                    }

                    // if path to directory
                    struct stat sb;
                    if (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode))
                    {
                        // redirect from absolute-path to absolute-path/
                        if (abs_path[strlen(abs_path) - 1] != '/')
                        {
                            char uri[strlen(abs_path) + 1 + 1];
                            strcpy(uri, abs_path);
                            strcat(uri, "/");
                            redirect(uri);
                            continue;
                        }

                        // use path/index.php or path/index.html, if present, instead of directory's path
                        char* index = indexes(path);
                        if (index != NULL)
                        {
                            free(path);
                            path = index;
                        }

                        // list contents of directory
                        else
                        {
                            list(path);
                            continue;
                        }
                    }

                    // look up MIME type for file at path
                    const char* type = lookup(path);
                    if (type == NULL)
                    {
                        error(501);
                        continue;
                    }

                    // interpret PHP script at path
                    if (strcasecmp("text/x-php", type) == 0)
                    {
                        interpret(path, query);
                    }

                    // transfer file at path
                    else
                    {
                        transfer(path, type);
                    }
                }
            }
        }
    }
}