Exemplo n.º 1
0
int
sdp_time_descr_init (sdp_time_descr_t ** td)
{
  *td = (sdp_time_descr_t *) osip_malloc (sizeof (sdp_time_descr_t));
  if (*td == NULL)
    return -1;
  (*td)->t_start_time = NULL;
  (*td)->t_stop_time = NULL;
  (*td)->r_repeats = (osip_list_t *) osip_malloc (sizeof (osip_list_t));
  osip_list_init ((*td)->r_repeats);
  return 0;
}
Exemplo n.º 2
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;
	int i;

	/* How to parse:

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

	   examples:

	   application/multipart ; boundary=
	   ^          ^
	 */
	if (hvalue == NULL || hvalue[0] == '\0')
		return OSIP_SUCCESS;	/* It's valid to add empty Accept header! */

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

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

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

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

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

	return OSIP_SUCCESS;
}
Exemplo n.º 3
0
//---------------------------------------------------------------------
void
Node::TransferUserInfoToPred(ChordId node)
{
	uinfo_t *red_cur=red_user_info_list;
	uinfo_t *cur=user_info_list;
	while(red_cur != NULL)
	{
		char *red_aor;
		uinfo_t *red_tmp=red_cur;
		red_cur=red_cur->next;
		osip_uri_to_str(red_tmp->aor->uri,&red_aor);
		if(red_aor)	osip_free(red_aor) ;
			
		char * red_registrar= (char *)osip_malloc(4 + strlen(node.GetAddress()) +1) ;
		sprintf (red_registrar, "sip:%s", node.GetAddress());
		SndUserRegisterRequest(RED_REGISTER,red_tmp,red_registrar ,3600);
		if(red_registrar)	osip_free(red_registrar) ;
		
		REMOVE_ELEMENT(red_user_info_list,red_tmp);
		delete red_tmp;
		

	}
	
	ChordId localnode=getChordId();
	unsigned int uid=0;
	while(cur != NULL)
	{
		
		char *aor;
		uinfo_t *tmp=cur;
		cur=cur->next;
		osip_uri_to_str(tmp->aor->uri,&aor);
		uid=uhash(aor);
		if(aor)	osip_free(aor) ;

		Constants constants(NULL);
		ChordId UserID(uid,&constants);
		if(!UserID.BelongsRightInclusive(node,localnode))
		{
			char * registrar= (char *)osip_malloc(4 + strlen(node.GetAddress()) +1) ;
			sprintf (registrar, "sip:%s", node.GetAddress());
			SndUserRegisterRequest(USER_REGISTRATION,tmp,registrar,3600);
			if(registrar)	osip_free(registrar) ;
		
			REMOVE_ELEMENT(user_info_list,tmp);
			//ADD_ELEMENT(red_user_info_list,tmp);//move this user info to redundant user info list
			delete tmp;
		}
	}

}
Exemplo n.º 4
0
int
_eXosip_dialog_init_as_uas (eXosip_dialog_t ** _jd, osip_message_t * _invite, osip_message_t * _200Ok)
{
  int i;
  eXosip_dialog_t *jd;

  *_jd = NULL;
  jd = (eXosip_dialog_t *) osip_malloc (sizeof (eXosip_dialog_t));
  if (jd == NULL)
    return OSIP_NOMEM;
  memset (jd, 0, sizeof (eXosip_dialog_t));
  jd->d_id = -1;                /* not yet available to user */
  i = osip_dialog_init_as_uas (&(jd->d_dialog), _invite, _200Ok);
  if (i != 0) {
    osip_free (jd);
    return i;
  }

  jd->d_count = 0;
  jd->d_session_timer_start = 0;
  jd->d_session_timer_length = 0;
  jd->d_session_timer_use_update = -1;
  jd->d_refresher = -1;         /* 0 -> me / 1 -> remote */
  jd->d_timer = osip_getsystemtime (NULL);
  jd->d_200Ok = NULL;
  jd->d_ack = NULL;
  jd->next = NULL;
  jd->parent = NULL;
  jd->d_out_trs = (osip_list_t *) osip_malloc (sizeof (osip_list_t));
  if (jd->d_out_trs == NULL) {
    osip_dialog_free (jd->d_dialog);
    osip_free (jd);
    return OSIP_NOMEM;
  }
  osip_list_init (jd->d_out_trs);
  jd->d_inc_trs = (osip_list_t *) osip_malloc (sizeof (osip_list_t));
  if (jd->d_inc_trs == NULL) {
    osip_dialog_free (jd->d_dialog);
    osip_free (jd->d_out_trs);
    osip_free (jd);
    return OSIP_NOMEM;
  }
  osip_list_init (jd->d_inc_trs);

  jd->d_dialog->local_cseq = 1;

  *_jd = jd;
  return OSIP_SUCCESS;
}
Exemplo n.º 5
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;
}
int
osip_accept_encoding_parse (osip_accept_encoding_t * accept_encoding,
                            const char *hvalue)
{
  const char *osip_accept_encoding_params;

  osip_accept_encoding_params = strchr (hvalue, ';');

  if (osip_accept_encoding_params != NULL)
    {
      if (__osip_generic_param_parseall (&accept_encoding->gen_params,
                                         osip_accept_encoding_params) == -1)
        return -1;
  } else
    osip_accept_encoding_params = hvalue + strlen (hvalue);

  if (osip_accept_encoding_params - hvalue + 1 < 2)
    return -1;
  accept_encoding->element =
    (char *) osip_malloc (osip_accept_encoding_params - hvalue + 1);
  if (accept_encoding->element == NULL)
    return -1;
  osip_clrncpy (accept_encoding->element, hvalue,
                osip_accept_encoding_params - hvalue);

  return 0;
}
Exemplo n.º 7
0
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;
}
Exemplo n.º 8
0
int
osip_call_info_parse (osip_call_info_t * call_info, const char *hvalue)
{
  const char *osip_call_info_params;

  osip_call_info_params = strchr (hvalue, '<');
  if (osip_call_info_params == NULL)
    return -1;

  osip_call_info_params = strchr (osip_call_info_params + 1, '>');
  if (osip_call_info_params == NULL)
    return -1;

  osip_call_info_params = strchr (osip_call_info_params + 1, ';');

  if (osip_call_info_params != NULL)
    {
      if (__osip_generic_param_parseall
          (call_info->gen_params, osip_call_info_params) == -1)
        return -1;
  } else
    osip_call_info_params = hvalue + strlen (hvalue);

  if (osip_call_info_params - hvalue + 1 < 2)
    return -1;
  call_info->element = (char *) osip_malloc (osip_call_info_params - hvalue + 1);
  if (call_info->element == NULL)
    return -1;
  osip_clrncpy (call_info->element, hvalue, osip_call_info_params - hvalue);

  return 0;
}
int
osip_call_info_parse (osip_call_info_t * call_info, const char *hvalue)
{
  const char *osip_call_info_params;
  int i;

  osip_call_info_params = strchr (hvalue, '<');
  if (osip_call_info_params == NULL)
    return OSIP_SYNTAXERROR;

  osip_call_info_params = strchr (osip_call_info_params + 1, '>');
  if (osip_call_info_params == NULL)
    return OSIP_SYNTAXERROR;

  osip_call_info_params = strchr (osip_call_info_params + 1, ';');

  if (osip_call_info_params != NULL)
    {
	  i = __osip_generic_param_parseall(&call_info->gen_params, osip_call_info_params);
      if (i != 0)
        return i;
  } else
    osip_call_info_params = hvalue + strlen (hvalue);

  if (osip_call_info_params - hvalue + 1 < 2)
    return OSIP_SYNTAXERROR;
  call_info->element = (char *) osip_malloc (osip_call_info_params - hvalue + 1);
  if (call_info->element == NULL)
    return OSIP_NOMEM;
  osip_clrncpy (call_info->element, hvalue, osip_call_info_params - hvalue);

  return OSIP_SUCCESS;
}
Exemplo n.º 10
0
char *strdup_printf(const char *fmt, ...)
{
	/* Guess we need no more than 100 bytes. */
	int n, size = 100;
	char *p;
	va_list ap;
	if ((p = osip_malloc (size)) == NULL)
		return NULL;
	while (1)
	{
		/* Try to print in the allocated space. */
		va_start (ap, fmt);
#ifdef WIN32
		n = _vsnprintf (p, size, fmt, ap);
#else
		n = vsnprintf (p, size, fmt, ap);
#endif
		va_end (ap);
		/* If that worked, return the string. */
		if (n > -1 && n < size)
			return p;
		/* Else try again with more space. */
		if (n > -1)	/* glibc 2.1 */
			size = n + 1;	/* precisely what is needed */
		else		/* glibc 2.0 */
			size *= 2;	/* twice the old size */
		if ((p = realloc (p, size)) == NULL)
			return NULL;
	}
}
Exemplo n.º 11
0
char *
osip_enquote (const char *s)
{
  char *rtn;
  char *t;

  t = rtn = osip_malloc (strlen (s) * 2 + 3);
  *t++ = '"';
  for (; *s != '\0'; s++)
    {
      switch (*s)
        {
          case '"':
          case '\\':
          case 0x7f:
            *t++ = '\\';
            *t++ = *s;
            break;
          case '\n':
          case '\r':
            *t++ = ' ';
            break;
          default:
            *t++ = *s;
            break;
        }
    }
  *t++ = '"';
  *t++ = '\0';
  return rtn;
}
Exemplo n.º 12
0
/* returns null on error. */
int
osip_content_type_to_str (const osip_content_type_t * content_type,
			  char **dest)
{
  char *buf;
  char *tmp;
  size_t len;

  *dest = NULL;
  if ((content_type == NULL) || (content_type->type == NULL)
      || (content_type->subtype == NULL))
    return -1;

  /* try to guess a long enough length */
  len = strlen (content_type->type) + strlen (content_type->subtype) + 4	/* for '/', ' ', ';' and '\0' */
    + 10 * osip_list_size (content_type->gen_params);

  buf = (char *) osip_malloc (len);
  tmp = buf;

  sprintf (tmp, "%s/%s", content_type->type, content_type->subtype);

  tmp = tmp + strlen (tmp);
  {
    int pos = 0;
    osip_generic_param_t *u_param;

    if (!osip_list_eol (content_type->gen_params, pos))
      {				/* needed for cannonical form! (authentication issue of rfc2543) */
	sprintf (tmp, " ");
	tmp++;
      }
    while (!osip_list_eol (content_type->gen_params, pos))
      {
	size_t tmp_len;

	u_param =
	  (osip_generic_param_t *) osip_list_get (content_type->gen_params,
						  pos);
	if (u_param->gvalue == NULL)
	  {
	    osip_free (buf);
	    return -1;
	  }
	tmp_len = strlen (buf) + 4 + strlen (u_param->gname)
	  + strlen (u_param->gvalue);
	if (len < tmp_len)
	  {
	    buf = osip_realloc (buf, tmp_len);
	    len = tmp_len;
	    tmp = buf + strlen (buf);
	  }
	sprintf (tmp, ";%s=%s", u_param->gname, u_param->gvalue);
	tmp = tmp + strlen (tmp);
	pos++;
      }
  }
  *dest = buf;
  return 0;
}
Exemplo n.º 13
0
/* returns null on error. */
int
osip_header_to_str (const osip_header_t * header, char **dest)
{
  size_t len;

  *dest = NULL;
  if ((header == NULL) || (header->hname == NULL))
    return OSIP_BADPARAMETER;

  len = 0;
  if (header->hvalue != NULL)
    len = strlen (header->hvalue);

  *dest = (char *) osip_malloc (strlen (header->hname) + len + 3);
  if (*dest == NULL)
    return OSIP_NOMEM;

  if (header->hvalue != NULL)
    sprintf (*dest, "%s: %s", header->hname, header->hvalue);
  else
    sprintf (*dest, "%s: ", header->hname);

  if (*dest[0] > 'a' && *dest[0] < 'z')
    *dest[0] = (*dest[0] - 32);
  return OSIP_SUCCESS;
}
Exemplo n.º 14
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;
}
Exemplo n.º 15
0
void 
Node::TransferUserInfoToSucc(ChordId node)
{
	uinfo_t *cur=user_info_list;
	uinfo_t *red_cur=red_user_info_list;

	char * succ= (char *)osip_malloc(4 + strlen(node.GetAddress()) +1) ;
	sprintf (succ, "sip:%s", node.GetAddress());
	const char *registrar=succ ;

	//转移该节点负责的用户信息
	while(cur != NULL)
	{
		uinfo_t *tmp=cur;
		cur=tmp->next;
		SndUserRegisterRequest(USER_REGISTRATION,tmp,registrar,3600);
		REMOVE_ELEMENT(user_info_list,tmp);
		delete tmp;
	}
	
	//转移该节点负责的冗余用户信息
	while(red_cur != NULL)
	{
		uinfo_t *tmp2=red_cur;
		red_cur=tmp2->next;
		SndUserRegisterRequest(RED_REGISTER,tmp2,registrar,3600);
		REMOVE_ELEMENT(red_user_info_list,tmp2);
		delete tmp2;
	}

	if(succ)	osip_free(succ) ;
}
Exemplo n.º 16
0
/* osip_message_t *sip is filled while analysing buf */
static int
_osip_message_parse (osip_message_t * sip, const char *buf, size_t length, int sipfrag)
{
  int i;
  const char *next_header_index;
  char *tmp;
  char *beg;

  tmp = osip_malloc (length + 2);
  if (tmp == NULL) {
    OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Could not allocate memory.\n"));
    return OSIP_NOMEM;
  }
  beg = tmp;
  memcpy (tmp, buf, length);    /* may contain binary data */
  tmp[length] = '\0';
  /* skip initial \r\n */
  while (tmp[0] == '\r' || tmp[0] == '\n')
    tmp++;
  osip_util_replace_all_lws (tmp);
  /* parse request or status line */
  i = __osip_message_startline_parse (sip, tmp, &next_header_index);
  if (i != 0 && !sipfrag) {
    OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Could not parse start line of message.\n"));
    osip_free (beg);
    return i;
  }
  tmp = (char *) next_header_index;

  /* parse headers */
  i = msg_headers_parse (sip, tmp, &next_header_index);
  if (i != 0) {
    OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "error in msg_headers_parse()\n"));
    osip_free (beg);
    return i;
  }
  tmp = (char *) next_header_index;

  /* this is a *very* simple test... (which handle most cases...) */
  if (tmp[0] == '\0' || tmp[1] == '\0' || tmp[2] == '\0') {
    /* this is mantory in the oSIP stack */
    if (sip->content_length == NULL)
      osip_message_set_content_length (sip, "0");
    osip_free (beg);
    return OSIP_SUCCESS;        /* no body found */
  }

  i = msg_osip_body_parse (sip, tmp, &next_header_index, length - (tmp - beg));
  osip_free (beg);
  if (i != 0) {
    OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "error in msg_osip_body_parse()\n"));
    return i;
  }

  /* this is mandatory in the oSIP stack */
  if (sip->content_length == NULL)
    osip_message_set_content_length (sip, "0");

  return OSIP_SUCCESS;
}
Exemplo n.º 17
0
int
osip_accept_encoding_parse(osip_accept_encoding_t * accept_encoding,
						   const char *hvalue)
{
	int i;
	const char *osip_accept_encoding_params;

	osip_accept_encoding_params = strchr(hvalue, ';');

	if (osip_accept_encoding_params != NULL) {
		i = __osip_generic_param_parseall(&accept_encoding->gen_params,
										  osip_accept_encoding_params);
		if (i != 0)
			return i;
	} else
		osip_accept_encoding_params = hvalue + strlen(hvalue);

	if (osip_accept_encoding_params - hvalue + 1 < 2)
		return OSIP_SYNTAXERROR;
	accept_encoding->element =
		(char *) osip_malloc(osip_accept_encoding_params - hvalue + 1);
	if (accept_encoding->element == NULL)
		return OSIP_NOMEM;
	osip_clrncpy(accept_encoding->element, hvalue,
				 osip_accept_encoding_params - hvalue);

	return OSIP_SUCCESS;
}
Exemplo n.º 18
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;
}
Exemplo n.º 19
0
static int __osip_message_startline_to_strresp(osip_message_t * sip, char **dest)
{
	char *tmp;
	const char *sip_version;
	char status_code[5];

	*dest = NULL;
	if ((sip == NULL) || (sip->reason_phrase == NULL)
		|| (sip->status_code < 100) || (sip->status_code > 699))
		return OSIP_BADPARAMETER;

	if (sip->sip_version == NULL)
		sip_version = osip_protocol_version;
	else
		sip_version = sip->sip_version;

	sprintf(status_code, "%u", sip->status_code);

	*dest = (char *) osip_malloc(strlen(sip_version)
								 + 3 + strlen(sip->reason_phrase) + 4);
	if (*dest == NULL)
		return OSIP_NOMEM;
	tmp = *dest;

	tmp = osip_str_append(tmp, sip_version);
	*tmp = ' ';
	tmp++;

	tmp = osip_strn_append(tmp, status_code, 3);
	*tmp = ' ';
	tmp++;
	strcpy(tmp, sip->reason_phrase);

	return OSIP_SUCCESS;
}
Exemplo n.º 20
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;
}
Exemplo n.º 21
0
/* returns -1 on error. */
int
osip_message_replace_header (osip_message_t * sip, const char *hname,
			     const char *hvalue)
{
  osip_header_t *h, *oldh;
  int i, oldpos = -1;

  if (sip == NULL || hname == NULL)
    return OSIP_BADPARAMETER;

  oldpos = osip_message_header_get_byname(sip, hname, 0, &oldh);

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

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

  if (h->hname == NULL)
    {
      osip_header_free (h);
      return OSIP_NOMEM;
    }
  osip_clrncpy (h->hname, hname, strlen (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 OSIP_NOMEM;
	}
      osip_clrncpy (h->hvalue, hvalue, strlen (hvalue));
    } else
      h->hvalue = NULL;

  if (oldpos != -1)
    {
      osip_list_remove(&sip->headers, oldpos);
      osip_header_free(oldh);
    }

  sip->message_property = 2;
  osip_list_add (&sip->headers, h, -1);
  return OSIP_SUCCESS;                     /* ok */
}
Exemplo n.º 22
0
static int
read_binary (char **msg, int *len, FILE * torture_file)
{
  *msg = (char *) osip_malloc (100000); /* msg are under 10000 */

  *len = fread (*msg, 1, 100000, torture_file);
  return ferror (torture_file) ? -1 : 0;
}
Exemplo n.º 23
0
int _eXosip_subscribe_init(eXosip_subscribe_t ** js)
{
	*js = (eXosip_subscribe_t *) osip_malloc(sizeof(eXosip_subscribe_t));
	if (*js == NULL)
		return OSIP_NOMEM;
	memset(*js, 0, sizeof(eXosip_subscribe_t));
	return OSIP_SUCCESS;
}
Exemplo n.º 24
0
int
osip_uri_param_init (osip_uri_param_t ** url_param)
{
  *url_param = (osip_uri_param_t *) osip_malloc (sizeof (osip_uri_param_t));
  (*url_param)->gname = NULL;
  (*url_param)->gvalue = NULL;
  return 0;
}
Exemplo n.º 25
0
int
osip_negotiation_remove_other_payloads (osip_negotiation_t *config)
{
  osip_list_special_free (config->other_codec, (void *(*)(void *)) &__payload_free);
  config->other_codec = (osip_list_t *) osip_malloc (sizeof (osip_list_t));
  osip_list_init (config->other_codec);
  return 0;
}
Exemplo n.º 26
0
int
__osip_nict_init (osip_nict_t ** nict, osip_t * osip, osip_message_t * request)
{
  osip_route_t *route;
  int i;

  OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO2, NULL, "allocating NICT context\n"));

  *nict = (osip_nict_t *) osip_malloc (sizeof (osip_nict_t));
  if (*nict == NULL)
    return OSIP_NOMEM;

  memset (*nict, 0, sizeof (osip_nict_t));
  /* for REQUEST retransmissions */
  {
    osip_via_t *via;
    char *proto;

    i = osip_message_get_via (request, 0, &via);        /* get top via */
    if (i < 0) {
      osip_free (*nict);
      *nict = NULL;
      return i;
    }
    proto = via_get_protocol (via);
    if (proto == NULL) {
      osip_free (*nict);
      *nict = NULL;
      return OSIP_UNDEFINED_ERROR;
    }
#ifdef USE_BLOCKINGSOCKET
    if (osip_strcasecmp (proto, "TCP") != 0 && osip_strcasecmp (proto, "TLS") != 0 && osip_strcasecmp (proto, "SCTP") != 0) {
      (*nict)->timer_e_length = DEFAULT_T1;
      (*nict)->timer_k_length = DEFAULT_T4;
      (*nict)->timer_e_start.tv_sec = -1;
      (*nict)->timer_k_start.tv_sec = -1;       /* not started */
    }
    else {                      /* reliable protocol is used: */
      (*nict)->timer_e_length = -1;     /* E is not ACTIVE */
      (*nict)->timer_k_length = 0;      /* MUST do the transition immediatly */
      (*nict)->timer_e_start.tv_sec = -1;
      (*nict)->timer_k_start.tv_sec = -1;       /* not started */
    }
  }
