Example #1
0
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;
}
Example #2
0
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;
}
Example #3
0
/** Test building a URI from component parts.
 *
 * \param uri Pre-created URI structure.
 * \param uri_data The data for building the URI and the expected output.
 * \return 1 on error, 0 on success. */
static int test_building_uri(VC_URI_PARTS_T *uri, BUILD_URI_T *uri_data)
{
   const char **p_str;
   const char *name, *value;

   LOG_INFO(NULL, "Building URI <%s>", uri_data->expected_uri);

   vc_uri_clear(uri);

   if (!vc_uri_set_scheme(uri, uri_data->scheme))
   {
      LOG_ERROR(NULL, "*** Failed to set scheme");
      return 1;
   }

   if (!vc_uri_set_userinfo(uri, uri_data->userinfo))
   {
      LOG_ERROR(NULL, "*** Failed to set userinfo");
      return 1;
   }

   if (!vc_uri_set_host(uri, uri_data->host))
   {
      LOG_ERROR(NULL, "*** Failed to set host");
      return 1;
   }

   if (!vc_uri_set_port(uri, uri_data->port))
   {
      LOG_ERROR(NULL, "*** Failed to set port");
      return 1;
   }

   if (!vc_uri_set_path(uri, uri_data->path))
   {
      LOG_ERROR(NULL, "*** Failed to set path");
      return 1;
   }

   if (!vc_uri_set_fragment(uri, uri_data->fragment))
   {
      LOG_ERROR(NULL, "*** Failed to set fragment");
      return 1;
   }

   p_str = uri_data->queries;
   name = *p_str++;

   while (name)
   {
      value = *p_str++;
      if (!vc_uri_add_query(uri, name, value))
      {
         LOG_ERROR(NULL, "*** Failed to add query");
         return 1;
      }
      name = *p_str++;
   }

   dump_uri(uri);

   return check_uri(uri, uri_data->expected_uri);
}
Example #4
0
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;
}