Asterisk - The Open Source Telephony Project  18.5.0
Macros | Functions
sip_utils.h File Reference

sip utils header file More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define IS_SIP_TECH(t)   ((t) == &sip_tech || (t) == &sip_tech_info)
 

Functions

const char * comedia_string (struct ast_flags *flags)
 Return a string describing the comedia value for the given flags. More...
 
const char * find_closing_quote (const char *start, const char *lim)
 Locate closing quote in a string, skipping escaped quotes. optionally with a limit on the search. start must be past the first quote. More...
 
const char * force_rport_string (struct ast_flags *flags)
 Return a string describing the force_rport value for the given flags. More...
 
const char * hangup_cause2sip (int cause)
 Convert Asterisk hangup causes to SIP codes. More...
 
int hangup_sip2cause (int cause)
 Convert SIP hangup causes to Asterisk hangup causes. More...
 
unsigned int port_str2int (const char *pt, unsigned int standard)
 converts ascii port to int representation. More...
 

Detailed Description

sip utils header file

Definition in file sip_utils.h.

Macro Definition Documentation

◆ IS_SIP_TECH

#define IS_SIP_TECH (   t)    ((t) == &sip_tech || (t) == &sip_tech_info)

Function Documentation

◆ comedia_string()

const char* comedia_string ( struct ast_flags flags)

Return a string describing the comedia value for the given flags.

Definition at line 43 of file channels/sip/utils.c.

References AST_CLI_YESNO, ast_test_flag, SIP_PAGE2_SYMMETRICRTP, and SIP_PAGE3_NAT_AUTO_COMEDIA.

Referenced by _sip_show_peer(), _sip_show_peers_one(), and sip_show_settings().

44 {
45  if (ast_test_flag(&flags[2], SIP_PAGE3_NAT_AUTO_COMEDIA)) {
46  return ast_test_flag(&flags[1], SIP_PAGE2_SYMMETRICRTP) ? "Auto (Yes)" : "Auto (No)";
47  }
49 }
#define ast_test_flag(p, flag)
Definition: utils.h:63
#define SIP_PAGE2_SYMMETRICRTP
Definition: sip.h:327
#define SIP_PAGE3_NAT_AUTO_COMEDIA
Definition: sip.h:387
#define AST_CLI_YESNO(x)
Return Yes or No depending on the argument.
Definition: cli.h:71

◆ find_closing_quote()

const char* find_closing_quote ( const char *  start,
const char *  lim 
)

Locate closing quote in a string, skipping escaped quotes. optionally with a limit on the search. start must be past the first quote.

Definition at line 5074 of file chan_sip.c.

Referenced by get_comma(), get_in_brackets_const(), get_in_brackets_full(), and parse_moved_contact().

5075 {
5076  char last_char = '\0';
5077  const char *s;
5078  for (s = start; *s && s != lim; last_char = *s++) {
5079  if (*s == '"' && last_char != '\\')
5080  break;
5081  }
5082  return s;
5083 }

◆ force_rport_string()

const char* force_rport_string ( struct ast_flags flags)

Return a string describing the force_rport value for the given flags.

Definition at line 35 of file channels/sip/utils.c.

References AST_CLI_YESNO, ast_test_flag, SIP_NAT_FORCE_RPORT, and SIP_PAGE3_NAT_AUTO_RPORT.

Referenced by _sip_show_peer(), _sip_show_peers_one(), sip_show_channel(), and sip_show_settings().

36 {
37  if (ast_test_flag(&flags[2], SIP_PAGE3_NAT_AUTO_RPORT)) {
38  return ast_test_flag(&flags[0], SIP_NAT_FORCE_RPORT) ? "Auto (Yes)" : "Auto (No)";
39  }
41 }
#define ast_test_flag(p, flag)
Definition: utils.h:63
#define SIP_NAT_FORCE_RPORT
Definition: sip.h:283
#define SIP_PAGE3_NAT_AUTO_RPORT
Definition: sip.h:386
#define AST_CLI_YESNO(x)
Return Yes or No depending on the argument.
Definition: cli.h:71

◆ hangup_cause2sip()

const char* hangup_cause2sip ( int  cause)

Convert Asterisk hangup causes to SIP codes.

 Possible values from causes.h
        AST_CAUSE_NOTDEFINED    AST_CAUSE_NORMAL        AST_CAUSE_BUSY
        AST_CAUSE_FAILURE       AST_CAUSE_CONGESTION    AST_CAUSE_UNALLOCATED

   In addition to these, a lot of PRI codes is defined in causes.h
   ...should we take care of them too ?

   Quote RFC 3398

   ISUP Cause value                        SIP response
   ----------------                        ------------
   1  unallocated number                   404 Not Found
   2  no route to network                  404 Not found
   3  no route to destination              404 Not found
   16 normal call clearing                 --- (*)
   17 user busy                            486 Busy here
   18 no user responding                   408 Request Timeout
   19 no answer from the user              480 Temporarily unavailable
   20 subscriber absent                    480 Temporarily unavailable
   21 call rejected                        403 Forbidden (+)
   22 number changed (w/o diagnostic)      410 Gone
   22 number changed (w/ diagnostic)       301 Moved Permanently
   23 redirection to new destination       410 Gone
   26 non-selected user clearing           404 Not Found (=)
   27 destination out of order             502 Bad Gateway
   28 address incomplete                   484 Address incomplete
   29 facility rejected                    501 Not implemented
   31 normal unspecified                   480 Temporarily unavailable

Definition at line 7108 of file chan_sip.c.

References AST_CAUSE_BEARERCAPABILITY_NOTAVAIL, AST_CAUSE_CALL_REJECTED, AST_CAUSE_CHAN_NOT_IMPLEMENTED, AST_CAUSE_CONGESTION, AST_CAUSE_DESTINATION_OUT_OF_ORDER, AST_CAUSE_FACILITY_REJECTED, AST_CAUSE_FAILURE, AST_CAUSE_INTERWORKING, AST_CAUSE_INVALID_NUMBER_FORMAT, AST_CAUSE_NO_ANSWER, AST_CAUSE_NO_ROUTE_DESTINATION, AST_CAUSE_NO_ROUTE_TRANSIT_NET, AST_CAUSE_NO_USER_RESPONSE, AST_CAUSE_NORMAL_UNSPECIFIED, AST_CAUSE_NOTDEFINED, AST_CAUSE_NUMBER_CHANGED, AST_CAUSE_SWITCH_CONGESTION, AST_CAUSE_UNALLOCATED, AST_CAUSE_UNREGISTERED, AST_CAUSE_USER_BUSY, ast_debug, and NULL.

Referenced by sip_hangup().

7109 {
7110  switch (cause) {
7111  case AST_CAUSE_UNALLOCATED: /* 1 */
7112  case AST_CAUSE_NO_ROUTE_DESTINATION: /* 3 IAX2: Can't find extension in context */
7113  case AST_CAUSE_NO_ROUTE_TRANSIT_NET: /* 2 */
7114  return "404 Not Found";
7115  case AST_CAUSE_CONGESTION: /* 34 */
7116  case AST_CAUSE_SWITCH_CONGESTION: /* 42 */
7117  return "503 Service Unavailable";
7118  case AST_CAUSE_NO_USER_RESPONSE: /* 18 */
7119  return "408 Request Timeout";
7120  case AST_CAUSE_NO_ANSWER: /* 19 */
7121  case AST_CAUSE_UNREGISTERED: /* 20 */
7122  return "480 Temporarily unavailable";
7123  case AST_CAUSE_CALL_REJECTED: /* 21 */
7124  return "403 Forbidden";
7125  case AST_CAUSE_NUMBER_CHANGED: /* 22 */
7126  return "410 Gone";
7127  case AST_CAUSE_NORMAL_UNSPECIFIED: /* 31 */
7128  return "480 Temporarily unavailable";
7130  return "484 Address incomplete";
7131  case AST_CAUSE_USER_BUSY:
7132  return "486 Busy here";
7133  case AST_CAUSE_FAILURE:
7134  return "500 Server internal failure";
7135  case AST_CAUSE_FACILITY_REJECTED: /* 29 */
7136  return "501 Not Implemented";
7138  return "503 Service Unavailable";
7139  /* Used in chan_iax2 */
7141  return "502 Bad Gateway";
7142  case AST_CAUSE_BEARERCAPABILITY_NOTAVAIL: /* Can't find codec to connect to host */
7143  return "488 Not Acceptable Here";
7144  case AST_CAUSE_INTERWORKING: /* Unspecified Interworking issues */
7145  return "500 Network error";
7146 
7147  case AST_CAUSE_NOTDEFINED:
7148  default:
7149  ast_debug(1, "AST hangup cause %d (no match found in SIP)\n", cause);
7150  return NULL;
7151  }
7152 
7153  /* Never reached */
7154  return 0;
7155 }
#define AST_CAUSE_SWITCH_CONGESTION
Definition: causes.h:122
#define AST_CAUSE_UNALLOCATED
Definition: causes.h:97
#define AST_CAUSE_FACILITY_REJECTED
Definition: causes.h:116
#define NULL
Definition: resample.c:96
#define AST_CAUSE_NO_USER_RESPONSE
Definition: causes.h:107
#define AST_CAUSE_INVALID_NUMBER_FORMAT
Definition: causes.h:115
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define AST_CAUSE_NO_ROUTE_TRANSIT_NET
Definition: causes.h:98
#define AST_CAUSE_CHAN_NOT_IMPLEMENTED
Definition: causes.h:131
#define AST_CAUSE_NO_ANSWER
Definition: causes.h:108
#define AST_CAUSE_NOTDEFINED
Definition: causes.h:154
#define AST_CAUSE_DESTINATION_OUT_OF_ORDER
Definition: causes.h:114
#define AST_CAUSE_FAILURE
Definition: causes.h:149
#define AST_CAUSE_NORMAL_UNSPECIFIED
Definition: causes.h:118
#define AST_CAUSE_UNREGISTERED
Definition: causes.h:153
#define AST_CAUSE_NUMBER_CHANGED
Definition: causes.h:111
#define AST_CAUSE_INTERWORKING
Definition: causes.h:145
#define AST_CAUSE_NO_ROUTE_DESTINATION
Definition: causes.h:99
#define AST_CAUSE_USER_BUSY
Definition: causes.h:106
#define AST_CAUSE_CALL_REJECTED
Definition: causes.h:110
#define AST_CAUSE_BEARERCAPABILITY_NOTAVAIL
Definition: causes.h:129
#define AST_CAUSE_CONGESTION
Definition: causes.h:152

