Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.57 KB | None | 0 0
  1. /*! \brief Transfer call before connect with a 302 redirect
  2. \note   Called by the transfer() dialplan application through the sip_transfer()
  3.         pbx interface function if the call is in ringing state
  4. \todo   Fix this function so that we wait for reply to the REFER and
  5.         react to errors, denials or other issues the other end might have.
  6.  */
  7. static int sip_sipredirect(struct sip_pvt *p, const char *dest)
  8. {
  9.         char *cdest;
  10.         char *extension, *domain;
  11.  
  12.         cdest = ast_strdupa(dest);
  13.  
  14.         extension = strsep(&cdest, "@");
  15.         domain = cdest;
  16.         if (ast_strlen_zero(extension)) {
  17.                 ast_log(LOG_ERROR, "Missing mandatory argument: extension\n");
  18.                 return 0;
  19.         }
  20.  
  21.         /* we'll issue the redirect message here */
  22.         if (!domain) {
  23.                 char *local_to_header;
  24.                 char to_header[256];
  25.  
  26.                 ast_copy_string(to_header, get_header(&p->initreq, "To"), sizeof(to_header));
  27.                 if (ast_strlen_zero(to_header)) {
  28.                         ast_log(LOG_ERROR, "Cannot retrieve the 'To' header from the original SIP request!\n");
  29.                         return 0;
  30.                 }
  31.                 if (((local_to_header = strcasestr(to_header, "sip:")) || (local_to_header = strcasestr(to_header, "sips:")))
  32.                         && (local_to_header = strchr(local_to_header, '@'))) {
  33.                         char ldomain[256];
  34.  
  35.                         memset(ldomain, 0, sizeof(ldomain));
  36.                         local_to_header++;
  37.                         /* This is okey because lhost and lport are as big as tmp */
  38.                         sscanf(local_to_header, "%256[^<>; ]", ldomain);
  39.                         if (ast_strlen_zero(ldomain)) {
  40.                                 ast_log(LOG_ERROR, "Can't find the host address\n");
  41.                                 return 0;
  42.                         }
  43.                         domain = ast_strdupa(ldomain);
  44.                 }
  45.         }
  46.  
  47.         add_diversion(&p->initreq, p);
  48.         ast_string_field_build(p, our_contact, "Transfer <sip:%s@%s>", extension, domain);
  49.         transmit_response_reliable(p, "302 Moved Temporarily", &p->initreq);
  50.  
  51.         sip_scheddestroy(p, SIP_TRANS_TIMEOUT); /* Make sure we stop send this reply. */
  52.         sip_alreadygone(p);
  53.  
  54.         if (p->owner) {
  55.                 enum ast_control_transfer message = AST_TRANSFER_SUCCESS;
  56.                 ast_queue_control_data(p->owner, AST_CONTROL_TRANSFER, &message, sizeof(message));
  57.         }
  58.         /* hangup here */
  59.         return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement