pj_str_t to char*

KD
Klaus Darilion
Wed, Dec 19, 2007 12:20 PM

Hi!

Are there helper functions which convert a pj_str_t into a null
terminated char* and also take care about allocating the memory for the
char*?

regards
Klaus

Hi! Are there helper functions which convert a pj_str_t into a null terminated char* and also take care about allocating the memory for the char*? regards Klaus
PC
P.J. Cast.
Wed, Dec 19, 2007 3:51 PM

If you are using C++, you can simply do:
std::string mystring(pj_str.ptr, pjs_str.slen);

If you are using C, you could write a simply little
function easily enough. Though, I'm not sure if pjsip
has a built in function.

  ____________________________________________________________________________________

Be a better friend, newshound, and
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

If you are using C++, you can simply do: std::string mystring(pj_str.ptr, pjs_str.slen); If you are using C, you could write a simply little function easily enough. Though, I'm not sure if pjsip has a built in function. ____________________________________________________________________________________ Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
BP
Benny Prijono
Sat, Dec 22, 2007 7:50 AM

P.J. Cast. wrote:

If you are using C++, you can simply do:
std::string mystring(pj_str.ptr, pjs_str.slen);

If you are using C, you could write a simply little
function easily enough. Though, I'm not sure if pjsip
has a built in function.

There are some actually:

PJ_IDECL(pj_str_t*) pj_strdup_with_null(pj_pool_t *pool,
pj_str_t *dst,
const pj_str_t src);
PJ_IDECL(pj_str_t
) pj_strdup2_with_null(pj_pool_t *pool,
pj_str_t *dst,
const char src);
PJ_IDECL(pj_str_t
) pj_strncpy_with_null(pj_str_t *dst,
const pj_str_t *src,
pj_ssize_t max);

With these functions, dst->ptr would be null terminated.

cheers,
-benny

P.J. Cast. wrote: > If you are using C++, you can simply do: > std::string mystring(pj_str.ptr, pjs_str.slen); > > If you are using C, you could write a simply little > function easily enough. Though, I'm not sure if pjsip > has a built in function. There are some actually: PJ_IDECL(pj_str_t*) pj_strdup_with_null(pj_pool_t *pool, pj_str_t *dst, const pj_str_t *src); PJ_IDECL(pj_str_t*) pj_strdup2_with_null(pj_pool_t *pool, pj_str_t *dst, const char *src); PJ_IDECL(pj_str_t*) pj_strncpy_with_null(pj_str_t *dst, const pj_str_t *src, pj_ssize_t max); With these functions, dst->ptr would be null terminated. cheers, -benny
KD
Klaus Darilion
Sat, Dec 22, 2007 4:40 PM

Benny Prijono wrote:

P.J. Cast. wrote:

If you are using C++, you can simply do:
std::string mystring(pj_str.ptr, pjs_str.slen);

If you are using C, you could write a simply little
function easily enough. Though, I'm not sure if pjsip
has a built in function.

There are some actually:

PJ_IDECL(pj_str_t*) pj_strdup_with_null(pj_pool_t *pool,
pj_str_t *dst,
const pj_str_t *src);

What is *pool? Is it available when I use the pjsua API?

klaus

PJ_IDECL(pj_str_t*) pj_strdup2_with_null(pj_pool_t *pool,
pj_str_t *dst,
const char src);
PJ_IDECL(pj_str_t
) pj_strncpy_with_null(pj_str_t *dst,
const pj_str_t *src,
pj_ssize_t max);

With these functions, dst->ptr would be null terminated.

cheers,
-benny


Visit our blog: http://blog.pjsip.org

pjsip mailing list
pjsip@lists.pjsip.org
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org

Benny Prijono wrote: > P.J. Cast. wrote: >> If you are using C++, you can simply do: >> std::string mystring(pj_str.ptr, pjs_str.slen); >> >> If you are using C, you could write a simply little >> function easily enough. Though, I'm not sure if pjsip >> has a built in function. > > There are some actually: > > PJ_IDECL(pj_str_t*) pj_strdup_with_null(pj_pool_t *pool, > pj_str_t *dst, > const pj_str_t *src); What is *pool? Is it available when I use the pjsua API? klaus > PJ_IDECL(pj_str_t*) pj_strdup2_with_null(pj_pool_t *pool, > pj_str_t *dst, > const char *src); > PJ_IDECL(pj_str_t*) pj_strncpy_with_null(pj_str_t *dst, > const pj_str_t *src, > pj_ssize_t max); > > With these functions, dst->ptr would be null terminated. > > cheers, > -benny > > _______________________________________________ > Visit our blog: http://blog.pjsip.org > > pjsip mailing list > pjsip@lists.pjsip.org > http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
BP
Benny Prijono
Wed, Dec 26, 2007 8:58 AM

Klaus Darilion wrote:

Benny Prijono wrote:

P.J. Cast. wrote:

If you are using C++, you can simply do:
std::string mystring(pj_str.ptr, pjs_str.slen);

If you are using C, you could write a simply little
function easily enough. Though, I'm not sure if pjsip
has a built in function.

There are some actually:

PJ_IDECL(pj_str_t*) pj_strdup_with_null(pj_pool_t *pool,
pj_str_t *dst,
const pj_str_t *src);

What is *pool? Is it available when I use the pjsua API?

Pool is pjlib's memory pool, it's the memory allocation strategy
that is used by all libraries. See this for more info:
http://www.pjsip.org/pjlib/docs/html/group__PJ__POOL__GROUP.htm

I'm not at all surprised if you didn't know this, as pjsua API is
presented without the need to use pool. But if you need it, you can
have your own with pjsua_pool_create()/pj_pool_release().

-benny

klaus

Klaus Darilion wrote: > Benny Prijono wrote: >> P.J. Cast. wrote: >>> If you are using C++, you can simply do: >>> std::string mystring(pj_str.ptr, pjs_str.slen); >>> >>> If you are using C, you could write a simply little >>> function easily enough. Though, I'm not sure if pjsip >>> has a built in function. >> There are some actually: >> >> PJ_IDECL(pj_str_t*) pj_strdup_with_null(pj_pool_t *pool, >> pj_str_t *dst, >> const pj_str_t *src); > > What is *pool? Is it available when I use the pjsua API? Pool is pjlib's memory pool, it's the memory allocation strategy that is used by all libraries. See this for more info: http://www.pjsip.org/pjlib/docs/html/group__PJ__POOL__GROUP.htm I'm not at all surprised if you didn't know this, as pjsua API is presented without the need to use pool. But if you need it, you can have your own with pjsua_pool_create()/pj_pool_release(). -benny > klaus