Beispiel #1
0
/* returns -1 on error. */
int
osip_cseq_parse (osip_cseq_t * cseq, const char *hvalue)
{
  char *method = NULL;
  const char *end = NULL;

  cseq->number = NULL;
  cseq->method = NULL;

  method = strchr (hvalue, ' ');	/* SEARCH FOR SPACE */
  end = hvalue + strlen (hvalue);

  if (method == NULL)
    return -1;

  if (method - hvalue + 1 < 2)
    return -1;
  cseq->number = (char *) osip_malloc (method - hvalue + 1);
  if (cseq->number == NULL)
    return -1;
  osip_strncpy (cseq->number, hvalue, method - hvalue);
  osip_clrspace (cseq->number);

  if (end - method + 1 < 2)
    return -1;
  cseq->method = (char *) osip_malloc (end - method + 1);
  if (cseq->method == NULL)
    return -1;
  osip_strncpy (cseq->method, method + 1, end - method);
  osip_clrspace (cseq->method);

  return 0;			/* ok */
}
Beispiel #2
0
static int groups_load_members(grp_t *grp, char *members)
{
    char *dest;
    int index = 0;

    char *tmp = members;
    char *sep;
    sep = strchr(members, '|'); /* find beginning of prefix */

    while (sep!=NULL && index<MAX_MEMBERS)
    {
        dest = grp->members[index];
        if (sep-tmp<254)
            osip_strncpy(dest, tmp, sep-tmp);
        else
        {
            OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_ERROR,NULL,
                                  "groups plugin: members url must be shorter than 254\n"));
        }

        index++;
        tmp = sep+1;
        sep = strchr(tmp, '|'); /* find beginning of prefix */
    }

    dest = grp->members[index];
    if (tmp!=NULL && strlen(tmp)<254)
    {
        osip_strncpy(dest, tmp, strlen(tmp));
    }

    for (index=0; index<MAX_MEMBERS; index++)
    {
        int i;
        osip_uri_t *uri;

        dest = grp->members[index];
        if (dest[0]=='\0')
            break;
        OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_ERROR,NULL,
                              "groups plugin: members of %s: %s\n",
                              grp->group,
                              dest));

        osip_uri_init(&uri);
        i = osip_uri_parse(uri, dest);
        osip_uri_free(uri);
        if (i!=0)
        {
            OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_ERROR,NULL,
                                  "groups plugin: Malformed members URL in group %s!\n",
                                  grp->group));
            return -1;
        }
    }

    return 0;
}
/* returns -1 on error. */
int
osip_content_type_parse (osip_content_type_t * content_type,
			 const char *hvalue)
{
  char *subtype;
  char *osip_content_type_params;

  /* How to parse:

     we'll place the pointers:
     subtype              =>  beginning of subtype
     osip_content_type_params  =>  beginning of params

     examples:

     application/multipart ; boundary=
     ^          ^
   */

  subtype = strchr (hvalue, '/');
  osip_content_type_params = strchr (hvalue, ';');

  if (subtype == NULL)
    return -1;			/* do we really mind such an error */

  if (osip_content_type_params != NULL)
    {
      if (__osip_generic_param_parseall (content_type->gen_params,
					 osip_content_type_params) == -1)
	return -1;
    }
  else
    osip_content_type_params = subtype + strlen (subtype);

  if (subtype - hvalue + 1 < 2)
    return -1;
  content_type->type = (char *) osip_malloc (subtype - hvalue + 1);
  if (content_type->type == NULL)
    return -1;
  osip_strncpy (content_type->type, hvalue, subtype - hvalue);
  osip_clrspace (content_type->type);

  if (osip_content_type_params - subtype < 2)
    return -1;
  content_type->subtype =
    (char *) osip_malloc (osip_content_type_params - subtype);
  if (content_type->subtype == NULL)
    return -1;
  osip_strncpy (content_type->subtype, subtype + 1,
		osip_content_type_params - subtype - 1);
  osip_clrspace (content_type->subtype);

  return 0;
}
Beispiel #4
0
char *
osip_strdup_without_quote (const char *ch)
{
  char *copy = (char *) osip_malloc (strlen (ch) + 1);

  /* remove leading and trailing " */
  if ((*ch == '\"'))
    {
      osip_strncpy (copy, ch + 1, strlen (ch + 1));
      osip_strncpy (copy + strlen (copy) - 1, "\0", 1);
  } else
    osip_strncpy (copy, ch, strlen (ch));
  return copy;
}
Beispiel #5
0
int jcall_new(eXosip_event_t *je)
{
    jcall_t *ca;
    int k;

    if (___call_init==0)
    {
        ___call_init = -1;
        __call_init();
    }

    for (k=0; k<MAX_NUMBER_OF_CALLS; k++)
    {
        if (jcalls[k].state == NOT_USED)
            break;
    }
    if (k==MAX_NUMBER_OF_CALLS)
        return -1;

    ca = &(jcalls[k]);
    memset(&(jcalls[k]), 0, sizeof(jcall_t));

    ca->cid = je->cid;
    ca->did = je->did;

    if (ca->did<1 && ca->cid<1)
    {
        exit(0);
        return -1; /* not enough information for this event?? */
    }

    osip_strncpy(ca->textinfo,   je->textinfo, 255);
    osip_strncpy(ca->req_uri,    je->req_uri, 255);
    osip_strncpy(ca->local_uri,  je->local_uri, 255);
    osip_strncpy(ca->remote_uri, je->remote_uri, 255);
    osip_strncpy(ca->subject,    je->subject, 255);

    if (ca->remote_sdp_audio_ip[0]=='\0')
    {
        osip_strncpy(ca->remote_sdp_audio_ip, je->remote_sdp_audio_ip, 49);
        ca->remote_sdp_audio_port = je->remote_sdp_audio_port;
        ca->payload = je->payload;
        osip_strncpy(ca->payload_name, je->payload_name, 49);

        os_sound_init();
    }

    if (je->reason_phrase[0]!='\0')
    {
        osip_strncpy(ca->reason_phrase, je->reason_phrase, 49);
        ca->status_code = je->status_code;
    }

    eXosip_answer_call(ca->did, 180, NULL);

    ca->state = je->type;
    return 0;
}
Beispiel #6
0
/* __osip_set_next_token:
   dest is the place where the value will be allocated
   buf is the string where the value is searched
   end_separator is the character that MUST be found at the end of the value
   next is the final location of the separator + 1

   the element MUST be found before any "\r" "\n" "\0" and
   end_separator

   return -1 on error
   return 1 on success
*/
int __osip_set_next_token(char **dest, char *buf, int end_separator, char **next)
{
	char *sep;					/* separator */

	*next = NULL;

	sep = buf;
	while ((*sep != end_separator) && (*sep != '\0') && (*sep != '\r')
		   && (*sep != '\n'))
		sep++;
	if ((*sep == '\r') || (*sep == '\n')) {	/* we should continue normally only if this is the separator asked! */
		if (*sep != end_separator)
			return OSIP_UNDEFINED_ERROR;
	}
	if (*sep == '\0')
		return OSIP_UNDEFINED_ERROR;	/* value must not end with this separator! */
	if (sep == buf)
		return OSIP_UNDEFINED_ERROR;	/* empty value (or several space!) */

	*dest = osip_malloc(sep - (buf) + 1);
	if (*dest == NULL)
		return OSIP_NOMEM;
	osip_strncpy(*dest, buf, sep - buf);

	*next = sep + 1;			/* return the position right after the separator */
	return OSIP_SUCCESS;
}
static int
jidentity_get_and_set_next_token (char **dest, char *buf, char **next)
{
  char *end;
  char *start;

  *next = NULL;

  /* find first non space and tab element */
  start = buf;
  while (((*start == ' ') || (*start == '\t')) && (*start != '\0')
         && (*start != '\r') && (*start != '\n') )
    start++;
  end = start+1;
  while ((*end != '\0') && (*end != '\r') && (*end != '\n')
         && (*end != '\t') && (*end != '|'))
    end++;
  
  if ((*end == '\r') || (*end == '\n'))
    /* we should continue normally only if this is the separator asked! */
    return -1;
  if (end == start)
    return -1;                  /* empty value (or several space!) */

  *dest = osip_malloc (end - (start) + 1);
  osip_strncpy (*dest, start, end - start);

  *next = end + 1;   /* return the position right after the separator
 */
  return 0;
}
Beispiel #8
0
char *
osip_clrncpy (char *dst, const char *src, size_t len)
{
   osip_strncpy ( dst, src, len);
   osip_clrspace ( dst );
   return dst;
}
Beispiel #9
0
int
sdp_message_parse_v (sdp_message_t * sdp, char *buf, char **next)
{
  char *equal;
  char *crlf;

  *next = buf;

  equal = buf;
  while ((*equal != '=') && (*equal != '\0'))
    equal++;
  if (*equal == '\0')
    return ERR_ERROR;

  /* check if header is "v" */
  if (equal[-1] != 'v')
    return ERR_DISCARD;

  crlf = equal + 1;

  while ((*crlf != '\r') && (*crlf != '\n') && (*crlf != '\0'))
    crlf++;
  if (*crlf == '\0')
    return ERR_ERROR;
  if (crlf == equal + 1)
    return ERR_ERROR;		/*v=\r ?? bad header */
  sdp->v_version = osip_malloc (crlf - (equal + 1) + 1);
  osip_strncpy (sdp->v_version, equal + 1, crlf - (equal + 1));

  if (crlf[1] == '\n')
    *next = crlf + 2;
  else
    *next = crlf + 1;
  return WF;
}
Beispiel #10
0
/*  not yet done!!! :-)
 */
