Changes between Initial Version and Version 1 of URI_Escaping

Apr 5, 2012 4:05:58 PM (7 years ago)



  • URI_Escaping

    v1 v1  
     3<!-- MAIN TABLE START --> 
     4<table border=0 width="90%" align="center"><tr><td> 
     7= URI Escaping = 
     9The general rules about escaping and unescaping reserved characters in SIP message elements in PJSIP are as follows: 
     11 1. For incoming message, escaped strings will be unescaped by the parser before they are placed in the corresponding elements. For example, an element containing this URI: 
     12 {{{ 
     14 }}} 
     15 will result in the following values to be placed in the {{{pjsip_sip_uri}}} structure: 
     16 {{{ 
     17pjsip_sip_uri.user = pj_str("good user"); = pj_str(""); 
     19 }}} 
     20 Notice the value of the ''user'' field in the example above. 
     21 2. A {{{pjsip_sip_uri}}} that is passed around within the application MUST contain unescaped values. Keep this in mind especially when constructing a {{{pjsip_sip_uri}}} structure manually. The library will take care about escaping them when needed, i.e. before transmitting the message to the wire. Hence using the example above, when setting the ''user'' field, put "good user" instead of "good%20user" as the value. 
     22 3. URI string that is passed around within the application MUST be escaped. Keep this in mind when constructing any URI strings. If you can't control the characters that go into an URI (for example, the username character set is not strictly enforced), then you need to construct a {{{pjsip_sip_uri}}} and ''print'' it in order to get a properly escaped URI. For example: 
     23 {{{ 
     24pjsip_sip_uri sip_uri; 
     25char buf[PJSIP_MAX_URL_SIZE]; 
     27pjsip_sip_uri_init(&sip_uri, PJ_FALSE); 
     28sip_uri.user = pj_str("good user"); = pj_str(""); 
     31len = pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR,  
     32                      &sip_uri, buf, sizeof(buf)); 
     33buf[len] = '\0'; 
     35// buf now contains "" 
     36 }}} 
     41<!-- MAIN TABLE END -->