Copy from a stl string to a pj_str_t struct

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We just use the method:
pj_cstr(&somepjstr, stdstr.c_str());

Works pretty good to do what Benny suggests, only uses
the predefined method. I guess the method also does a
check for null pointer to set length to 0 in that
case.

HTH

--- Benny Prijono <bennylp at pjsip.org> wrote:

> On 2/7/08, Dan <dan.aberg at keystream.se> wrote:
> >
> >
> > > I've figured out this one, but it feels a bit
> clumsy
> > >
> > >
> > >
> > >       char* tmpUsername = new
> char[username.size()];
> > >
> > >       strcpy(tmpUsername, username.c_str());
> > >
> > >
> > >
> > >       pjsua_acc_config pjsuaAccountConfig;
> > >
> > > pjsua_acc_config_default(&pjsuaAccountConfig);
> > >
> > >       pjsuaAccountConfig.id = pj_str(tmpUserId);
> > >
> > >
> > >
> > > Any other ideas?
> > >
> >
> > How about:
> >         pjsuaAccountConfig.id = pj_strdup3 (pool,
> username.c_str());
> >
> 
> Or, since acc_config is a temporary object which
> will not be accessed
> by pjsip after pjsua_acc_add() is called, we can
> probably get away
> with this:
> 
>   pjsuaAccountConfig.id.ptr =
> (char*)username.c_str();
>   pjsuaAccountConfig.id.slen = username.size();
> 
> or
> 
>  pj_strset(&pjsuaAccountConfig.id,
> (char*)username.c_str(), username.size());
> 
> Yeah that involves an ugly casting to remove the
> const, but it saves
> us from using the pool.
> 
> cheers,
>  -benny
> 
> 
> > /Dan
> >
> 
> _______________________________________________
> Visit our blog: http://blog.pjsip.org
> 
> pjsip mailing list
> pjsip at lists.pjsip.org
>
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
> 



      ____________________________________________________________________________________
Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  http://tools.search.yahoo.com/newsearch/category.php?category=shopping



[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux