예제 #1
0
int on_body(http_parser* _, const char* at, size_t length) {
	(void)_;
	con_len = (int)length;
	//printf("body : %s\n", at);
	//memcpy(http.content, at, (int)length);
	//http.content[(int)length] = '\0';

	//analysis
	if(c_info.user_id[0] == '\0')
	{
		qs_scanvalue("__user", at, c_info.user_id, sizeof(c_info.user_id));
		printf("user_id = %s\n", c_info.user_id);
	}
	switch(c_info.p_type)
	{
		case COMMENT:
			qs_scanvalue("comment_text", at, c_info.comment, sizeof(c_info.comment));
			break;
		case ADD_FRIEND:
			qs_scanvalue("to_friend", at, c_info.s_id, sizeof(c_info.s_id));
			break;
		case NOTE:
			qs_scanvalue("title", at, c_info.comment, sizeof(c_info.comment));
			break;
		case STATUS:
			qs_scanvalue("xhpc_message_text", at, c_info.comment, sizeof(c_info.comment));
			break;
	}
	
//	if(!strncmp(contype, "text/html", CONTYPE_LENGTH))
//	{
//		printf("hello, world\n");
//		//fwrite(at, 1, length, dest);
//		if(length)
//		{
//			if(isGzip)
//			{
//				char * uncomp = (char*)calloc(length*8, sizeof(char));
//				decompress(at, uncomp, length);
//
//			#ifdef HTTP_PRINT
//				printf( "Body: %.*s\n", 8*length, uncomp);
//			#endif
//
//			}else{
//				
//			#ifdef HTTP_PRINT
//				printf( "Body: %.*s\n", (int)length, at);
//			#endif
//				;
//			}
//		}
//	}
	return 0;
}
예제 #2
0
int main(int argc, char * argv[])
{
    int i;
    char * kvpairs[NUMKVPAIRS];
    char value[VALSIZE];
    char * value_ptr;
    unsigned char r, g, b, a;
    double dr, dg, db, da;

    char getstring[] = "scheme://*****:*****@domain:port/path?foo=bar&frob&baz=quux&color=09FA#anchor";

    printf("Our GET string is %s\n\n", getstring);

    /********************************************************/
    /*  The easy, but not as efficient way: qs_scanvalue()  */
    /********************************************************/
    if ( qs_scanvalue("foo", getstring, value, sizeof(value)) != NULL )
        printf("Key %s is set, and the value is: \"%s\"\n", "foo", value);
    else
        printf("Key %s is NOT set\n", "foo");

    if ( qs_scanvalue("baz", getstring, value, sizeof(value)) != NULL )
        printf("Key %s is set, and the value is: \"%s\"\n", "baz", value);
    else
        printf("Key %s is NOT set\n", "baz");

    if ( qs_scanvalue("frob", getstring, value, sizeof(value)) != NULL )
        printf("Key %s is set, and the value is: \"%s\"\n", "frob", value);
    else
        printf("Key %s is NOT set\n", "frob");

    if ( qs_scanvalue("blah", getstring, value, sizeof(value)) != NULL )
        printf("Key %s is set, and the value is: \"%s\"\n", "blah", value);
    else
        printf("Key %s is NOT set\n", "blah");

    if ( qs_scanvalue("color", getstring, value, sizeof(value)) != NULL )
    {
        printf("Key %s is set, and the value is: \"%s\"\n", "color", value);
        if ( hex2ccolor(value, &r, &g, &b, &a) != 0 && hex2dcolor(value, &dr, &dg, &db, &da) != 0 )
        {
            printf("    \"%s\" successfully decoded as uchar  : r=%d, g=%d, b=%d, a=%d\n", "color", r, g, b, a);
            printf("    \"%s\" successfully decoded as double : r=%.2f, g=%.2f, b=%.2f, a=%.2f\n", "color", dr, dg, db, da);
        }
        else
            printf("    \"%s\" NOT successfully decoded\n", "color");
    }
    else
        printf("Key %s is NOT set\n", "color");

    printf("\n");


    /*************************************************************************/
    /*  The faster, more complex, and destructive way: qs_parse() / qs_k2v() */
    /*************************************************************************/

    /*  ***THIS WILL ALTER getstring***  */
    i = qs_parse(getstring, kvpairs, 256);
    /*  At this point qs_scanvalue() will no longer work with this query string  */

    if ( (value_ptr = qs_k2v("foo", kvpairs, i)) != NULL )
        printf("Key %s is set, and the value is: \"%s\"\n", "foo", value_ptr);
    else
        printf("Key %s is NOT set\n", "foo");

    if ( (value_ptr = qs_k2v("baz", kvpairs, i)) != NULL )
        printf("Key %s is set, and the value is: \"%s\"\n", "baz", value_ptr);
    else
        printf("Key %s is NOT set\n", "baz");

    if ( (value_ptr = qs_k2v("frob", kvpairs, i)) != NULL )
        printf("Key %s is set, and the value is: \"%s\"\n", "frob", value_ptr);
    else
        printf("Key %s is NOT set\n", "frob");

    if ( (value_ptr = qs_k2v("blah", kvpairs, i)) != NULL )
        printf("Key %s is set, and the value is: \"%s\"\n", "blah", value_ptr);
    else
        printf("Key %s is NOT set\n", "blah");

    if ( (value_ptr = qs_k2v("color", kvpairs, i)) != NULL )
    {
        printf("Key %s is set, and the value is: \"%s\"\n", "color", value_ptr);
        if ( hex2ccolor(value_ptr, &r, &g, &b, &a) != 0 && hex2dcolor(value_ptr, &dr, &dg, &db, &da) != 0 )
        {
            printf("    \"%s\" successfully decoded as uchar  : r=%d, g=%d, b=%d, a=%d\n", "color", r, g, b, a);
            printf("    \"%s\" successfully decoded as double : r=%.2f, g=%.2f, b=%.2f, a=%.2f\n", "color", dr, dg, db, da);
        }
        else
            printf("    \"%s\" NOT successfully decoded\n", "color");
    }
    else
        printf("Key %s is NOT set\n", "color");

    return 0;
}
예제 #3
0
void _url_parse(char * url)
{
	printf("............url = %s.........\n", url);
	char *pos;
	int len=0;
	char *path;
	
	//parse url
	parseURL(url, &storage);
	storage.path.start += 1;  //remove '/'
	if(storage.path.start == storage.path.end)
		return;
	
	//store user_id
	if(storage.query.end != storage.query.start)
	{
		char * query = readURLField(url, storage.query);
		printf("malloc 1\n");
		qs_scanvalue("__user", query, c_info.user_id, sizeof(c_info.user_id));
		qs_scanvalue("q", query, c_info.comment, sizeof(c_info.comment));
		FREE(query);
		printf("FREE 1\n");
	}
	//modify me, stupid implemention of s_id
	path = readURLField(url, storage.path);
		printf("malloc 2\n");
	printf("url path = %s\n", path);
	//avoid referer url check
	if(c_info.p_type == 0)
	{
		c_info.p_type = _page_type_(path);
		printf("p_type = %d\n", c_info.p_type);
	}

	if((pos = strchr(path, '/')) == strrchr(path, '/'))
	{
		if(!pos)
		{
			strcpy(c_info.s_id, path);
			FREE(path);
		printf("FREE 2\n");
		}
		else
		{
			memcpy(c_info.s_id,path, pos-path);
			printf("pos-path = %d\n", pos-path);
			c_info.s_id[pos-path] = '\0';
			FREE(path);
			printf("FREE 4\n");
		}
		printf("c_info.s_id = %s\n", c_info.s_id);
	}else
		FREE(path);
//	regex_match("(\\w+\\.)+\\w+", path, &pos, &len);   //regex [\w+\.]+, not endwith php
//	if(len != 0 && !strstr(path, "php"))  //need modify
//	{
//		printf("pos = %s, len=%d\n", pos, len);
//	    strcpy(c_info.s_id, path);
//		printf("subject name:%s\n", c_info.s_id);
//	}

	if(c_info.p_type == MEDIA_SET)
	{
		path = readURLField(url, storage.query);
		printf("malloc 4\n");
		qs_scanvalue("set", path, c_info.r_id, sizeof(c_info.r_id));
		FREE(path);
		printf("FREE 6\n");
	}
}