#else
    if (osip_strcasecmp (proto, "TCP") != 0 && osip_strcasecmp (proto, "TLS") != 0 && osip_strcasecmp (proto, "SCTP") != 0) {
      (*nict)->timer_e_length = DEFAULT_T1;
      (*nict)->timer_k_length = DEFAULT_T4;
      (*nict)->timer_e_start.tv_sec = -1;
      (*nict)->timer_k_start.tv_sec = -1;       /* not started */
    }
    else {                      /* reliable protocol is used: */
      (*nict)->timer_e_length = DEFAULT_T1;
      (*nict)->timer_k_length = 0;      /* MUST do the transition immediatly */
      (*nict)->timer_e_start.tv_sec = -1;
      (*nict)->timer_k_start.tv_sec = -1;       /* not started */
    }
  }
Exemplo n.º 27
0
PPL_DECLARE (int) tlp_rcv_func_init (tlp_rcv_func_t ** elt, int (*cb_rcv_func) (int), int plug_id)	/* number of element to get */
{
  *elt = (tlp_rcv_func_t *) osip_malloc (sizeof (tlp_rcv_func_t));
  if (*elt == NULL)
    return -1;
  (*elt)->cb_rcv_func = cb_rcv_func;
  (*elt)->plug_id = plug_id;
  return 0;
}
Exemplo n.º 28
0
static char *
osip_to_tag_new_random ()
{
  char *tmp = (char *) osip_malloc (33);
  unsigned int number = osip_build_random_number ();

  sprintf (tmp, "%u", number);
  return tmp;
}
Exemplo n.º 29
0
int
osip_content_length_init (osip_content_length_t ** cl)
{
  *cl = (osip_content_length_t *) osip_malloc (sizeof (osip_content_length_t));
  if (*cl == NULL)
    return OSIP_NOMEM;
  (*cl)->value = NULL;
  return OSIP_SUCCESS;
}
Exemplo n.º 30
0
int
osip_www_authenticate_init (osip_www_authenticate_t ** dest)
{
  *dest = (osip_www_authenticate_t *) osip_malloc (sizeof (osip_www_authenticate_t));
  if (*dest == NULL)
    return OSIP_NOMEM;
  memset (*dest, 0, sizeof (osip_www_authenticate_t));
  return OSIP_SUCCESS;
}