Guest User

asterisk-1.6.2.10-called-rpid.patch

a guest
Jun 20th, 2011
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.62 KB | None | 0 0
  1. --- asterisk-1.6.2.10/channels/chan_sip.c.orig 2010-07-24 19:24:31.000000000 -0400
  2. +++ asterisk-1.6.2.10/channels/chan_sip.c 2010-07-24 19:24:20.000000000 -0400
  3. @@ -331,6 +331,25 @@
  4. <para>Always returns <literal>0</literal>.</para>
  5. </description>
  6. </application>
  7. + <application name="SIPCalledRPID" language="en_US">
  8. + <synopsis>
  9. + Set the RPID header for Called Party Identification
  10. + </synopsis>
  11. + <syntax>
  12. + <parameter name="Name" required="true" />
  13. + <parameter name="Number" required="true" />
  14. + </syntax>
  15. + <description>
  16. + <para>Sets the Remote-Party-ID header information to be sent to a call
  17. + originator on further progress through this extension. Many SIP
  18. + phones use this header to display the name and number of the party
  19. + which has been called from the telephone.</para>
  20. + <para>This progress may be updated throughout the call progress whenever
  21. + Asterisk sends a new 180 Ringing, 183 Call Progress, or 200 OK response
  22. + to the calling channel.</para>
  23. + <para>Always returns <literal>0</literal>.</para>
  24. + </description>
  25. + </application>
  26. <function name="SIP_HEADER" language="en_US">
  27. <synopsis>
  28. Gets the specified SIP header.
  29. @@ -1552,6 +1571,7 @@
  30. int method; /*!< SIP method that opened this dialog */
  31. AST_DECLARE_STRING_FIELDS(
  32. AST_STRING_FIELD(callid); /*!< Global CallID */
  33. + AST_STRING_FIELD(calledid); /*!< Called Party RPID Header String */
  34. AST_STRING_FIELD(randdata); /*!< Random data */
  35. AST_STRING_FIELD(accountcode); /*!< Account code */
  36. AST_STRING_FIELD(realm); /*!< Authorization realm */
  37. @@ -2279,6 +2299,7 @@
  38. static int transmit_response_using_temp(ast_string_field callid, struct sockaddr_in *sin, int useglobal_nat, const int intended_method, const struct sip_request *req, const char *msg);
  39. static int transmit_response(struct sip_pvt *p, const char *msg, const struct sip_request *req);
  40. static int transmit_response_reliable(struct sip_pvt *p, const char *msg, const struct sip_request *req);
  41. +static int transmit_response_with_calledrpid(struct sip_pvt *p, char *msg, struct sip_request *req);
  42. static int transmit_response_with_date(struct sip_pvt *p, const char *msg, const struct sip_request *req);
  43. static int transmit_response_with_sdp(struct sip_pvt *p, const char *msg, const struct sip_request *req, enum xmittype reliable, int oldsdp);
  44. static int transmit_response_with_unsupported(struct sip_pvt *p, const char *msg, const struct sip_request *req, const char *unsupported);
  45. @@ -6531,8 +6552,12 @@
  46. p->invitestate = INV_EARLY_MEDIA;
  47. if (!ast_test_flag(&p->flags[0], SIP_PROGRESS_SENT) ||
  48. (ast_test_flag(&p->flags[0], SIP_PROG_INBAND) == SIP_PROG_INBAND_NEVER)) {
  49. - /* Send 180 ringing if out-of-band seems reasonable */
  50. - transmit_provisional_response(p, "180 Ringing", &p->initreq, 0);
  51. + /* Send 180 ringing if out-of-band seems reasonable */
  52. + if (!ast_strlen_zero(p->calledid)) {
  53. + transmit_response_with_calledrpid(p, "180 Ringing", &p->initreq);
  54. + } else {
  55. + transmit_provisional_response(p, "180 Ringing", &p->initreq, 0);
  56. + }
  57. ast_set_flag(&p->flags[0], SIP_RINGING);
  58. if (ast_test_flag(&p->flags[0], SIP_PROG_INBAND) != SIP_PROG_INBAND_YES)
  59. break;
  60. @@ -9795,6 +9820,15 @@
  61. add_header(req, "Date", tmpdat);
  62. }
  63.  
  64. +/*! \brief transmit_response_with_calledrpid: Transmit response, no retransmits */
  65. +static int transmit_response_with_calledrpid(struct sip_pvt *p, char *msg, struct sip_request *req)
  66. +{
  67. + struct sip_request resp;
  68. + respprep(&resp, p, msg, req);
  69. + add_header(&resp, "Remote-Party-ID", p->calledid);
  70. + return send_response(p, &resp, XMIT_UNRELIABLE, 0);
  71. +}
  72. +
  73. /*! \brief Append date and content length before transmitting response */
  74. static int transmit_response_with_date(struct sip_pvt *p, const char *msg, const struct sip_request *req)
  75. {
  76. @@ -10498,6 +10532,9 @@
  77. return -1;
  78. }
  79. respprep(&resp, p, msg, req);
  80. + if (!ast_strlen_zero(p->calledid)) {
  81. + add_header(&resp, "Remote-Party-ID", p->calledid);
  82. + }
  83. if (p->rtp) {
  84. if (!p->autoframing && !ast_test_flag(&p->flags[0], SIP_OUTGOING)) {
  85. ast_debug(1, "Setting framing from config on incoming call\n");
  86. @@ -25532,6 +25569,7 @@
  87. static char *app_dtmfmode = "SIPDtmfMode";
  88. static char *app_sipaddheader = "SIPAddHeader";
  89. static char *app_sipremoveheader = "SIPRemoveHeader";
  90. +static char *app_sipcalledrpid = "SIPCalledRPID";
  91.  
  92. /*! \brief Set the DTMFmode for an outbound SIP call (application) */
  93. static int sip_dtmfmode(struct ast_channel *chan, void *data)
  94. @@ -25662,6 +25700,46 @@
  95. return 0;
  96. }
  97.  
  98. +/*! \brief Set the value of the RPID header for called party identification */
  99. +static int sip_calledrpid(struct ast_channel *chan, void *data)
  100. +{
  101. + struct sip_pvt *p;
  102. + AST_DECLARE_APP_ARGS(args,
  103. + AST_APP_ARG(name);
  104. + AST_APP_ARG(number);
  105. + );
  106. + const char *fromdomain;
  107. + char rpid[256];
  108. +
  109. + if (ast_strlen_zero(data)) {
  110. + ast_log(LOG_WARNING, "This application requires the arguments: Name, Number\n");
  111. + return 0;
  112. + }
  113. +
  114. + AST_STANDARD_APP_ARGS(args, data);
  115. +
  116. + if (ast_strlen_zero(args.name) || ast_strlen_zero(args.number)) {
  117. + ast_log(LOG_WARNING, "One or more arguments are invalid: Name, Number\n");
  118. + return 0;
  119. + }
  120. +
  121. + ast_channel_lock(chan);
  122. +
  123. + if (chan->tech != &sip_tech) {
  124. + ast_log(LOG_WARNING, "This application is only useful for calls originated from SIP UA's\n");
  125. + ast_channel_unlock(chan);
  126. + return 0;
  127. + }
  128. +
  129. + p = chan->tech_pvt;
  130. + fromdomain = S_OR(p->fromdomain, ast_inet_ntoa(p->ourip.sin_addr));
  131. + sprintf(rpid, "\"%s\" <sip:%s@%s>;party=called;id-type=subscriber;screen=yes;privacy=off", args.name, args.number, fromdomain);
  132. + ast_string_field_set(p, calledid, rpid);
  133. +
  134. + ast_channel_unlock(chan);
  135. + return 0;
  136. +}
  137. +
  138. /*! \brief Transfer call before connect with a 302 redirect
  139. \note Called by the transfer() dialplan application through the sip_transfer()
  140. pbx interface function if the call is in ringing state
  141. @@ -25947,6 +26025,7 @@
  142. ast_register_application_xml(app_dtmfmode, sip_dtmfmode);
  143. ast_register_application_xml(app_sipaddheader, sip_addheader);
  144. ast_register_application_xml(app_sipremoveheader, sip_removeheader);
  145. + ast_register_application_xml(app_sipcalledrpid, sip_calledrpid);
  146.  
  147. /* Register dialplan functions */
  148. ast_custom_function_register(&sip_header_function);
  149. @@ -26010,6 +26089,7 @@
  150. ast_unregister_application(app_dtmfmode);
  151. ast_unregister_application(app_sipaddheader);
  152. ast_unregister_application(app_sipremoveheader);
  153. + ast_unregister_application(app_sipcalledrpid);
  154.  
  155. /* Unregister CLI commands */
  156. ast_cli_unregister_multiple(cli_sip, ARRAY_LEN(cli_sip));
Advertisement
Add Comment
Please, Sign In to add comment