int
main (int argc, char **argv)
{
  FILE *content_types_file;


  osip_content_type_t *content_type;
  char *a_content_type;
  char *dest;
  char *res;

  content_types_file = fopen (argv[1], "r");
  if (content_types_file == NULL)
    {
      fprintf (stdout,
	       "Failed to open %s file.\nUsage: tcontent_type content_types.txt\n",
	       argv[1]);
      exit (0);
    }

  a_content_type = (char *) osip_malloc (200);
  res = fgets (a_content_type, 200, content_types_file);	/* lines are under 200 */
  while (res != NULL)
    {

      int errcode;

      /* remove the last '\n' before parsing */
      strncpy (a_content_type + strlen (a_content_type) - 1, "\0", 1);

      if (0 != strncmp (a_content_type, "#", 1))
	{
	  /* allocate & init content_type */
	  osip_content_type_init (&content_type);
	  printf ("=================================================\n");
	  printf ("CONTENT_TYPE TO PARSE: |%s|\n", a_content_type);
	  errcode = osip_content_type_parse (content_type, a_content_type);
	  if (errcode != -1)
	    {
	      if (osip_content_type_to_str (content_type, &dest) != -1)
		{
		  printf ("result:                |%s|\n", dest);
		  osip_free (dest);
		}
	    }
	  else
	    printf ("Bad content_type format: %s\n", a_content_type);
	  osip_content_type_free (content_type);
	  printf ("=================================================\n");
	}
      res = fgets (a_content_type, 200, content_types_file);	/* lines are under 200 */
    }
  osip_free (a_content_type);
  return 0;
}
int
osip_body_set_contenttype (osip_body_t * body, const char *hvalue)
{
  int i;

  if (body == NULL)
    return -1;
  if (hvalue == NULL)
    return -1;

  i = osip_content_type_init (&(body->content_type));
  if (i != 0)
    return -1;
  i = osip_content_type_parse (body->content_type, hvalue);
  if (i != 0)
    {
      osip_content_type_free (body->content_type);
      body->content_type = NULL;
      return -1;
    }
  return 0;
}
Exemple #3
0
/* returns -1 on error. */
int osip_message_set_content_type(osip_message_t * sip, const char *hvalue)
{
	int i;

	if (sip->content_type != NULL)
		return OSIP_BADPARAMETER;

	if (hvalue == NULL || hvalue[0] == '\0')
		return OSIP_SUCCESS;

	i = osip_content_type_init(&(sip->content_type));
	if (i != 0)
		return i;
	sip->message_property = 2;
	i = osip_content_type_parse(sip->content_type, hvalue);
	if (i != 0) {
		osip_content_type_free(sip->content_type);
		sip->content_type = NULL;
		return i;
	}
	return OSIP_SUCCESS;
}
/* returns -1 on error. */
int
osip_message_set_content_type (osip_message_t * sip, const char *hvalue)
{
  int i;

  if (sip->content_type != NULL)
    return -1;

  if (hvalue == NULL || hvalue[0] == '\0')
    return 0;

  i = osip_content_type_init (&(sip->content_type));
  if (i != 0)
    return -1;
  sip->message_property = 2;
  i = osip_content_type_parse (sip->content_type, hvalue);
  if (i != 0)
    {
      osip_content_type_free (sip->content_type);
      sip->content_type = NULL;
    }
  return 0;
}