Asterisk-13-Function_PJSIP_HEADER_29394907.html 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Asterisk Project : Asterisk 13 Function_PJSIP_HEADER</title>
  5. <link rel="stylesheet" href="styles/site.css" type="text/css" />
  6. <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
  7. </head>
  8. <body class="theme-default aui-theme-default">
  9. <div id="page">
  10. <div id="main" class="aui-page-panel">
  11. <div id="main-header">
  12. <div id="breadcrumb-section">
  13. <ol id="breadcrumbs">
  14. <li class="first">
  15. <span><a href="index.html">Asterisk Project</a></span>
  16. </li>
  17. <li>
  18. <span><a href="Asterisk-13-Command-Reference_29394274.html">Asterisk 13 Command Reference</a></span>
  19. </li>
  20. <li>
  21. <span><a href="Asterisk-13-Dialplan-Functions_29394287.html">Asterisk 13 Dialplan Functions</a></span>
  22. </li>
  23. </ol>
  24. </div>
  25. <h1 id="title-heading" class="pagetitle">
  26. <span id="title-text">
  27. Asterisk Project : Asterisk 13 Function_PJSIP_HEADER
  28. </span>
  29. </h1>
  30. </div>
  31. <div id="content" class="view">
  32. <div class="page-metadata">
  33. Created by <span class='author'> wikibot</span> on Aug 08, 2014
  34. </div>
  35. <div id="main-content" class="wiki-content group">
  36. <h1 id="Asterisk13Function_PJSIP_HEADER-PJSIP_HEADER()">PJSIP_HEADER()</h1>
  37. <h3 id="Asterisk13Function_PJSIP_HEADER-Synopsis">Synopsis</h3>
  38. <p>Gets, adds, updates or removes the specified SIP header from a PJSIP session.</p>
  39. <h3 id="Asterisk13Function_PJSIP_HEADER-Description">Description</h3>
  40. <p>Examples:</p>
  41. <p>;</p>
  42. <p>; Set 'somevar' to the value of the 'From' header.</p>
  43. <p>exten =&gt; 1,1,Set(somevar=${PJSIP_HEADER(read,From)})</p>
  44. <p>;</p>
  45. <p>; Set 'via2' to the value of the 2nd 'Via' header.</p>
  46. <p>exten =&gt; 1,1,Set(via2=${PJSIP_HEADER(read,Via,2)})</p>
  47. <p>;</p>
  48. <p>; Add an 'X-Myheader' header with the value of 'myvalue'.</p>
  49. <p>exten =&gt; 1,1,Set(PJSIP_HEADER(add,X-MyHeader)=myvalue)</p>
  50. <p>;</p>
  51. <p>; Add an 'X-Myheader' header with an empty value.</p>
  52. <p>exten =&gt; 1,1,Set(PJSIP_HEADER(add,X-MyHeader)=)</p>
  53. <p>;</p>
  54. <p>; Update the value of the header named 'X-Myheader' to 'newvalue'.</p>
  55. <p>; 'X-Myheader' must already exist or the call will fail.</p>
  56. <p>exten =&gt; 1,1,Set(PJSIP_HEADER(update,X-MyHeader)=newvalue)</p>
  57. <p>;</p>
  58. <p>; Remove all headers whose names exactly match 'X-MyHeader'.</p>
  59. <p>exten =&gt; 1,1,Set(PJSIP_HEADER(remove,X-MyHeader)=)</p>
  60. <p>;</p>
  61. <p>; Remove all headers that begin with 'X-My'.</p>
  62. <p>exten =&gt; 1,1,Set(PJSIP_HEADER(remove,X-My*)=)</p>
  63. <p>;</p>
  64. <p>; Remove all previously added headers.</p>
  65. <p>exten =&gt; 1,1,Set(PJSIP_HEADER(remove,*)=)</p>
  66. <p>;</p>
  67. <div class="aui-message hint shadowed information-macro">
  68. <p class="title">Note</p>
  69. <span class="aui-icon icon-hint">Icon</span>
  70. <div class="message-content">
  71. <p>The <code>remove</code> action can be called by reading <strong>or</strong> writing PJSIP_HEADER.</p>
  72. <p>;</p>
  73. <p>; Display the number of headers removed</p>
  74. <p>exten =&gt; 1,1,Verbose( Removed ${PJSIP_HEADER(remove,X-MyHeader)} headers)</p>
  75. <p>;</p>
  76. <p>; Set a variable to the number of headers removed</p>
  77. <p>exten =&gt; 1,1,Set(count=${PJSIP_HEADER(remove,X-MyHeader)})</p>
  78. <p>;</p>
  79. <p>; Just remove them ignoring any count</p>
  80. <p>exten =&gt; 1,1,Set(=${PJSIP_HEADER(remove,X-MyHeader)})</p>
  81. <p>exten =&gt; 1,1,Set(PJSIP_HEADER(remove,X-MyHeader)=)</p>
  82. <p>;</p>
  83. </div>
  84. </div>
  85. <div class="aui-message hint shadowed information-macro">
  86. <p class="title">Note</p>
  87. <span class="aui-icon icon-hint">Icon</span>
  88. <div class="message-content">
  89. <p>If you call PJSIP_HEADER in a normal dialplan context you'll be operating on the <strong>caller's (incoming)</strong> channel which may not be what you want. To operate on the <strong>callee's (outgoing)</strong> channel call PJSIP_HEADER in a pre-dial handler.</p>
  90. <p>Example:</p>
  91. <p>;</p>
  92. <p>[handler]</p>
  93. <p>exten =&gt; addheader,1,Set(PJSIP_HEADER(add,X-MyHeader)=myvalue)</p>
  94. <p>exten =&gt; addheader,2,Set(PJSIP_HEADER(add,X-MyHeader2)=myvalue2)</p>
  95. <p>;</p>
  96. <p>[somecontext]</p>
  97. <p>exten =&gt; 1,1,Dial(PJSIP/${EXTEN},,b(handler^addheader^1))</p>
  98. <p>;</p>
  99. </div>
  100. </div>
  101. <h3 id="Asterisk13Function_PJSIP_HEADER-Syntax">Syntax</h3>
  102. <div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
  103. <pre>PJSIP_HEADER(action,name[,number])</pre>
  104. </div></div>
  105. <h5 id="Asterisk13Function_PJSIP_HEADER-Arguments">Arguments</h5>
  106. <ul>
  107. <li><code>action</code>
  108. <ul>
  109. <li><code>read</code> - Returns instance <em>number</em> of header <em>name</em>.</li>
  110. <li><code>add</code> - Adds a new header <em>name</em> to this session.</li>
  111. <li><code>update</code> - Updates instance <em>number</em> of header <em>name</em> to a new value. The header must already exist.</li>
  112. <li><code>remove</code> - Removes all instances of previously added headers whose names match <em>name</em>. A {<strong>} may be appended to <em>name</em> to remove all headers *beginning with</strong> <em>name</em>. <em>name</em> may be set to a single {<strong>} to clear *all</strong> previously added headers. In all cases, the number of headers actually removed is returned.</li>
  113. </ul>
  114. </li>
  115. <li><code>name</code> - The name of the header.</li>
  116. <li><code>number</code> - If there's more than 1 header with the same name, this specifies which header to read or update. If not specified, defaults to <code>1</code> meaning the first matching header. Not valid for <code>add</code> or <code>remove</code>.</li>
  117. </ul>
  118. <h3 id="Asterisk13Function_PJSIP_HEADER-SeeAlso">See Also</h3>
  119. <h3 id="Asterisk13Function_PJSIP_HEADER-ImportVersion">Import Version</h3>
  120. <p>This documentation was imported from Asterisk Version SVN-branch-13-r420538</p>
  121. </div>
  122. </div> </div>
  123. <div id="footer">
  124. <section class="footer-body">
  125. <p>Document generated by Confluence on Aug 11, 2014 13:47</p>
  126. </section>
  127. </div>
  128. </div> </body>
  129. </html>