int
__osip_set_next_token_better (char **dest, char *buf, int end_separator,
                              int *forbidden_tab[], int size_tab, char **next)
{
  char *sep;                    /* separator */

  *next = NULL;

  sep = buf;
  while ((*sep != end_separator) && (*sep != '\0') && (*sep != '\r')
         && (*sep != '\n'))
    sep++;
  if ((*sep == '\r') && (*sep == '\n'))
    {                           /* we should continue normally only if this is the separator asked! */
      if (*sep != end_separator)
        return -1;
    }
  if (*sep == '\0')
    return -1;                  /* value must not end with this separator! */
  if (sep == buf)
    return -1;                  /* empty value (or several space!) */

  *dest = osip_malloc (sep - (buf) + 1);
  osip_strncpy (*dest, buf, sep - buf);

  *next = sep + 1;              /* return the position right after the separator */
  return 1;
}
int
eXosip_register_build_initial_register_withqvalue(const char *from, const char *proxy,
									   const char *contact, int expires,
									   const char *qvalue,
									   osip_message_t ** reg)
{
	eXosip_reg_t *jr = NULL;
	int i;

	*reg = NULL;

	if (from == NULL || proxy == NULL)
		return OSIP_BADPARAMETER;

#ifdef REJECT_DOUBLE_REGISTRATION
	/* Avoid adding the same registration info twice to prevent mem leaks */
	for (jr = eXosip.j_reg; jr != NULL; jr = jr->next) {
		if (strcmp(jr->r_aor, from) == 0 && strcmp(jr->r_registrar, proxy) == 0) {
			REMOVE_ELEMENT(eXosip.j_reg, jr);
			eXosip_reg_free(jr);
			jr = NULL;
			break;
		}
	}
#endif

	if (jr == NULL) {
		/* Add new registration info */
		i = eXosip_reg_init(&jr, from, proxy, contact);
		if (i != 0) {
			OSIP_TRACE(osip_trace
					   (__FILE__, __LINE__, OSIP_ERROR, NULL,
						"eXosip: cannot register! "));
			return i;
		}
		ADD_ELEMENT(eXosip.j_reg, jr);
	}

	/* build register */
	jr->r_reg_period = expires;
	if (jr->r_reg_period <= 0)	/* too low */
		jr->r_reg_period = 0;
	else if (jr->r_reg_period < 30)	/* too low */
		jr->r_reg_period = 30;

	if(qvalue)
		osip_strncpy(jr->r_qvalue, qvalue, sizeof(jr->r_qvalue));

	i = _eXosip_register_build_register(jr, reg);
	if (i != 0) {
		OSIP_TRACE(osip_trace
				   (__FILE__, __LINE__, OSIP_ERROR, NULL,
					"eXosip: cannot build REGISTER!\n"));
		*reg = NULL;
		return i;
	}

	return jr->r_id;
}
Beispiel #12
0
int jcall_ack(eXosip_event_t *je)
{
    jcall_t *ca;
    int k;

    if (___call_init==0)
    {
        ___call_init = -1;
        __call_init();
    }

    for (k=0; k<MAX_NUMBER_OF_CALLS; k++)
    {
        if (jcalls[k].state != NOT_USED
                && jcalls[k].cid==je->cid
                && jcalls[k].did==je->did)
            break;
    }
    if (k==MAX_NUMBER_OF_CALLS)
        return -1;

    ca = &(jcalls[k]);

    if (je->remote_sdp_audio_ip[0]!='\0')
    {
        osip_strncpy(ca->remote_sdp_audio_ip, je->remote_sdp_audio_ip, 49);
        ca->remote_sdp_audio_port = je->remote_sdp_audio_port;
        ca->payload = je->payload;
        osip_strncpy(ca->payload_name, je->payload_name, 49);
    }
    if (ca->remote_sdp_audio_ip[0]!='\0')
    {
        if (0==os_sound_start(ca, atoi(je->jc->c_sdp_port)))
        {
            ca->enable_audio=1; /* audio is started */
        }
    }

    if (je->reason_phrase[0]!='\0')
    {
        osip_strncpy(ca->reason_phrase, je->reason_phrase, 49);
        ca->status_code = je->status_code;
    }
    ca->state = je->type;
    return 0;
}
static int
sdp_message_parse_i (sdp_message_t * sdp, char *buf, char **next)
{
  char *equal;
  char *crlf;
  int i;
  char *i_info;

  *next = buf;

  equal = buf;
  while ((*equal != '=') && (*equal != '\0'))
    equal++;
  if (*equal == '\0')
    return ERR_ERROR;

  /* check if header is "i" */
  if (equal[-1] != 'i')
    return ERR_DISCARD;

  crlf = equal + 1;

  while ((*crlf != '\r') && (*crlf != '\n') && (*crlf != '\0'))
    crlf++;
  if (*crlf == '\0')
    return ERR_ERROR;
  if (crlf == equal + 1)
    return ERR_ERROR;		/* o=\r ?? bad header */

  /* s=text */

  /* text is interpreted as ISO-10646 UTF8! */
  /* using ISO 8859-1 requires "a=charset:ISO-8859-1 */
  i_info = osip_malloc (crlf - (equal + 1) + 1);
  osip_strncpy (i_info, equal + 1, crlf - (equal + 1));

  /* add the bandwidth at the correct place:
     if there is no media line yet, then the "b=" is the
     global one.
   */
  i = osip_list_size (sdp->m_medias);
  if (i == 0)
    sdp->i_info = i_info;
  else
    {
      sdp_media_t *last_sdp_media =
	(sdp_media_t *) osip_list_get (sdp->m_medias, i - 1);
      last_sdp_media->i_info = i_info;
    }

  if (crlf[1] == '\n')
    *next = crlf + 2;
  else
    *next = crlf + 1;
  return WF;
}
int
eXosip_subscribe_init(eXosip_subscribe_t **js, char *uri)
{
  if (uri==NULL) return -1;
  *js = (eXosip_subscribe_t *)osip_malloc(sizeof(eXosip_subscribe_t));
  if (*js == NULL) return -1;
  memset(*js, 0, sizeof(eXosip_subscribe_t));
  osip_strncpy((*js)->s_uri, uri, strlen(uri));
  return 0;
}
Beispiel #15
0
/* returns -1 on error. */
int
osip_message_set_topheader (osip_message_t * sip, const char *hname, const char *hvalue)
{
  osip_header_t *h;
  int i;

  if (hname == NULL)
    return -1;

  i = osip_header_init (&h);
  if (i != 0)
    return -1;

  h->hname = (char *) osip_malloc (strlen (hname) + 1);

  if (h->hname == NULL)
    {
      osip_header_free (h);
      return -1;
    }
  osip_strncpy (h->hname, hname, strlen (hname));
  osip_clrspace (h->hname);

  if (hvalue != NULL)
    {				/* some headers can be null ("subject:") */
      h->hvalue = (char *) osip_malloc (strlen (hvalue) + 1);
      if (h->hvalue == NULL)
	{
	  osip_header_free (h);
	  return -1;
	}
      osip_strncpy (h->hvalue, hvalue, strlen (hvalue));
      osip_clrspace (h->hvalue);
    }
  else
    h->hvalue = NULL;
#ifdef USE_TMP_BUFFER
  sip->message_property = 2;
#endif
  osip_list_add (sip->headers, h, 0);
  return 0;			/* ok */
}
Beispiel #16
0
char *
osip_strdup (const char *ch)
{
  char *copy;
  size_t length;
  if (ch == NULL)
    return NULL;
  length = strlen (ch);
  copy = (char *) osip_malloc (length + 1);
  osip_strncpy (copy, ch, length);
  return copy;
}
Beispiel #17
0
/* This is a portable way to find the default gateway.
 * The ip of the default interface is returned.
 */
