Exemplo n.º 1
0
/**
 * Initializes an URL object
 */
void ICACHE_FLASH_ATTR url_initialize( url_object_type* url, url_protocol_type protocol, uint8_t* hostname, uint16_t port, uint8_t* path, uint8_t* query )
{
    url->protocol = protocol;
    url->port = port;
    url->query = NULL;

    url->host_ip = url_hostname_is_ip( hostname );
    if( url->host_ip == 0x00000000 ) {
        if( hostname == NULL ) url->hostname = NULL;
        else {
            url->hostname = ( uint8_t* ) os_malloc( strlen( ( char* ) hostname ) + 1 );
            strcpy( ( char* ) url->hostname, ( char* ) hostname );
        }
    }

    if( path == NULL ) url->path = NULL;
    else {
        url->path = ( uint8_t* ) os_malloc( strlen( ( char* ) path ) + 1 );
        strcpy( ( char* ) url->path, ( char* ) path );
    }
    if( strlen( query ) > 0 )
        url_parse_query( url, query, strlen( query ) );
    else
        url->query = NULL;
}
Exemplo n.º 2
0
static ConnInterface::Ptr url_parse_serial(
        std::string path, int baud, std::string query)
{
	std::string file_path;
	int baudrate;

	// /dev/ttyACM0:57600
    url_parse_host(path, file_path, baudrate, "/dev/ttyACM0", baud);
    url_parse_query(query);

    return boost::make_shared<ConnSerial>(file_path, baudrate);
}
Exemplo n.º 3
0
static struct nm_ctxdata *new_ctxdata(char *uri)
{
	struct nm_ctxdata *data;

	if (!uri)
		return NULL;

	data = safe_calloc(1, sizeof(struct nm_ctxdata));
	dprint(1, (debugfile, "nm: initialize context data %p\n", data));

	if (url_parse_query(uri, &data->db_filename, &data->query_items)) {
		mutt_error(_("failed to parse notmuch uri: %s"), uri);
		data->db_filename = NULL;
		data->query_items = NULL;
		data->query_type = 0;
		return NULL;
	}

	return data;
}
Exemplo n.º 4
0
/**
 * Parse URL path and query into object
 */
void ICACHE_FLASH_ATTR url_parse_path( url_object_type* url, uint8_t* url_path )
{
    uint8_t* fragment, *delimiter, *query;

    url_path = skip_whitespace( url_path );

    if( ( fragment = ( uint8_t* ) strchr( ( char* ) url_path, '#' ) ) != NULL ) ( *fragment ) = '\0';
    if( ( delimiter = ( uint8_t* ) strchr( ( char* ) url_path, '?' ) ) != NULL ) {
        ( *delimiter ) = '\0';
        query = delimiter + 1;
        url_parse_query( url, query, strlen( query ) );
    }

    if( url->path != NULL ) os_free( url_path );
    url->path = ( uint8_t* ) os_malloc( strlen( ( char* ) url_path ) + 1 );
    strcpy( ( char* ) url->path, ( char* ) url_path );

    if( fragment != NULL ) ( *fragment ) = '#';
    if( delimiter != NULL ) ( *delimiter ) = '?';
}
Exemplo n.º 5
0
/**
 * HTTP request parsing
 */
uint8_t* ICACHE_FLASH_ATTR http_request_parse( http_request_object_type* request, uint8_t* data )
{
    http_header_scheme_type scheme;
    char empty[ 1 ] = "\0", host[ 5 ] = "Host", content_length[ 15 ] = "Content-Length", header_sec_ws_key[ 18 ] = "Sec-WebSocket-Key";
    uint8_t* mark, *store, *end;
    uint16_t length;

    if( request->location == NULL ) {
        request->location = ( url_object_type* ) os_malloc( sizeof( url_object_type ) );
        url_initialize( request->location, URL_PROTOCOL_NONE, ( uint8_t* ) empty, 0, ( uint8_t* ) empty, ( uint8_t* ) empty );
    }

    data = http_request_parse_method_line( request, data );
    scheme = http_request_path_get_scheme( request->location->path );

    request->content_length = 0;
    request->headers = NULL;
    request->location->hostname = NULL;
    request->location->host_ip = 0x00000000;
    request->scheme = scheme;
    
    while( ( *data != '\0' ) && (( *data ) != '\r' && ( *( data + 1 ) != '\n' )) ) {
        mark = http_header_field_parse_name( data, ( uint8_t* ) empty, 1 );
        if( ( *mark ) == ':' ) {
            ( *mark ) = '\0';
            if( http_header_field_check_scheme( data, scheme ) ) {
                length = http_header_field_value_length( mark + 1 );
                store = ( uint8_t* ) os_malloc( length + 1 );
                end = http_header_field_parse_value( mark + 1, store, 0 );

                if( strcmp( content_length, ( char* ) data ) == 0 ) {
                    parse_uint32( &( request->content_length ), store );
                } else if( strcmp( host, ( char* ) data ) == 0 ) {
                    request->location->hostname = store;
                } else {
                    request->headers = http_header_field_add( request->headers, data, store );
                    os_free( store );
                }
                data = end;
            } else {
                data = http_header_field_parse_value( mark + 1, ( uint8_t* ) empty, 1 );
            }
            ( *mark ) = ':';
        } else break;
    }

    if(( *data ) == '\r' && ( *( data + 1 ) == '\n' )) {
        data += 2;
        if( request->content_length > 0 )
            url_parse_query( request->location, data, ( int16_t ) request->content_length );
        request->content = (( *data ) == '\0' ) ? NULL : data;
    } else request->content = data;

	if( scheme == ( HTTP_REQUEST_SCHEME | WS_REQUEST_SCHEME ) ) {
		if( http_header_field_get( request->headers, ( uint8_t* ) header_sec_ws_key ) != NULL ) request->location->protocol = URL_PROTOCOL_WS;
		else request->location->protocol = URL_PROTOCOL_HTTP;
	} else if( scheme == WS_REQUEST_SCHEME ) request->location->protocol = URL_PROTOCOL_WS;
    else request->location->protocol = URL_PROTOCOL_HTTP;

    return data;
}