本文整理汇总了C++中osip_malloc函数的典型用法代码示例。如果您正苦于以下问题:C++ osip_malloc函数的具体用法?C++ osip_malloc怎么用?C++ osip_malloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了osip_malloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sdp_time_descr_init
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;
}
示例2: osip_content_type_parse
/* 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;
}
示例3: while
//---------------------------------------------------------------------
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;
}
}
}
示例4: _eXosip_dialog_init_as_uas
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;
}
示例5: osip_malloc
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;
}
示例6: osip_accept_encoding_parse
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;
}
示例7: jidentity_get_and_set_next_token
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;
}
示例8: osip_call_info_parse
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;
}
示例9: osip_call_info_parse
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;
}
示例10: vsnprintf
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;
}
}
示例11: osip_enquote
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;
}
示例12: osip_content_type_to_str
/* 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;
}
示例13: osip_header_to_str
/* 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;
}
示例14: sdp_message_parse_v
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;
}
示例15: strlen
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) ;
}