static int _eXosip_default_gateway_ipv4(char *address, int size)
{
#ifdef __APPLE_CC__
	int len;
#else
	unsigned int len;
#endif
	int sock_rt, on = 1;

	struct sockaddr_in iface_out;

	struct sockaddr_in remote;

	memset(&remote, 0, sizeof(struct sockaddr_in));

	remote.sin_family = AF_INET;
	remote.sin_addr.s_addr = inet_addr(eXosip.ipv4_for_gateway);
	remote.sin_port = htons(11111);

	memset(&iface_out, 0, sizeof(iface_out));
	sock_rt = socket(AF_INET, SOCK_DGRAM, 0);

	if (setsockopt(sock_rt, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on)) == -1) {
		perror("DEBUG: [get_output_if] setsockopt(SOL_SOCKET, SO_BROADCAST");
		close(sock_rt);
		snprintf(address, size, "127.0.0.1");
		return OSIP_NO_NETWORK;
	}

	if (connect
		(sock_rt, (struct sockaddr *) &remote, sizeof(struct sockaddr_in)) == -1) {
		perror("DEBUG: [get_output_if] connect");
		close(sock_rt);
		snprintf(address, size, "127.0.0.1");
		return OSIP_NO_NETWORK;
	}

	len = sizeof(iface_out);
	if (getsockname(sock_rt, (struct sockaddr *) &iface_out, &len) == -1) {
		perror("DEBUG: [get_output_if] getsockname");
		close(sock_rt);
		snprintf(address, size, "127.0.0.1");
		return OSIP_NO_NETWORK;
	}

	close(sock_rt);
	if (iface_out.sin_addr.s_addr == 0) {	/* what is this case?? */
		snprintf(address, size, "127.0.0.1");
		return OSIP_NO_NETWORK;
	}
	osip_strncpy(address, inet_ntoa(iface_out.sin_addr), size - 1);
	return OSIP_SUCCESS;
}
Beispiel #18
0
int
main (int argc, char **argv)
{
  FILE *urls_file;


  osip_uri_t *url;
  char *a_url;
  char *dest;
  char *res;

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

  a_url = (char *) osip_malloc (200);
  res = fgets (a_url, 200, urls_file);  /* lines are under 200 */
  while (res != NULL)
    {
      int errcode;

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

      if (0 != strncmp (a_url, "#", 1))
        {
          /* allocate & init url */
          osip_uri_init (&url);
          printf ("=================================================\n");
          printf ("URL TO PARSE: |%s|\n", a_url);
          errcode = osip_uri_parse (url, a_url);
          if (errcode != -1)
            {
              if (osip_uri_to_str (url, &dest) != -1)
                {
                  printf ("result:       |%s|\n", dest);
                  osip_uri_test_accessor_api (url);
                  osip_free (dest);
                }
          } else
            printf ("Bad url format: %s\n", a_url);
          osip_uri_free (url);
          printf ("=================================================\n");
        }
      res = fgets (a_url, 200, urls_file);      /* lines are under 200 */
    }
  osip_free (a_url);
  return 0;
}
Beispiel #19
0
int
main (int argc, char **argv)
{
  FILE *vias_file;


  osip_via_t *via;
  char *a_via;
  char *dest;
  char *res;

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

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

      int errcode;

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

      if (0 != strncmp (a_via, "#", 1))
        {
          /* allocate & init via */
          osip_via_init (&via);
          printf ("=================================================\n");
          printf ("VIA TO PARSE: |%s|\n", a_via);
          errcode = osip_via_parse (via, a_via);
          if (errcode != -1)
            {
              if (osip_via_to_str (via, &dest) != -1)
                {
                  printf ("result:       |%s|\n", dest);
                  osip_free (dest);
                }
          } else
            printf ("Bad via format: %s\n", a_via);
          osip_via_free (via);
          printf ("=================================================\n");
        }
      res = fgets (a_via, 200, vias_file);      /* lines are under 200 */
    }
  osip_free (a_via);

  return 0;
}
Beispiel #20
0
int
eXosip_notify_init (eXosip_notify_t ** jn, osip_message_t * inc_subscribe)
{
  osip_contact_t *co;
  char *uri;
  int i;
  char locip[50];

#ifdef SM
  eXosip_get_localip_from_via (inc_subscribe, locip, 49);
#else
  i = _eXosip_find_protocol (inc_subscribe);
  if (i == IPPROTO_UDP)
    {
      eXosip_guess_ip_for_via (eXosip.net_interfaces[0].net_ip_family, locip, 49);
  } else if (i == IPPROTO_TCP)
    {
      eXosip_guess_ip_for_via (eXosip.net_interfaces[1].net_ip_family, locip, 49);
  } else
    {
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_ERROR, NULL,
                   "eXosip: unsupported protocol (default to UDP)\n"));
      eXosip_guess_ip_for_via (eXosip.net_interfaces[0].net_ip_family, locip, 49);
      return -1;
    }

