Changes between Initial Version and Version 1 of URI_Escaping


Ignore:
Timestamp:
Apr 5, 2012 4:05:58 PM (7 years ago)
Author:
bennylp
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • URI_Escaping

    v1 v1  
     1{{{ 
     2#!html 
     3<!-- MAIN TABLE START --> 
     4<table border=0 width="90%" align="center"><tr><td> 
     5}}} 
     6 
     7= URI Escaping = 
     8 
     9The general rules about escaping and unescaping reserved characters in SIP message elements in PJSIP are as follows: 
     10 
     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 {{{ 
     13sip:good%20user@example.com 
     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"); 
     18pjsip_sip_uri.host = pj_str("example.com"); 
     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]; 
     26 
     27pjsip_sip_uri_init(&sip_uri, PJ_FALSE); 
     28sip_uri.user = pj_str("good user"); 
     29sip_uri.host = pj_str("example.com"); 
     30 
     31len = pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR,  
     32                      &sip_uri, buf, sizeof(buf)); 
     33buf[len] = '\0'; 
     34 
     35// buf now contains "sip:good%20user@example.com" 
     36 }}} 
     37 
     38 
     39{{{ 
     40#!html 
     41<!-- MAIN TABLE END --> 
     42</td></tr></table> 
     43}}} 
     44