◆ hangup_sip2cause()

int hangup_sip2cause ( int  cause)

Convert SIP hangup causes to Asterisk hangup causes.

Definition at line 6986 of file chan_sip.c.

References AST_CAUSE_BEARERCAPABILITY_NOTAVAIL, AST_CAUSE_BUSY, AST_CAUSE_CALL_REJECTED, AST_CAUSE_CONGESTION, AST_CAUSE_DESTINATION_OUT_OF_ORDER, AST_CAUSE_FACILITY_REJECTED, AST_CAUSE_FAILURE, AST_CAUSE_INTERWORKING, AST_CAUSE_INVALID_NUMBER_FORMAT, AST_CAUSE_NO_ANSWER, AST_CAUSE_NO_ROUTE_DESTINATION, AST_CAUSE_NO_USER_RESPONSE, AST_CAUSE_NORMAL, AST_CAUSE_NORMAL_TEMPORARY_FAILURE, AST_CAUSE_NUMBER_CHANGED, AST_CAUSE_RECOVERY_ON_TIMER_EXPIRE, AST_CAUSE_UNALLOCATED, and AST_CAUSE_USER_BUSY.

Referenced by __transmit_response(), handle_incoming(), handle_response(), and handle_response_invite().

6987 {
6988  /* Possible values taken from causes.h */
6989 
6990  switch(cause) {
6991  case 401: /* Unauthorized */
6992  return AST_CAUSE_CALL_REJECTED;
6993  case 403: /* Not found */
6994  return AST_CAUSE_CALL_REJECTED;
6995  case 404: /* Not found */
6996  return AST_CAUSE_UNALLOCATED;
6997  case 405: /* Method not allowed */
6998  return AST_CAUSE_INTERWORKING;
6999  case 407: /* Proxy authentication required */
7000  return AST_CAUSE_CALL_REJECTED;
7001  case 408: /* No reaction */
7003  case 409: /* Conflict */
7005  case 410: /* Gone */
7006  return AST_CAUSE_NUMBER_CHANGED;
7007  case 411: /* Length required */
7008  return AST_CAUSE_INTERWORKING;
7009  case 413: /* Request entity too large */
7010  return AST_CAUSE_INTERWORKING;
7011  case 414: /* Request URI too large */
7012  return AST_CAUSE_INTERWORKING;
7013  case 415: /* Unsupported media type */
7014  return AST_CAUSE_INTERWORKING;
7015  case 420: /* Bad extension */
7017  case 480: /* No answer */
7018  return AST_CAUSE_NO_ANSWER;
7019  case 481: /* No answer */
7020  return AST_CAUSE_INTERWORKING;
7021  case 482: /* Loop detected */
7022  return AST_CAUSE_INTERWORKING;
7023  case 483: /* Too many hops */
7024  return AST_CAUSE_NO_ANSWER;
7025  case 484: /* Address incomplete */
7027  case 485: /* Ambiguous */
7028  return AST_CAUSE_UNALLOCATED;
7029  case 486: /* Busy everywhere */
7030  return AST_CAUSE_BUSY;
7031  case 487: /* Request terminated */
7032  return AST_CAUSE_INTERWORKING;
7033  case 488: /* No codecs approved */
7035  case 491: /* Request pending */
7036  return AST_CAUSE_INTERWORKING;
7037  case 493: /* Undecipherable */
7038  return AST_CAUSE_INTERWORKING;
7039  case 500: /* Server internal failure */
7040  return AST_CAUSE_FAILURE;
7041  case 501: /* Call rejected */
7043  case 502:
7045  case 503: /* Service unavailable */
7046  return AST_CAUSE_CONGESTION;
7047  case 504: /* Gateway timeout */
7049  case 505: /* SIP version not supported */
7050  return AST_CAUSE_INTERWORKING;
7051  case 600: /* Busy everywhere */
7052  return AST_CAUSE_USER_BUSY;
7053  case 603: /* Decline */
7054  return AST_CAUSE_CALL_REJECTED;
7055  case 604: /* Does not exist anywhere */
7056  return AST_CAUSE_UNALLOCATED;
7057  case 606: /* Not acceptable */
7059  default:
7060  if (cause < 500 && cause >= 400) {
7061  /* 4xx class error that is unknown - someting wrong with our request */
7062  return AST_CAUSE_INTERWORKING;
7063  } else if (cause < 600 && cause >= 500) {
7064  /* 5xx class error - problem in the remote end */
7065  return AST_CAUSE_CONGESTION;
7066  } else if (cause < 700 && cause >= 600) {
7067  /* 6xx - global errors in the 4xx class */
7068  return AST_CAUSE_INTERWORKING;
7069  }
7070  return AST_CAUSE_NORMAL;
7071  }
7072  /* Never reached */
7073  return 0;
7074 }
#define AST_CAUSE_NORMAL_TEMPORARY_FAILURE
Definition: causes.h:121
#define AST_CAUSE_UNALLOCATED
Definition: causes.h:97
#define AST_CAUSE_FACILITY_REJECTED
Definition: causes.h:116
#define AST_CAUSE_RECOVERY_ON_TIMER_EXPIRE
Definition: causes.h:142
#define AST_CAUSE_NO_USER_RESPONSE
Definition: causes.h:107
#define AST_CAUSE_INVALID_NUMBER_FORMAT
Definition: causes.h:115
#define AST_CAUSE_NO_ANSWER
Definition: causes.h:108
#define AST_CAUSE_DESTINATION_OUT_OF_ORDER
Definition: causes.h:114
#define AST_CAUSE_NORMAL
Definition: causes.h:150
#define AST_CAUSE_FAILURE
Definition: causes.h:149
#define AST_CAUSE_NUMBER_CHANGED
Definition: causes.h:111
#define AST_CAUSE_INTERWORKING
Definition: causes.h:145
#define AST_CAUSE_NO_ROUTE_DESTINATION
Definition: causes.h:99
#define AST_CAUSE_USER_BUSY
Definition: causes.h:106
#define AST_CAUSE_BUSY
Definition: causes.h:148
#define AST_CAUSE_CALL_REJECTED
Definition: causes.h:110
#define AST_CAUSE_BEARERCAPABILITY_NOTAVAIL
Definition: causes.h:129
#define AST_CAUSE_CONGESTION
Definition: causes.h:152

◆ port_str2int()

unsigned int port_str2int ( const char *  pt,
unsigned int  standard 
)

converts ascii port to int representation.

  • pt[in] string that contains a port.
  • standard[in] port to return in case the port string input is NULL or if there is a parsing error.
Returns
An integer port representation.

converts ascii port to int representation.

Definition at line 3538 of file chan_sip.c.

References ast_strlen_zero.

Referenced by build_peer(), reload_config(), and sip_parse_register_line().

3539 {
3540  int port = standard;
3541  if (ast_strlen_zero(pt) || (sscanf(pt, "%30d", &port) != 1) || (port < 1) || (port > 65535)) {
3542  port = standard;
3543  }
3544 
3545  return port;
3546 }
#define ast_strlen_zero(foo)
Definition: strings.h:52