#endif
  if (inc_subscribe == NULL
      || inc_subscribe->to == NULL || inc_subscribe->to->url == NULL)
    return -1;
  co = (osip_contact_t *) osip_list_get (inc_subscribe->contacts, 0);
  if (co == NULL || co->url == NULL)
    return -1;

  *jn = (eXosip_notify_t *) osip_malloc (sizeof (eXosip_notify_t));
  if (*jn == NULL)
    return -1;
  memset (*jn, 0, sizeof (eXosip_notify_t));

  i = osip_uri_to_str (co->url, &uri);
  if (i != 0)
    {
      osip_free (*jn);
      *jn = NULL;
      return -1;
    }
  osip_strncpy ((*jn)->n_uri, uri, 254);
  osip_free (uri);

  return 0;
}
Beispiel #21
0
int jcall_offhold(eXosip_event_t *je)
{
    jcall_t *ca;
    int k;

    if (___call_init==0)
    {
        ___call_init = -1;
        __call_init();
    }

    for (k=0; k<MAX_NUMBER_OF_CALLS; k++)
    {
        if (jcalls[k].state != NOT_USED
                && jcalls[k].cid==je->cid
                && jcalls[k].did==je->did)
            break;
    }
    if (k==MAX_NUMBER_OF_CALLS)
        return -1;

    ca = &(jcalls[k]);
    osip_strncpy(ca->textinfo,   je->textinfo, 255);

    if (ca->remote_sdp_audio_ip[0]=='\0')
    {
        osip_strncpy(ca->remote_sdp_audio_ip, je->remote_sdp_audio_ip, 49);
        ca->remote_sdp_audio_port = je->remote_sdp_audio_port;
    }

    if (je->reason_phrase[0]!='\0')
    {
        osip_strncpy(ca->reason_phrase, je->reason_phrase, 49);
        ca->status_code = je->status_code;
    }
    ca->state = je->type;
    return 0;
}
sdp_message_t *get_test_remote_message(int index, FILE *torture_file, int verbose)
{
  sdp_message_t *remote_sdp;
  char *msg;
  char *tmpmsg;
  char *tmp;
  char *marker;
  int i;

  i = 0;
  tmp = (char *) osip_malloc (500);
  marker = fgets (tmp, 500, torture_file);	/* lines are under 500 */
  while (marker != NULL && i < index)
    {
      if (0 == strncmp (tmp, "|", 1))
	i++;
      marker = fgets (tmp, 500, torture_file);
    }

  msg = (char *) osip_malloc (10000);	/* msg are under 10000 */
  tmpmsg = msg;

  if (marker == NULL)
    {
      fprintf (stderr,
	       "Error! The message's number you specified does not exist\n");
      osip_free (msg);
      return NULL;			/* end of file detected! */
    }
  /* this part reads an entire message, separator is "|" */
  /* (it is unlinkely that it will appear in messages!) */
  while (marker != NULL && strncmp (tmp, "|", 1))
    {
      osip_strncpy (tmpmsg, tmp, strlen (tmp));
      tmpmsg = tmpmsg + strlen (tmp);
      marker = fgets (tmp, 500, torture_file);
    }

  if (verbose)
      fprintf (stdout, "%s\n", msg);

  i = sdp_message_init(&remote_sdp);
  if (i!=0) return NULL;
  
  i = sdp_message_parse(remote_sdp, msg);
  if (i!=0) return NULL;
  
  return remote_sdp;
}
Beispiel #23
0
/* append string_osip_to_append to string at position cur
   size is the current allocated size of the element
*/
char *__osip_sdp_append_string(char *string, size_t size, char *cur,
							   char *string_osip_to_append)
{
	size_t length = strlen(string_osip_to_append);

	if (cur - string + length > size) {
		size_t length2;

		length2 = cur - string;
		string = osip_realloc(string, size + length + 10);
		cur = string + length2;	/* the initial allocation may have changed! */
	}
	osip_strncpy(cur, string_osip_to_append, length);
	return cur + strlen(cur);
}
static int
sdp_message_parse_r (sdp_message_t * sdp, char *buf, char **next)
{
  char *equal;
  char *crlf;
  int index;
  char *r_header;
  sdp_time_descr_t *t_descr;

  *next = buf;

  equal = buf;
  while ((*equal != '=') && (*equal != '\0'))
    equal++;
  if (*equal == '\0')
    return ERR_ERROR;

  /* check if header is "r" */
  if (equal[-1] != 'r')
    return ERR_DISCARD;

  index = osip_list_size (sdp->t_descrs);
  if (index == 0)
    return ERR_ERROR;		/* r field can't come alone! */

  crlf = equal + 1;

  while ((*crlf != '\r') && (*crlf != '\n') && (*crlf != '\0'))
    crlf++;
  if (*crlf == '\0')
    return ERR_ERROR;
  if (crlf == equal + 1)
    return ERR_ERROR;		/* r=\r ?? bad header */

  /* r=far too complexe and somewhat useless... I don't parse it! */
  r_header = osip_malloc (crlf - (equal + 1) + 1);
  osip_strncpy (r_header, equal + 1, crlf - (equal + 1));

  /* r field carry information for the last "t" field */
  t_descr = (sdp_time_descr_t *) osip_list_get (sdp->t_descrs, index - 1);
  osip_list_add (t_descr->r_repeats, r_header, -1);

  if (crlf[1] == '\n')
    *next = crlf + 2;
  else
    *next = crlf + 1;
  return WF;
}
int
osip_content_length_parse (osip_content_length_t * content_length, const char *hvalue)
{
  size_t len;

  if (hvalue == NULL)
    return OSIP_BADPARAMETER;
  len = strlen (hvalue);
  if (len + 1 < 2)
    return OSIP_SYNTAXERROR;
  content_length->value = (char *) osip_malloc (len + 1);
  if (content_length->value == NULL)
    return OSIP_NOMEM;
  osip_strncpy (content_length->value, hvalue, len);
  return OSIP_SUCCESS;
}
int
osip_content_length_parse (osip_content_length_t * content_length,
                           const char *hvalue)
{
    size_t len;

    if (hvalue == NULL)
        return -1;
    len = strlen (hvalue);
    if (len + 1 < 2)
        return -1;
    content_length->value = (char *) osip_malloc (len + 1);
    if (content_length->value == NULL)
        return -1;
    osip_strncpy (content_length->value, hvalue, len);
    return 0;
}
Beispiel #27
0
int
eXosip_call_build_notify (int did, int subscription_status,
                          osip_message_t ** request)
{
  char subscription_state[50];
  char *tmp;
  int i;

  *request = NULL;
  i = eXosip_call_build_request (did, "NOTIFY", request);
  if (i != 0)
    return i;

  if (subscription_status == EXOSIP_SUBCRSTATE_PENDING)
    osip_strncpy (subscription_state, "pending;expires=", 16);
  else if (subscription_status == EXOSIP_SUBCRSTATE_ACTIVE)
    osip_strncpy (subscription_state, "active;expires=", 15);
  else if (subscription_status == EXOSIP_SUBCRSTATE_TERMINATED)
    {
      int reason = NORESOURCE;

      if (reason == DEACTIVATED)
        osip_strncpy (subscription_state, "terminated;reason=deactivated", 29);
      else if (reason == PROBATION)
        osip_strncpy (subscription_state, "terminated;reason=probation", 27);
      else if (reason == REJECTED)
        osip_strncpy (subscription_state, "terminated;reason=rejected", 26);
      else if (reason == TIMEOUT)
        osip_strncpy (subscription_state, "terminated;reason=timeout", 25);
      else if (reason == GIVEUP)
        osip_strncpy (subscription_state, "terminated;reason=giveup", 24);
      else if (reason == NORESOURCE)
        osip_strncpy (subscription_state, "terminated;reason=noresource", 29);
    }
  tmp = subscription_state + strlen (subscription_state);
  if (subscription_status != EXOSIP_SUBCRSTATE_TERMINATED)
    sprintf (tmp, "%i", 180);
  osip_message_set_header (*request, "Subscription-State", subscription_state);

  return OSIP_SUCCESS;
}
Beispiel #28
0
static char *
read_text (int num, FILE * torture_file)
{
  char *marker;
  char *tmp;
  char *tmpmsg;
  char *msg;
  int i;
  static int num_test = 0;

  i = 0;
  tmp = (char *) osip_malloc (500);
  marker = fgets (tmp, 500, torture_file);      /* lines are under 500 */
  while (marker != NULL && i < num) {
    if (0 == strncmp (tmp, "|", 1))
      i++;
    marker = fgets (tmp, 500, torture_file);
  }
  num_test++;

  msg = (char *) osip_malloc (100000);  /* msg are under 10000 */
  if (msg == NULL) {
    fprintf (stderr, "Error! osip_malloc failed\n");
    return NULL;
  }
  tmpmsg = msg;

  if (marker == NULL) {
    fprintf (stderr, "Error! The message's number you specified does not exist\n");
    return NULL;                /* end of file detected! */
  }
  /* this part reads an entire message, separator is "|" */
  /* (it is unlinkely that it will appear in messages!) */
  while (marker != NULL && strncmp (tmp, "|", 1)) {
    osip_strncpy (tmpmsg, tmp, strlen (tmp));
    tmpmsg = tmpmsg + strlen (tmp);
    marker = fgets (tmp, 500, torture_file);
  }

  osip_free (tmp);
  return msg;
}
static int
sdp_message_parse_p (sdp_message_t * sdp, char *buf, char **next)
{
  char *equal;
  char *crlf;
  char *p_phone;

  *next = buf;

  equal = buf;
  while ((*equal != '=') && (*equal != '\0'))
    equal++;
  if (*equal == '\0')
    return ERR_ERROR;

  /* check if header is "p" */
  if (equal[-1] != 'p')
    return ERR_DISCARD;

  crlf = equal + 1;

  while ((*crlf != '\r') && (*crlf != '\n') && (*crlf != '\0'))
    crlf++;
  if (*crlf == '\0')
    return ERR_ERROR;
  if (crlf == equal + 1)
    return ERR_ERROR;		/* p=\r ?? bad header */

  /* e=email */
  /* we assume this is an EMAIL-ADDRESS */
  p_phone = osip_malloc (crlf - (equal + 1) + 1);
  osip_strncpy (p_phone, equal + 1, crlf - (equal + 1));

  osip_list_add (sdp->p_phones, p_phone, -1);

  if (crlf[1] == '\n')
    *next = crlf + 2;
  else
    *next = crlf + 1;
  return WF;
}
static int
sdp_message_parse_z (sdp_message_t * sdp, char *buf, char **next)
{
  char *equal;
  char *crlf;
  char *z_header;

  *next = buf;

  equal = buf;
  while ((*equal != '=') && (*equal != '\0'))
    equal++;
  if (*equal == '\0')
    return ERR_ERROR;

  /* check if header is "z" */
  if (equal[-1] != 'z')
    return ERR_DISCARD;

  crlf = equal + 1;

  while ((*crlf != '\r') && (*crlf != '\n') && (*crlf != '\0'))
    crlf++;
  if (*crlf == '\0')
    return ERR_ERROR;
  if (crlf == equal + 1)
    return ERR_ERROR;		/* z=\r ?? bad header */

  /* z=somewhat useless... I don't parse it! */
  z_header = osip_malloc (crlf - (equal + 1) + 1);
  osip_strncpy (z_header, equal + 1, crlf - (equal + 1));

  sdp->z_adjustments = z_header;

  if (crlf[1] == '\n')
    *next = crlf + 2;
  else
    *next = crlf + 1;
  return WF;
}