コード例 #1
0
ファイル: test_uri.c プロジェクト: 4leavedclover/userland
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;
}
コード例 #2
0
ファイル: test_uri.c プロジェクト: 4leavedclover/userland
/** 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);
}
コード例 #3
0
ファイル: test_uri.c プロジェクト: 4leavedclover/userland
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;
}
コード例 #4
0
ファイル: io_http.c プロジェクト: DSkywalk/RetroArch
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;
}
コード例 #5
0
ファイル: rtp_reader.c プロジェクト: 4leavedclover/userland
/**************************************************************************//**
 * Open the container.
 * Uses the I/O URI and/or data to configure the container.
 *
 * @param p_ctx   The reader context.
 * @return  The resulting status of the function.
 */
VC_CONTAINER_STATUS_T rtp_reader_open( VC_CONTAINER_T *p_ctx )
{
   VC_CONTAINER_MODULE_T *module = 0;
   VC_CONTAINER_TRACK_T *track = 0;
   VC_CONTAINER_TRACK_MODULE_T *t_module = 0;
   VC_CONTAINER_STATUS_T status = VC_CONTAINER_SUCCESS;
   VC_CONTAINERS_LIST_T *parameters = NULL;
   uint32_t payload_type;
   uint32_t initial_seq_num;

   /* Check the URI scheme looks valid */
   if (!vc_uri_scheme(p_ctx->priv->uri) ||
       (strcasecmp(vc_uri_scheme(p_ctx->priv->uri), RTP_SCHEME) &&
        strcasecmp(vc_uri_scheme(p_ctx->priv->uri), RTP_PKT_SCHEME)))
      return VC_CONTAINER_ERROR_FORMAT_NOT_SUPPORTED;

   /* Make the query/parameter list more easily searchable */
   parameters = fill_parameter_list(p_ctx->priv->uri);
   if (!parameters) { status = VC_CONTAINER_ERROR_OUT_OF_MEMORY; goto error; }

   /* Payload type parameter is mandatory and must fit in 7 bits */
   if (!rtp_get_parameter_u32(parameters, PAYLOAD_TYPE_NAME, &payload_type) || payload_type > 127)
   {
      status = VC_CONTAINER_ERROR_FORMAT_INVALID;
      goto error;
   }

   /* Allocate our context */
   module = (VC_CONTAINER_MODULE_T *)malloc(sizeof(VC_CONTAINER_MODULE_T));
   if (!module) { status = VC_CONTAINER_ERROR_OUT_OF_MEMORY; goto error; }

   memset(module, 0, sizeof(*module));
   p_ctx->priv->module = module;
   p_ctx->tracks = &module->track;

   /* Allocate the track, including space for reading an RTP packet on the end */
   track = vc_container_allocate_track(p_ctx, sizeof(VC_CONTAINER_TRACK_MODULE_T) + MAXIMUM_PACKET_SIZE);
   if (!track)
   {
      status = VC_CONTAINER_ERROR_OUT_OF_MEMORY;
      goto error;
   }
   module->track = track;
   p_ctx->tracks_num = 1;
   t_module = track->priv->module;

   /* Initialise the track data */
   t_module->buffer = (uint8_t *)(t_module + 1);
   status = decode_payload_type(p_ctx, track, parameters, payload_type);
   if (status != VC_CONTAINER_SUCCESS)
      goto error;

   vc_container_assert(t_module->timestamp_clock != 0);

   /* Default to a generic, unstructured payload handler */
   if (!t_module->payload_handler)
      t_module->payload_handler = generic_payload_handler;

   if (rtp_get_parameter_x32(parameters, SSRC_NAME, &t_module->expected_ssrc))
      SET_BIT(t_module->flags, TRACK_SSRC_SET);

   t_module->probation = MIN_SEQUENTIAL;
   if (rtp_get_parameter_u32(parameters, SEQ_NAME, &initial_seq_num))
   {
      /* If an initial sequence number is provided, avoid probation period */
      t_module->max_seq_num = (uint16_t)initial_seq_num;
      t_module->probation = 0;
   }

   track->is_enabled = true;

   vc_containers_list_destroy(parameters);

   p_ctx->priv->pf_close = rtp_reader_close;
   p_ctx->priv->pf_read = rtp_reader_read;
   p_ctx->priv->pf_seek = rtp_reader_seek;
   p_ctx->priv->pf_control = rtp_reader_control;

   return VC_CONTAINER_SUCCESS;

error:
   if (parameters) vc_containers_list_destroy(parameters);
   if(status == VC_CONTAINER_SUCCESS || status == VC_CONTAINER_ERROR_EOS)
      status = VC_CONTAINER_ERROR_FORMAT_INVALID;
   LOG_DEBUG(p_ctx, "error opening RTP (%i)", status);
   rtp_reader_close(p_ctx);
   return status;
}
コード例 #6
0
ファイル: test_uri.c プロジェクト: 4leavedclover/userland
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;
}