static int check_null_uri_pointer(void) { int error_count = 0; char buffer[1]; /* Check NULL URI can be passed without failure to all routines */ vc_uri_release( NULL ); vc_uri_clear( NULL ); if (vc_uri_parse( NULL, NULL )) error_count++; if (vc_uri_parse( NULL, "" )) error_count++; if (vc_uri_build( NULL, NULL, 0 ) != 0) error_count++; buffer[0] = TEST_CHAR; if (vc_uri_build( NULL, buffer, sizeof(buffer) ) != 0) error_count++; if (buffer[0] != TEST_CHAR) error_count++; if (vc_uri_scheme( NULL )) error_count++; if (vc_uri_userinfo( NULL )) error_count++; if (vc_uri_host( NULL )) error_count++; if (vc_uri_port( NULL )) error_count++; if (vc_uri_path( NULL )) error_count++; if (vc_uri_fragment( NULL )) error_count++; if (vc_uri_num_queries( NULL ) != 0) error_count++; vc_uri_query( NULL, 0, NULL, NULL ); if (vc_uri_set_scheme( NULL, NULL )) error_count++; if (vc_uri_set_userinfo( NULL, NULL )) error_count++; if (vc_uri_set_host( NULL, NULL )) error_count++; if (vc_uri_set_port( NULL, NULL )) error_count++; if (vc_uri_set_path( NULL, NULL )) error_count++; if (vc_uri_set_fragment( NULL, NULL )) error_count++; if (vc_uri_add_query( NULL, NULL, NULL )) error_count++; if (error_count) LOG_ERROR(NULL, "NULL URI parameter testing failed"); return error_count; }
/** Dump a URI structure to the log. * * \param uri URI structure to be dumped. */ static void dump_uri(VC_URI_PARTS_T *uri) { const char *str; uint32_t query_count, ii; str = vc_uri_scheme(uri); if (str) LOG_DEBUG(NULL, "Scheme: <%s>", str); str = vc_uri_userinfo(uri); if (str) LOG_DEBUG(NULL, "Userinfo: <%s>", str); str = vc_uri_host(uri); if (str) LOG_DEBUG(NULL, "Host: <%s>", str); str = vc_uri_port(uri); if (str) LOG_DEBUG(NULL, "Port: <%s>", str); str = vc_uri_path(uri); if (str) LOG_DEBUG(NULL, "Path: <%s>", str); query_count = vc_uri_num_queries(uri); for (ii = 0; ii < query_count; ii++) { const char *value; vc_uri_query(uri, ii, &str, &value); if (str) { if (value) LOG_DEBUG(NULL, "Query %d: <%s>=<%s>", ii, str, value); else LOG_DEBUG(NULL, "Query %d: <%s>", ii, str); } } str = vc_uri_fragment(uri); if (str) LOG_DEBUG(NULL, "Fragment: <%s>", str); }
static VC_CONTAINER_STATUS_T io_http_open_socket(VC_CONTAINER_IO_T *ctx) { VC_CONTAINER_IO_MODULE_T *module = ctx->module; VC_CONTAINER_STATUS_T status; const char *host, *port; /* Treat empty host or port strings as not defined */ port = vc_uri_port(ctx->uri_parts); if (port && !*port) port = NULL; /* Require the port to be defined */ if (!port) { status = VC_CONTAINER_ERROR_URI_OPEN_FAILED; goto error; } host = vc_uri_host(ctx->uri_parts); if (host && !*host) host = NULL; if (!host) { status = VC_CONTAINER_ERROR_URI_OPEN_FAILED; goto error; } module->sock = vc_container_net_open(host, port, VC_CONTAINER_NET_OPEN_FLAG_STREAM, NULL); if (!module->sock) { status = VC_CONTAINER_ERROR_URI_NOT_FOUND; goto error; } return VC_CONTAINER_SUCCESS; error: return status; }
static int check_get_defaults(VC_URI_PARTS_T *uri) { int error_count = 0; const char *name = NULL, *value = NULL; char buffer[1]; if (vc_uri_scheme( uri )) error_count++; if (vc_uri_userinfo( uri )) error_count++; if (vc_uri_host( uri )) error_count++; if (vc_uri_port( uri )) error_count++; if (vc_uri_path( uri )) error_count++; if (vc_uri_fragment( uri )) error_count++; if (vc_uri_num_queries( uri ) != 0) error_count++; vc_uri_query( uri, 0, &name, &value ); if (name != NULL || value != NULL) error_count++; if (vc_uri_build(uri, NULL, 0) != 0) error_count++; buffer[0] = ~*TEST_STRING; /* Initialize with something */ vc_uri_build(uri, buffer, sizeof(buffer)); if (buffer[0] != '\0') /* Expect empty string */ error_count++; if (error_count) LOG_ERROR(NULL, "Getting default values gave unexpected values"); return error_count; }
VC_CONTAINER_STATUS_T vc_container_io_http_open(VC_CONTAINER_IO_T *p_ctx, const char *unused, VC_CONTAINER_IO_MODE_T mode) { VC_CONTAINER_STATUS_T status = VC_CONTAINER_SUCCESS; VC_CONTAINER_IO_MODULE_T *module = 0; VC_CONTAINER_PARAM_UNUSED(unused); /* Check the URI to see if we're dealing with an http stream */ if (!vc_uri_scheme(p_ctx->uri_parts) || strcasecmp(vc_uri_scheme(p_ctx->uri_parts), "http")) return VC_CONTAINER_ERROR_FORMAT_NOT_SUPPORTED; /* * Some basic error checking. */ if (mode == VC_CONTAINER_IO_MODE_WRITE) { status = VC_CONTAINER_ERROR_UNSUPPORTED_OPERATION; goto error; } if (strlen(p_ctx->uri) > HTTP_URI_LENGTH_MAX) { status = VC_CONTAINER_ERROR_URI_OPEN_FAILED; goto error; } module = calloc(1, sizeof(*module)); if (!module) { status = VC_CONTAINER_ERROR_OUT_OF_MEMORY; goto error; } p_ctx->module = module; /* header_list will contain pointers into the response_buffer, so take care in re-use */ module->header_list = vc_containers_list_create(HEADER_LIST_INITIAL_CAPACITY, sizeof(HTTP_HEADER_T), (VC_CONTAINERS_LIST_COMPARATOR_T)io_http_header_comparator); if (!module->header_list) { status = VC_CONTAINER_ERROR_OUT_OF_MEMORY; goto error; } /* * Make sure that we have a port number. */ if (vc_uri_port(p_ctx->uri_parts) == NULL) vc_uri_set_port(p_ctx->uri_parts, IO_HTTP_DEFAULT_PORT); status = io_http_open_socket(p_ctx); if (status != VC_CONTAINER_SUCCESS) goto error; /* * Whoo hoo! Our socket is open. Now let's send a HEAD request. */ status = io_http_head(p_ctx); if (status != VC_CONTAINER_SUCCESS) goto error; p_ctx->pf_close = io_http_close; p_ctx->pf_read = io_http_read; p_ctx->pf_write = NULL; p_ctx->pf_control = io_http_control; p_ctx->pf_seek = io_http_seek; p_ctx->capabilities = VC_CONTAINER_IO_CAPS_NO_CACHING; p_ctx->capabilities |= VC_CONTAINER_IO_CAPS_SEEK_SLOW; return VC_CONTAINER_SUCCESS; error: io_http_close(p_ctx); return status; }
static int check_accessors(VC_URI_PARTS_T *uri) { int error_count = 0; const char *str; if (vc_uri_set_scheme( uri, TEST_STRING )) { str = vc_uri_scheme(uri); if (!str || strcmp(TEST_STRING, str)) error_count++; if (!vc_uri_set_scheme( uri, NULL )) error_count++; if (vc_uri_scheme(uri)) error_count++; } else error_count++; if (vc_uri_set_userinfo( uri, TEST_STRING )) { str = vc_uri_userinfo(uri); if (!str || strcmp(TEST_STRING, str)) error_count++; if (!vc_uri_set_userinfo( uri, NULL )) error_count++; if (vc_uri_userinfo(uri)) error_count++; } else error_count++; if (vc_uri_set_host( uri, TEST_STRING )) { str = vc_uri_host(uri); if (!str || strcmp(TEST_STRING, str)) error_count++; if (!vc_uri_set_host( uri, NULL )) error_count++; if (vc_uri_host(uri)) error_count++; } else error_count++; if (vc_uri_set_port( uri, TEST_STRING )) { str = vc_uri_port(uri); if (!str || strcmp(TEST_STRING, str)) error_count++; if (!vc_uri_set_port( uri, NULL )) error_count++; if (vc_uri_port(uri)) error_count++; } else error_count++; if (vc_uri_set_path( uri, TEST_STRING )) { str = vc_uri_path(uri); if (!str || strcmp(TEST_STRING, str)) error_count++; if (!vc_uri_set_path( uri, NULL )) error_count++; if (vc_uri_path(uri)) error_count++; } else error_count++; if (vc_uri_set_fragment( uri, TEST_STRING )) { str = vc_uri_fragment(uri); if (!str || strcmp(TEST_STRING, str)) error_count++; if (!vc_uri_set_fragment( uri, NULL )) error_count++; if (vc_uri_fragment(uri)) error_count++; } else error_count++; if (vc_uri_add_query( uri, NULL, NULL )) error_count++; if (vc_uri_add_query( uri, NULL, TEST_VALUE )) error_count++; if (!vc_uri_add_query( uri, TEST_STRING, NULL )) error_count++; if (!vc_uri_add_query( uri, TEST_NAME, TEST_VALUE )) error_count++; if (vc_uri_num_queries(uri) == 2) { const char *name = NULL, *value = NULL; vc_uri_query(uri, 0, &name, &value); if (!name || strcmp(TEST_STRING, name)) error_count++; if (value) error_count++; vc_uri_query(uri, 1, &name, &value); if (!name || strcmp(TEST_NAME, name)) error_count++; if (!value || strcmp(TEST_VALUE, value)) error_count++; } else error_count++; if (error_count) LOG_ERROR(NULL, "Accessors failed"); return error_count; }