Review Board 1.7.16


Use the correct IP address in the c and o sdp lines when using an externally mapped IP address

Review Request #566 - Created March 16, 2010 and submitted

ebroad
/trunk
17044
Reviewers
asterisk-dev
Asterisk
The issue stems from a call to ast_rtp_instance_get_local_address() in chan_sip.c in get_our_media_address(). ast_rtp_instance_get_local_address() will always return the internal IP address of the Asterisk machine, which could pose a problem when using NAT.

A simple solution would be to override {v,t}sin->sin_addr in get_our_media_address() with p->ourip.sin_addr.s_addr if it is different(which is what the attached diff does), though I don't know what that might break.

Edit 1: This patch short-circuits some logic later on in get_our_media_address(). ast_rtp_instance_get_local_address() does exactly as the function name suggests, it gets the local address of the machine the Asterisk is running on, which is bad for NAT setups. Should we be calling this in get_our_media_address() or instead just use p->ourip? or should we try to stick with letting the RTP engine decide, and modifying ast_rtp_instance_get_local_address() to return our externally mapped IP when appropriate, which would break from what the function is supposed to do? Comments anyone? 
Applied to trunk, compiled, fax and voice calls made to and from Asterisk successfully.

Changes between revision 1 and 2

1 2 3 4
1 2 3 4

  1. /trunk/channels/chan_sip.c: Loading...
/trunk/channels/chan_sip.c
Diff Revision 1 Diff Revision 2
[20] 258 lines
[+20] [+] ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
259
#include "asterisk/translate.h"
259
#include "asterisk/translate.h"
260
#include "asterisk/ast_version.h"
260
#include "asterisk/ast_version.h"
261
#include "asterisk/event.h"
261
#include "asterisk/event.h"
262
#include "asterisk/stun.h"
262
#include "asterisk/stun.h"
263
#include "asterisk/cel.h"
263
#include "asterisk/cel.h"

    
   
264
#include "asterisk/aoc.h"
264
#include "sip/include/sip.h"
265
#include "sip/include/sip.h"
265
#include "sip/include/globals.h"
266
#include "sip/include/globals.h"
266
#include "sip/include/config_parser.h"
267
#include "sip/include/config_parser.h"
267
#include "sip/include/reqresp_parser.h"
268
#include "sip/include/reqresp_parser.h"
268
#include "sip/include/sip_utils.h"
269
#include "sip/include/sip_utils.h"

    
   
270
#include "asterisk/ccss.h"

    
   
271
#include "asterisk/xml.h"
269
#include "sip/include/dialog.h"
272
#include "sip/include/dialog.h"
270
#include "sip/include/dialplan_functions.h"
273
#include "sip/include/dialplan_functions.h"
271

    
   
274

   
272
/*** DOCUMENTATION
275
/*** DOCUMENTATION
273
	<application name="SIPDtmfMode" language="en_US">
276
	<application name="SIPDtmfMode" language="en_US">
[+20] [20] 349 lines
[+20] [+] static const struct cfsip_methods {
623
	{ SIP_SUBSCRIBE, NO_RTP, "SUBSCRIBE",CAN_CREATE_DIALOG },
626
	{ SIP_SUBSCRIBE, NO_RTP, "SUBSCRIBE",CAN_CREATE_DIALOG },
624
	{ SIP_MESSAGE,   NO_RTP, "MESSAGE",  CAN_CREATE_DIALOG },
627
	{ SIP_MESSAGE,   NO_RTP, "MESSAGE",  CAN_CREATE_DIALOG },
625
	{ SIP_UPDATE,    NO_RTP, "UPDATE",   CAN_NOT_CREATE_DIALOG },
628
	{ SIP_UPDATE,    NO_RTP, "UPDATE",   CAN_NOT_CREATE_DIALOG },
626
	{ SIP_INFO,      NO_RTP, "INFO",     CAN_NOT_CREATE_DIALOG },
629
	{ SIP_INFO,      NO_RTP, "INFO",     CAN_NOT_CREATE_DIALOG },
627
	{ SIP_CANCEL,    NO_RTP, "CANCEL",   CAN_NOT_CREATE_DIALOG },
630
	{ SIP_CANCEL,    NO_RTP, "CANCEL",   CAN_NOT_CREATE_DIALOG },
628
	{ SIP_PUBLISH,   NO_RTP, "PUBLISH",  CAN_CREATE_DIALOG_UNSUPPORTED_METHOD },
631
	{ SIP_PUBLISH,   NO_RTP, "PUBLISH",  CAN_CREATE_DIALOG },
629
	{ SIP_PING,      NO_RTP, "PING",     CAN_CREATE_DIALOG_UNSUPPORTED_METHOD }
632
	{ SIP_PING,      NO_RTP, "PING",     CAN_CREATE_DIALOG_UNSUPPORTED_METHOD }
630
};
633
};
631

    
   
634

   
632
/*! \brief List of well-known SIP options. If we get this in a require,
635
/*! \brief List of well-known SIP options. If we get this in a require,
633
   we should check the list and answer accordingly. */
636
   we should check the list and answer accordingly. */
[+20] [20] 81 lines
[+20] [+] static const struct sip_reasons {
715
/*@{*/
718
/*@{*/
716
static char default_language[MAX_LANGUAGE];      /*!< Default language setting for new channels */
719
static char default_language[MAX_LANGUAGE];      /*!< Default language setting for new channels */
717
static char default_callerid[AST_MAX_EXTENSION]; /*!< Default caller ID for sip messages */
720
static char default_callerid[AST_MAX_EXTENSION]; /*!< Default caller ID for sip messages */
718
static char default_mwi_from[80];                /*!< Default caller ID for MWI updates */
721
static char default_mwi_from[80];                /*!< Default caller ID for MWI updates */
719
static char default_fromdomain[AST_MAX_EXTENSION]; /*!< Default domain on outound messages */
722
static char default_fromdomain[AST_MAX_EXTENSION]; /*!< Default domain on outound messages */

    
   
723
static int default_fromdomainport;                 /*!< Default domain port on outbound messages */
720
static char default_notifymime[AST_MAX_EXTENSION]; /*!< Default MIME media type for MWI notify messages */
724
static char default_notifymime[AST_MAX_EXTENSION]; /*!< Default MIME media type for MWI notify messages */
721
static char default_vmexten[AST_MAX_EXTENSION];    /*!< Default From Username on MWI updates */
725
static char default_vmexten[AST_MAX_EXTENSION];    /*!< Default From Username on MWI updates */
722
static int default_qualify;                        /*!< Default Qualify= setting */
726
static int default_qualify;                        /*!< Default Qualify= setting */
723
static char default_mohinterpret[MAX_MUSICCLASS];  /*!< Global setting for moh class to use when put on hold */
727
static char default_mohinterpret[MAX_MUSICCLASS];  /*!< Global setting for moh class to use when put on hold */
724
static char default_mohsuggest[MAX_MUSICCLASS];    /*!< Global setting for moh class to suggest when putting
728
static char default_mohsuggest[MAX_MUSICCLASS];    /*!< Global setting for moh class to suggest when putting
[+20] [20] 57 lines
[+20] [+] static enum st_refresher global_st_refresher; /*!< Session-Timer refresher */
782
static int global_max_se;                     /*!< Highest threshold for session refresh interval */
786
static int global_max_se;                     /*!< Highest threshold for session refresh interval */
783

    
   
787

   
784
static int global_dynamic_exclude_static = 0; /*!< Exclude static peers from contact registrations */
788
static int global_dynamic_exclude_static = 0; /*!< Exclude static peers from contact registrations */
785
/*@}*/
789
/*@}*/
786

    
   
790

   

    
   
791
/*!

    
   
792
 * We use libxml2 in order to parse XML that may appear in the body of a SIP message. Currently,

    
   
793
 * the only usage is for parsing PIDF bodies of incoming PUBLISH requests in the call-completion

    
   
794
 * event package. This variable is set at module load time and may be checked at runtime to determine

    
   
795
 * if XML parsing support was found.

    
   
796
 */

    
   
797
static int can_parse_xml;

    
   
798

   
787
/*! \name Object counters @{
799
/*! \name Object counters @{
788
 *  \bug These counters are not handled in a thread-safe way ast_atomic_fetchadd_int()
800
 *  \bug These counters are not handled in a thread-safe way ast_atomic_fetchadd_int()
789
 *  should be used to modify these values. */
801
 *  should be used to modify these values. */
790
static int speerobjs = 0;     /*!< Static peers */
802
static int speerobjs = 0;     /*!< Static peers */
791
static int rpeerobjs = 0;     /*!< Realtime peers */
803
static int rpeerobjs = 0;     /*!< Realtime peers */
792
static int apeerobjs = 0;     /*!< Autocreated peer objects */
804
static int apeerobjs = 0;     /*!< Autocreated peer objects */
793
static int regobjs = 0;       /*!< Registry objects */
805
static int regobjs = 0;       /*!< Registry objects */
794
/* }@ */
806
/* }@ */
795

    
   
807

   
796
static struct ast_flags global_flags[2] = {{0}};  /*!< global SIP_ flags */
808
static struct ast_flags global_flags[3] = {{0}};  /*!< global SIP_ flags */
797
static int global_t38_maxdatagram;                /*!< global T.38 FaxMaxDatagram override */
809
static int global_t38_maxdatagram;                /*!< global T.38 FaxMaxDatagram override */
798

    
   
810

   
799
static char used_context[AST_MAX_CONTEXT];        /*!< name of automatically created context for unloading */
811
static char used_context[AST_MAX_CONTEXT];        /*!< name of automatically created context for unloading */
800

    
   
812

   
801
AST_MUTEX_DEFINE_STATIC(netlock);
813
AST_MUTEX_DEFINE_STATIC(netlock);
[+20] [20] 47 lines
[+20] [+] static const int HASH_PEER_SIZE = 17;
849
#else
861
#else
850
static const int HASH_PEER_SIZE = 563;	/*!< Size of peer hash table, prime number preferred! */
862
static const int HASH_PEER_SIZE = 563;	/*!< Size of peer hash table, prime number preferred! */
851
static const int HASH_DIALOG_SIZE = 563;
863
static const int HASH_DIALOG_SIZE = 563;
852
#endif
864
#endif
853

    
   
865

   

    
   
866
static const struct {

    
   
867
	enum ast_cc_service_type service;

    
   
868
	const char *service_string;

    
   
869
} sip_cc_service_map [] = {

    
   
870
	[AST_CC_NONE] = { AST_CC_NONE, "" },

    
   
871
	[AST_CC_CCBS] = { AST_CC_CCBS, "BS" },

    
   
872
	[AST_CC_CCNR] = { AST_CC_CCNR, "NR" },

    
   
873
	[AST_CC_CCNL] = { AST_CC_CCNL, "NL" },

    
   
874
};

    
   
875

   

    
   
876
static enum ast_cc_service_type service_string_to_service_type(const char * const service_string)

    
   
877
{

    
   
878
	enum ast_cc_service_type service;

    
   
879
	for (service = AST_CC_CCBS; service <= AST_CC_CCNL; ++service) {

    
   
880
		if (!strcasecmp(service_string, sip_cc_service_map[service].service_string)) {

    
   
881
			return service;

    
   
882
		}

    
   
883
	}

    
   
884
	return AST_CC_NONE;

    
   
885
}

    
   
886

   

    
   
887
static const struct {

    
   
888
	enum sip_cc_notify_state state;

    
   
889
	const char *state_string;

    
   
890
} sip_cc_notify_state_map [] = {

    
   
891
	[CC_QUEUED] = {CC_QUEUED, "cc-state: queued"},

    
   
892
	[CC_READY] = {CC_READY, "cc-state: ready"},

    
   
893
};

    
   
894

   

    
   
895
AST_LIST_HEAD_STATIC(epa_static_data_list, epa_backend);

    
   
896

   

    
   
897
static int sip_epa_register(const struct epa_static_data *static_data)

    
   
898
{

    
   
899
	struct epa_backend *backend = ast_calloc(1, sizeof(*backend));

    
   
900

   

    
   
901
	if (!backend) {

    
   
902
		return -1;

    
   
903
	}

    
   
904

   

    
   
905
	backend->static_data = static_data;

    
   
906

   

    
   
907
	AST_LIST_LOCK(&epa_static_data_list);

    
   
908
	AST_LIST_INSERT_TAIL(&epa_static_data_list, backend, next);

    
   
909
	AST_LIST_UNLOCK(&epa_static_data_list);

    
   
910
	return 0;

    
   
911
}

    
   
912

   

    
   
913
static void cc_handle_publish_error(struct sip_pvt *pvt, const int resp, struct sip_request *req, struct sip_epa_entry *epa_entry);

    
   
914

   

    
   
915
static void cc_epa_destructor(void *data)

    
   
916
{

    
   
917
	struct sip_epa_entry *epa_entry = data;

    
   
918
	struct cc_epa_entry *cc_entry = epa_entry->instance_data;

    
   
919
	ast_free(cc_entry);

    
   
920
}

    
   
921

   

    
   
922
static const struct epa_static_data cc_epa_static_data  = {

    
   
923
	.event = CALL_COMPLETION,

    
   
924
	.name = "call-completion",

    
   
925
	.handle_error = cc_handle_publish_error,

    
   
926
	.destructor = cc_epa_destructor,

    
   
927
};

    
   
928

   

    
   
929
static const struct epa_static_data *find_static_data(const char * const event_package)

    
   
930
{

    
   
931
	const struct epa_backend *backend = NULL;

    
   
932

   

    
   
933
	AST_LIST_LOCK(&epa_static_data_list);

    
   
934
	AST_LIST_TRAVERSE(&epa_static_data_list, backend, next) {

    
   
935
		if (!strcmp(backend->static_data->name, event_package)) {

    
   
936
			break;

    
   
937
		}

    
   
938
	}

    
   
939
	AST_LIST_UNLOCK(&epa_static_data_list);

    
   
940
	return backend ? backend->static_data : NULL;

    
   
941
}

    
   
942

   

    
   
943
static struct sip_epa_entry *create_epa_entry (const char * const event_package, const char * const destination)

    
   
944
{

    
   
945
	struct sip_epa_entry *epa_entry;

    
   
946
	const struct epa_static_data *static_data;

    
   
947

   

    
   
948
	if (!(static_data = find_static_data(event_package))) {

    
   
949
		return NULL;

    
   
950
	}

    
   
951

   

    
   
952
	if (!(epa_entry = ao2_t_alloc(sizeof(*epa_entry), static_data->destructor, "Allocate new EPA entry"))) {

    
   
953
		return NULL;

    
   
954
	}

    
   
955

   

    
   
956
	epa_entry->static_data = static_data;

    
   
957
	ast_copy_string(epa_entry->destination, destination, sizeof(epa_entry->destination));

    
   
958
	return epa_entry;

    
   
959
}

    
   
960

   

    
   
961
/*!

    
   
962
 * Used to create new entity IDs by ESCs.

    
   
963
 */

    
   
964
static int esc_etag_counter;

    
   
965
static const int DEFAULT_PUBLISH_EXPIRES = 3600;

    
   
966

   

    
   
967
#ifdef HAVE_LIBXML2

    
   
968
static int cc_esc_publish_handler(struct sip_pvt *pvt, struct sip_request *req, struct event_state_compositor *esc, struct sip_esc_entry *esc_entry);

    
   
969

   

    
   
970
static const struct sip_esc_publish_callbacks cc_esc_publish_callbacks = {

    
   
971
	.initial_handler = cc_esc_publish_handler,

    
   
972
	.modify_handler = cc_esc_publish_handler,

    
   
973
};

    
   
974
#endif

    
   
975

   

    
   
976
/*!

    
   
977
 * \brief The Event State Compositors

    
   
978
 *

    
   
979
 * An Event State Compositor is an entity which

    
   
980
 * accepts PUBLISH requests and acts appropriately

    
   
981
 * based on these requests.

    
   
982
 *

    
   
983
 * The actual event_state_compositor structure is simply

    
   
984
 * an ao2_container of sip_esc_entrys. When an incoming

    
   
985
 * PUBLISH is received, we can match the appropriate sip_esc_entry

    
   
986
 * using the entity ID of the incoming PUBLISH.

    
   
987
 */

    
   
988
static struct event_state_compositor {

    
   
989
	enum subscriptiontype event;

    
   
990
	const char * name;

    
   
991
	const struct sip_esc_publish_callbacks *callbacks;

    
   
992
	struct ao2_container *compositor;

    
   
993
} event_state_compositors [] = {

    
   
994
#ifdef HAVE_LIBXML2

    
   
995
	{CALL_COMPLETION, "call-completion", &cc_esc_publish_callbacks},

    
   
996
#endif

    
   
997
};

    
   
998

   

    
   
999
static const int ESC_MAX_BUCKETS = 37;

    
   
1000

   

    
   
1001
static void esc_entry_destructor(void *obj)

    
   
1002
{

    
   
1003
	struct sip_esc_entry *esc_entry = obj;

    
   
1004
	if (esc_entry->sched_id > -1) {

    
   
1005
		AST_SCHED_DEL(sched, esc_entry->sched_id);

    
   
1006
	}

    
   
1007
}

    
   
1008

   

    
   
1009
static int esc_hash_fn(const void *obj, const int flags)

    
   
1010
{

    
   
1011
	const struct sip_esc_entry *entry = obj;

    
   
1012
	return ast_str_hash(entry->entity_tag);

    
   
1013
}

    
   
1014

   

    
   
1015
static int esc_cmp_fn(void *obj, void *arg, int flags)

    
   
1016
{

    
   
1017
	struct sip_esc_entry *entry1 = obj;

    
   
1018
	struct sip_esc_entry *entry2 = arg;

    
   
1019

   

    
   
1020
	return (!strcmp(entry1->entity_tag, entry2->entity_tag)) ? (CMP_MATCH | CMP_STOP) : 0;

    
   
1021
}

    
   
1022

   

    
   
1023
static struct event_state_compositor *get_esc(const char * const event_package) {

    
   
1024
	int i;

    
   
1025
	for (i = 0; i < ARRAY_LEN(event_state_compositors); i++) {

    
   
1026
		if (!strcasecmp(event_package, event_state_compositors[i].name)) {

    
   
1027
			return &event_state_compositors[i];

    
   
1028
		}

    
   
1029
	}

    
   
1030
	return NULL;

    
   
1031
}

    
   
1032

   

    
   
1033
static struct sip_esc_entry *get_esc_entry(const char * entity_tag, struct event_state_compositor *esc) {

    
   
1034
	struct sip_esc_entry *entry;

    
   
1035
	struct sip_esc_entry finder;

    
   
1036

   

    
   
1037
	ast_copy_string(finder.entity_tag, entity_tag, sizeof(finder.entity_tag));

    
   
1038

   

    
   
1039
	entry = ao2_find(esc->compositor, &finder, OBJ_POINTER);

    
   
1040

   

    
   
1041
	return entry;

    
   
1042
}

    
   
1043

   

    
   
1044
static int publish_expire(const void *data)

    
   
1045
{

    
   
1046
	struct sip_esc_entry *esc_entry = (struct sip_esc_entry *) data;

    
   
1047
	struct event_state_compositor *esc = get_esc(esc_entry->event);

    
   
1048

   

    
   
1049
	ast_assert(esc != NULL);

    
   
1050

   

    
   
1051
	ao2_unlink(esc->compositor, esc_entry);

    
   
1052
	ao2_ref(esc_entry, -1);

    
   
1053
	return 0;

    
   
1054
}

    
   
1055

   

    
   
1056
static void create_new_sip_etag(struct sip_esc_entry *esc_entry, int is_linked)

    
   
1057
{

    
   
1058
	int new_etag = ast_atomic_fetchadd_int(&esc_etag_counter, +1);

    
   
1059
	struct event_state_compositor *esc = get_esc(esc_entry->event);

    
   
1060

   

    
   
1061
	ast_assert(esc != NULL);

    
   
1062
	if (is_linked) {

    
   
1063
		ao2_unlink(esc->compositor, esc_entry);

    
   
1064
	}

    
   
1065
	snprintf(esc_entry->entity_tag, sizeof(esc_entry->entity_tag), "%d", new_etag);

    
   
1066
	ao2_link(esc->compositor, esc_entry);

    
   
1067
}

    
   
1068

   

    
   
1069
static struct sip_esc_entry *create_esc_entry(struct event_state_compositor *esc, struct sip_request *req, const int expires)

    
   
1070
{

    
   
1071
	struct sip_esc_entry *esc_entry;

    
   
1072
	int expires_ms;

    
   
1073

   

    
   
1074
	if (!(esc_entry = ao2_alloc(sizeof(*esc_entry), esc_entry_destructor))) {

    
   
1075
		return NULL;

    
   
1076
	}

    
   
1077

   

    
   
1078
	esc_entry->event = esc->name;

    
   
1079

   

    
   
1080
	expires_ms = expires * 1000;

    
   
1081
	/* Bump refcount for scheduler */

    
   
1082
	ao2_ref(esc_entry, +1);

    
   
1083
	esc_entry->sched_id = ast_sched_add(sched, expires_ms, publish_expire, esc_entry);

    
   
1084

   

    
   
1085
	/* Note: This links the esc_entry into the ESC properly */

    
   
1086
	create_new_sip_etag(esc_entry, 0);

    
   
1087

   

    
   
1088
	return esc_entry;

    
   
1089
}

    
   
1090

   

    
   
1091
static int initialize_escs(void)

    
   
1092
{

    
   
1093
	int i, res = 0;

    
   
1094
	for (i = 0; i < ARRAY_LEN(event_state_compositors); i++) {

    
   
1095
		if (!((event_state_compositors[i].compositor) =

    
   
1096
					ao2_container_alloc(ESC_MAX_BUCKETS, esc_hash_fn, esc_cmp_fn))) {

    
   
1097
			res = -1;

    
   
1098
		}

    
   
1099
	}

    
   
1100
	return res;

    
   
1101
}

    
   
1102

   

    
   
1103
static void destroy_escs(void)

    
   
1104
{

    
   
1105
	int i;

    
   
1106
	for (i = 0; i < ARRAY_LEN(event_state_compositors); i++) {

    
   
1107
		ao2_ref(event_state_compositors[i].compositor, -1);

    
   
1108
	}

    
   
1109
}

    
   
1110

   
854
/*! \brief
1111
/*! \brief
855
 * Here we implement the container for dialogs (sip_pvt), defining
1112
 * Here we implement the container for dialogs (sip_pvt), defining
856
 * generic wrapper functions to ease the transition from the current
1113
 * generic wrapper functions to ease the transition from the current
857
 * implementation (a single linked list) to a different container.
1114
 * implementation (a single linked list) to a different container.
858
 * In addition to a reference to the container, we need functions to lock/unlock
1115
 * In addition to a reference to the container, we need functions to lock/unlock
[+20] [20] 140 lines
[+20] [+] static int sip_standard_port(enum sip_transport type, int port);
999

    
   
1256

   
1000
/*--- Transmitting responses and requests */
1257
/*--- Transmitting responses and requests */
1001
static int sipsock_read(int *id, int fd, short events, void *ignore);
1258
static int sipsock_read(int *id, int fd, short events, void *ignore);
1002
static int __sip_xmit(struct sip_pvt *p, struct ast_str *data, int len);
1259
static int __sip_xmit(struct sip_pvt *p, struct ast_str *data, int len);
1003
static int __sip_reliable_xmit(struct sip_pvt *p, int seqno, int resp, struct ast_str *data, int len, int fatal, int sipmethod);
1260
static int __sip_reliable_xmit(struct sip_pvt *p, int seqno, int resp, struct ast_str *data, int len, int fatal, int sipmethod);

    
   
1261
static void add_cc_call_info_to_response(struct sip_pvt *p, struct sip_request *resp);
1004
static int __transmit_response(struct sip_pvt *p, const char *msg, const struct sip_request *req, enum xmittype reliable);
1262
static int __transmit_response(struct sip_pvt *p, const char *msg, const struct sip_request *req, enum xmittype reliable);
1005
static int retrans_pkt(const void *data);
1263
static int retrans_pkt(const void *data);
1006
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);
1264
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);
1007
static int transmit_response(struct sip_pvt *p, const char *msg, const struct sip_request *req);
1265
static int transmit_response(struct sip_pvt *p, const char *msg, const struct sip_request *req);
1008
static int transmit_response_reliable(struct sip_pvt *p, const char *msg, const struct sip_request *req);
1266
static int transmit_response_reliable(struct sip_pvt *p, const char *msg, const struct sip_request *req);
[+20] [20] 4 lines
[+20] [+] static int transmit_response_with_unsupported(struct sip_pvt *p, const char *msg, const struct sip_request *req, const char *unsupported);
1013
static int transmit_provisional_response(struct sip_pvt *p, const char *msg, const struct sip_request *req, int with_sdp);
1271
static int transmit_provisional_response(struct sip_pvt *p, const char *msg, const struct sip_request *req, int with_sdp);
1014
static int transmit_response_with_allow(struct sip_pvt *p, const char *msg, const struct sip_request *req, enum xmittype reliable);
1272
static int transmit_response_with_allow(struct sip_pvt *p, const char *msg, const struct sip_request *req, enum xmittype reliable);
1015
static void transmit_fake_auth_response(struct sip_pvt *p, int sipmethod, struct sip_request *req, enum xmittype reliable);
1273
static void transmit_fake_auth_response(struct sip_pvt *p, int sipmethod, struct sip_request *req, enum xmittype reliable);
1016
static int transmit_request(struct sip_pvt *p, int sipmethod, int inc, enum xmittype reliable, int newbranch);
1274
static int transmit_request(struct sip_pvt *p, int sipmethod, int inc, enum xmittype reliable, int newbranch);
1017
static int transmit_request_with_auth(struct sip_pvt *p, int sipmethod, int seqno, enum xmittype reliable, int newbranch);
1275
static int transmit_request_with_auth(struct sip_pvt *p, int sipmethod, int seqno, enum xmittype reliable, int newbranch);
1018
static int transmit_invite(struct sip_pvt *p, int sipmethod, int sdp, int init);
1276
static int transmit_publish(struct sip_epa_entry *epa_entry, enum sip_publish_type publish_type, const char * const explicit_uri);

    
   
1277
static int transmit_invite(struct sip_pvt *p, int sipmethod, int sdp, int init, const char * const explicit_uri);
1019
static int transmit_reinvite_with_sdp(struct sip_pvt *p, int t38version, int oldsdp);
1278
static int transmit_reinvite_with_sdp(struct sip_pvt *p, int t38version, int oldsdp);

    
   
1279
static int transmit_info_with_aoc(struct sip_pvt *p, struct ast_aoc_decoded *decoded);
1020
static int transmit_info_with_digit(struct sip_pvt *p, const char digit, unsigned int duration);
1280
static int transmit_info_with_digit(struct sip_pvt *p, const char digit, unsigned int duration);
1021
static int transmit_info_with_vidupdate(struct sip_pvt *p);
1281
static int transmit_info_with_vidupdate(struct sip_pvt *p);
1022
static int transmit_message_with_text(struct sip_pvt *p, const char *text);
1282
static int transmit_message_with_text(struct sip_pvt *p, const char *text);
1023
static int transmit_refer(struct sip_pvt *p, const char *dest);
1283
static int transmit_refer(struct sip_pvt *p, const char *dest);
1024
static int transmit_notify_with_mwi(struct sip_pvt *p, int newmsgs, int oldmsgs, const char *vmexten);
1284
static int transmit_notify_with_mwi(struct sip_pvt *p, int newmsgs, int oldmsgs, const char *vmexten);
1025
static int transmit_notify_with_sipfrag(struct sip_pvt *p, int cseq, char *message, int terminate);
1285
static int transmit_notify_with_sipfrag(struct sip_pvt *p, int cseq, char *message, int terminate);

    
   
1286
static int transmit_cc_notify(struct ast_cc_agent *agent, struct sip_pvt *subscription, enum sip_cc_notify_state state);
1026
static int transmit_register(struct sip_registry *r, int sipmethod, const char *auth, const char *authheader);
1287
static int transmit_register(struct sip_registry *r, int sipmethod, const char *auth, const char *authheader);
1027
static int send_response(struct sip_pvt *p, struct sip_request *req, enum xmittype reliable, int seqno);
1288
static int send_response(struct sip_pvt *p, struct sip_request *req, enum xmittype reliable, int seqno);
1028
static int send_request(struct sip_pvt *p, struct sip_request *req, enum xmittype reliable, int seqno);
1289
static int send_request(struct sip_pvt *p, struct sip_request *req, enum xmittype reliable, int seqno);
1029
static void copy_request(struct sip_request *dst, const struct sip_request *src);
1290
static void copy_request(struct sip_request *dst, const struct sip_request *src);
1030
static void receive_message(struct sip_pvt *p, struct sip_request *req);
1291
static void receive_message(struct sip_pvt *p, struct sip_request *req);
[+20] [20] 203 lines
[+20] [+] static int get_refer_info(struct sip_pvt *transferer, struct sip_request *outgoing_req);
1234
static int parse_ok_contact(struct sip_pvt *pvt, struct sip_request *req);
1495
static int parse_ok_contact(struct sip_pvt *pvt, struct sip_request *req);
1235
static int set_address_from_contact(struct sip_pvt *pvt);
1496
static int set_address_from_contact(struct sip_pvt *pvt);
1236
static void check_via(struct sip_pvt *p, struct sip_request *req);
1497
static void check_via(struct sip_pvt *p, struct sip_request *req);
1237
static int get_rpid(struct sip_pvt *p, struct sip_request *oreq);
1498
static int get_rpid(struct sip_pvt *p, struct sip_request *oreq);
1238
static int get_rdnis(struct sip_pvt *p, struct sip_request *oreq, char **name, char **number, int *reason);
1499
static int get_rdnis(struct sip_pvt *p, struct sip_request *oreq, char **name, char **number, int *reason);
1239
static int get_destination(struct sip_pvt *p, struct sip_request *oreq);
1500
static int get_destination(struct sip_pvt *p, struct sip_request *oreq, int *cc_recall_core_id);
1240
static int get_msg_text(char *buf, int len, struct sip_request *req, int addnewline);
1501
static int get_msg_text(char *buf, int len, struct sip_request *req, int addnewline);
1241
static int transmit_state_notify(struct sip_pvt *p, int state, int full, int timeout);
1502
static int transmit_state_notify(struct sip_pvt *p, int state, int full, int timeout);
1242
static void update_connectedline(struct sip_pvt *p, const void *data, size_t datalen);
1503
static void update_connectedline(struct sip_pvt *p, const void *data, size_t datalen);
1243
static void update_redirecting(struct sip_pvt *p, const void *data, size_t datalen);
1504
static void update_redirecting(struct sip_pvt *p, const void *data, size_t datalen);
1244
static void change_redirecting_information(struct sip_pvt *p, struct sip_request *req, struct ast_party_redirecting *redirecting, int set_call_forward);
1505
static void change_redirecting_information(struct sip_pvt *p, struct sip_request *req, struct ast_party_redirecting *redirecting, int set_call_forward);
[+20] [20] 6 lines
[+20] [+] static void *_sip_tcp_helper_thread(struct sip_pvt *pvt, struct ast_tcptls_session_instance *tcptls_session);
1251

    
   
1512

   
1252
/*--- Constructing requests and responses */
1513
/*--- Constructing requests and responses */
1253
static void initialize_initreq(struct sip_pvt *p, struct sip_request *req);
1514
static void initialize_initreq(struct sip_pvt *p, struct sip_request *req);
1254
static int init_req(struct sip_request *req, int sipmethod, const char *recip);
1515
static int init_req(struct sip_request *req, int sipmethod, const char *recip);
1255
static int reqprep(struct sip_request *req, struct sip_pvt *p, int sipmethod, int seqno, int newbranch);
1516
static int reqprep(struct sip_request *req, struct sip_pvt *p, int sipmethod, int seqno, int newbranch);
1256
static void initreqprep(struct sip_request *req, struct sip_pvt *p, int sipmethod);
1517
static void initreqprep(struct sip_request *req, struct sip_pvt *p, int sipmethod, const char * const explicit_uri);
1257
static int init_resp(struct sip_request *resp, const char *msg);
1518
static int init_resp(struct sip_request *resp, const char *msg);
1258
static inline int resp_needs_contact(const char *msg, enum sipmethod method);
1519
static inline int resp_needs_contact(const char *msg, enum sipmethod method);
1259
static int respprep(struct sip_request *resp, struct sip_pvt *p, const char *msg, const struct sip_request *req);
1520
static int respprep(struct sip_request *resp, struct sip_pvt *p, const char *msg, const struct sip_request *req);
1260
static const struct sockaddr_in *sip_real_dst(const struct sip_pvt *p);
1521
static const struct sockaddr_in *sip_real_dst(const struct sip_pvt *p);
1261
static void build_via(struct sip_pvt *p);
1522
static void build_via(struct sip_pvt *p);
1262
static int create_addr_from_peer(struct sip_pvt *r, struct sip_peer *peer);
1523
static int create_addr_from_peer(struct sip_pvt *r, struct sip_peer *peer);
1263
static int create_addr(struct sip_pvt *dialog, const char *opeer, struct sockaddr_in *sin, int newdialog);
1524
static int create_addr(struct sip_pvt *dialog, const char *opeer, struct sockaddr_in *sin, int newdialog, struct sockaddr_in *remote_address);
1264
static char *generate_random_string(char *buf, size_t size);
1525
static char *generate_random_string(char *buf, size_t size);
1265
static void build_callid_pvt(struct sip_pvt *pvt);
1526
static void build_callid_pvt(struct sip_pvt *pvt);
1266
static void build_callid_registry(struct sip_registry *reg, struct in_addr ourip, const char *fromdomain);
1527
static void build_callid_registry(struct sip_registry *reg, struct in_addr ourip, const char *fromdomain);
1267
static void make_our_tag(char *tagbuf, size_t len);
1528
static void make_our_tag(char *tagbuf, size_t len);
1268
static int add_header(struct sip_request *req, const char *var, const char *value);
1529
static int add_header(struct sip_request *req, const char *var, const char *value);
[+20] [20] 26 lines
[+20] [+] static void handle_request_info(struct sip_pvt *p, struct sip_request *req);
1295
static int handle_invite_replaces(struct sip_pvt *p, struct sip_request *req, int debug, int seqno, struct sockaddr_in *sin, int *nounlock);
1556
static int handle_invite_replaces(struct sip_pvt *p, struct sip_request *req, int debug, int seqno, struct sockaddr_in *sin, int *nounlock);
1296
static int handle_request_notify(struct sip_pvt *p, struct sip_request *req, struct sockaddr_in *sin, int seqno, const char *e);
1557
static int handle_request_notify(struct sip_pvt *p, struct sip_request *req, struct sockaddr_in *sin, int seqno, const char *e);
1297
static int local_attended_transfer(struct sip_pvt *transferer, struct sip_dual *current, struct sip_request *req, int seqno, int *nounlock);
1558
static int local_attended_transfer(struct sip_pvt *transferer, struct sip_dual *current, struct sip_request *req, int seqno, int *nounlock);
1298

    
   
1559

   
1299
/*------Response handling functions */
1560
/*------Response handling functions */

    
   
1561
static void handle_response_publish(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);
1300
static void handle_response_invite(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);
1562
static void handle_response_invite(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);
1301
static void handle_response_notify(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);
1563
static void handle_response_notify(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);
1302
static void handle_response_refer(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);
1564
static void handle_response_refer(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);
1303
static void handle_response_subscribe(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);
1565
static void handle_response_subscribe(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);
1304
static int handle_response_register(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);
1566
static int handle_response_register(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);
[+20] [20] 65 lines
[+20] [+] const struct ast_channel_tech sip_tech = {
1370
 * The struct is initialized just before registering the channel driver,
1632
 * The struct is initialized just before registering the channel driver,
1371
 * and is for use with channels using SIP INFO DTMF.
1633
 * and is for use with channels using SIP INFO DTMF.
1372
 */
1634
 */
1373
struct ast_channel_tech sip_tech_info;
1635
struct ast_channel_tech sip_tech_info;
1374

    
   
1636

   

    
   
1637
static int sip_cc_agent_init(struct ast_cc_agent *agent, struct ast_channel *chan);

    
   
1638
static int sip_cc_agent_start_offer_timer(struct ast_cc_agent *agent);

    
   
1639
static int sip_cc_agent_stop_offer_timer(struct ast_cc_agent *agent);

    
   
1640
static void sip_cc_agent_ack(struct ast_cc_agent *agent);

    
   
1641
static int sip_cc_agent_status_request(struct ast_cc_agent *agent);

    
   
1642
static int sip_cc_agent_start_monitoring(struct ast_cc_agent *agent);

    
   
1643
static int sip_cc_agent_recall(struct ast_cc_agent *agent);

    
   
1644
static void sip_cc_agent_destructor(struct ast_cc_agent *agent);

    
   
1645

   

    
   
1646
static struct ast_cc_agent_callbacks sip_cc_agent_callbacks = {

    
   
1647
	.type = "SIP",

    
   
1648
	.init = sip_cc_agent_init,

    
   
1649
	.start_offer_timer = sip_cc_agent_start_offer_timer,

    
   
1650
	.stop_offer_timer = sip_cc_agent_stop_offer_timer,

    
   
1651
	.ack = sip_cc_agent_ack,

    
   
1652
	.status_request = sip_cc_agent_status_request,

    
   
1653
	.start_monitoring = sip_cc_agent_start_monitoring,

    
   
1654
	.callee_available = sip_cc_agent_recall,

    
   
1655
	.destructor = sip_cc_agent_destructor,

    
   
1656
};

    
   
1657

   

    
   
1658
static int find_by_notify_uri_helper(void *obj, void *arg, int flags)

    
   
1659
{

    
   
1660
	struct ast_cc_agent *agent = obj;

    
   
1661
	struct sip_cc_agent_pvt *agent_pvt = agent->private_data;

    
   
1662
	const char *uri = arg;

    
   
1663

   

    
   
1664
	return !strcmp(agent_pvt->notify_uri, uri) ? CMP_MATCH | CMP_STOP : 0;

    
   
1665
}

    
   
1666

   

    
   
1667
static struct ast_cc_agent *find_sip_cc_agent_by_notify_uri(const char * const uri)

    
   
1668
{

    
   
1669
	struct ast_cc_agent *agent = ast_cc_agent_callback(0, find_by_notify_uri_helper, (char *)uri, "SIP");

    
   
1670
	return agent;

    
   
1671
}

    
   
1672

   

    
   
1673
static int find_by_subscribe_uri_helper(void *obj, void *arg, int flags)

    
   
1674
{

    
   
1675
	struct ast_cc_agent *agent = obj;

    
   
1676
	struct sip_cc_agent_pvt *agent_pvt = agent->private_data;

    
   
1677
	const char *uri = arg;

    
   
1678

   

    
   
1679
	return !strcmp(agent_pvt->subscribe_uri, uri) ? CMP_MATCH | CMP_STOP : 0;

    
   
1680
}

    
   
1681

   

    
   
1682
static struct ast_cc_agent *find_sip_cc_agent_by_subscribe_uri(const char * const uri)

    
   
1683
{

    
   
1684
	struct ast_cc_agent *agent = ast_cc_agent_callback(0, find_by_subscribe_uri_helper, (char *)uri, "SIP");

    
   
1685
	return agent;

    
   
1686
}

    
   
1687

   

    
   
1688
static int find_by_callid_helper(void *obj, void *arg, int flags)

    
   
1689
{

    
   
1690
	struct ast_cc_agent *agent = obj;

    
   
1691
	struct sip_cc_agent_pvt *agent_pvt = agent->private_data;

    
   
1692
	struct sip_pvt *call_pvt = arg;

    
   
1693

   

    
   
1694
	return !strcmp(agent_pvt->original_callid, call_pvt->callid) ? CMP_MATCH | CMP_STOP : 0;

    
   
1695
}

    
   
1696

   

    
   
1697
static struct ast_cc_agent *find_sip_cc_agent_by_original_callid(struct sip_pvt *pvt)

    
   
1698
{

    
   
1699
	struct ast_cc_agent *agent = ast_cc_agent_callback(0, find_by_callid_helper, pvt, "SIP");

    
   
1700
	return agent;

    
   
1701
}

    
   
1702

   

    
   
1703
static int sip_cc_agent_init(struct ast_cc_agent *agent, struct ast_channel *chan)

    
   
1704
{

    
   
1705
	struct sip_cc_agent_pvt *agent_pvt = ast_calloc(1, sizeof(*agent_pvt));

    
   
1706
	struct sip_pvt *call_pvt = chan->tech_pvt;

    
   
1707

   

    
   
1708
	if (!agent_pvt) {

    
   
1709
		return -1;

    
   
1710
	}

    
   
1711

   

    
   
1712
	ast_assert(!strcmp(chan->tech->type, "SIP"));

    
   
1713

   

    
   
1714
	ast_copy_string(agent_pvt->original_callid, call_pvt->callid, sizeof(agent_pvt->original_callid));

    
   
1715
	ast_copy_string(agent_pvt->original_exten, call_pvt->exten, sizeof(agent_pvt->original_exten));

    
   
1716
	agent_pvt->offer_timer_id = -1;

    
   
1717
	agent->private_data = agent_pvt;

    
   
1718
	sip_pvt_lock(call_pvt);

    
   
1719
	ast_set_flag(&call_pvt->flags[0], SIP_OFFER_CC);

    
   
1720
	sip_pvt_unlock(call_pvt);

    
   
1721
	return 0;

    
   
1722
}

    
   
1723

   

    
   
1724
static int sip_offer_timer_expire(const void *data)

    
   
1725
{

    
   
1726
	struct ast_cc_agent *agent = (struct ast_cc_agent *) data;

    
   
1727
	struct sip_cc_agent_pvt *agent_pvt = agent->private_data;

    
   
1728

   

    
   
1729
	agent_pvt->offer_timer_id = -1;

    
   
1730

   

    
   
1731
	return ast_cc_failed(agent->core_id, "SIP agent %s's offer timer expired", agent->device_name);

    
   
1732
}

    
   
1733

   

    
   
1734
static int sip_cc_agent_start_offer_timer(struct ast_cc_agent *agent)

    
   
1735
{

    
   
1736
	struct sip_cc_agent_pvt *agent_pvt = agent->private_data;

    
   
1737
	int when;

    
   
1738

   

    
   
1739
	when = ast_get_cc_offer_timer(agent->cc_params) * 1000;

    
   
1740
	agent_pvt->offer_timer_id = ast_sched_add(sched, when, sip_offer_timer_expire, agent);

    
   
1741
	return 0;

    
   
1742
}

    
   
1743

   

    
   
1744
static int sip_cc_agent_stop_offer_timer(struct ast_cc_agent *agent)

    
   
1745
{

    
   
1746
	struct sip_cc_agent_pvt *agent_pvt = agent->private_data;

    
   
1747

   

    
   
1748
	AST_SCHED_DEL(sched, agent_pvt->offer_timer_id);

    
   
1749
	return 0;

    
   
1750
}

    
   
1751

   

    
   
1752
static void sip_cc_agent_ack(struct ast_cc_agent *agent)

    
   
1753
{

    
   
1754
	struct sip_cc_agent_pvt *agent_pvt = agent->private_data;

    
   
1755

   

    
   
1756
	sip_pvt_lock(agent_pvt->subscribe_pvt);

    
   
1757
	ast_set_flag(&agent_pvt->subscribe_pvt->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED);

    
   
1758
	transmit_response(agent_pvt->subscribe_pvt, "200 OK", &agent_pvt->subscribe_pvt->initreq);

    
   
1759
	transmit_cc_notify(agent, agent_pvt->subscribe_pvt, CC_QUEUED);

    
   
1760
	sip_pvt_unlock(agent_pvt->subscribe_pvt);

    
   
1761
	agent_pvt->is_available = TRUE;

    
   
1762
}

    
   
1763

   

    
   
1764
static int sip_cc_agent_status_request(struct ast_cc_agent *agent)

    
   
1765
{

    
   
1766
	struct sip_cc_agent_pvt *agent_pvt = agent->private_data;

    
   
1767
	enum ast_device_state state = agent_pvt->is_available ? AST_DEVICE_NOT_INUSE : AST_DEVICE_INUSE;

    
   
1768
	return ast_cc_agent_status_response(agent->core_id, state);

    
   
1769
}

    
   
1770

   

    
   
1771
static int sip_cc_agent_start_monitoring(struct ast_cc_agent *agent)

    
   
1772
{

    
   
1773
	/* To start monitoring just means to wait for an incoming PUBLISH

    
   
1774
	 * to tell us that the caller has become available again. No special

    
   
1775
	 * action is needed

    
   
1776
	 */

    
   
1777
	return 0;

    
   
1778
}

    
   
1779

   

    
   
1780
static int sip_cc_agent_recall(struct ast_cc_agent *agent)

    
   
1781
{

    
   
1782
	struct sip_cc_agent_pvt *agent_pvt = agent->private_data;

    
   
1783
	/* If we have received a PUBLISH beforehand stating that the caller in question

    
   
1784
	 * is not available, we can save ourself a bit of effort here and just report

    
   
1785
	 * the caller as busy

    
   
1786
	 */

    
   
1787
	if (!agent_pvt->is_available) {

    
   
1788
		return ast_cc_agent_caller_busy(agent->core_id, "Caller %s is busy, reporting to the core",

    
   
1789
				agent->device_name);

    
   
1790
	}

    
   
1791
	/* Otherwise, we transmit a NOTIFY to the caller and await either

    
   
1792
	 * a PUBLISH or an INVITE

    
   
1793
	 */

    
   
1794
	sip_pvt_lock(agent_pvt->subscribe_pvt);

    
   
1795
	transmit_cc_notify(agent, agent_pvt->subscribe_pvt, CC_READY);

    
   
1796
	sip_pvt_unlock(agent_pvt->subscribe_pvt);

    
   
1797
	return 0;

    
   
1798
}

    
   
1799

   

    
   
1800
static void sip_cc_agent_destructor(struct ast_cc_agent *agent)

    
   
1801
{

    
   
1802
	struct sip_cc_agent_pvt *agent_pvt = agent->private_data;

    
   
1803

   

    
   
1804
	if (!agent_pvt) {

    
   
1805
		/* The agent constructor probably failed. */

    
   
1806
		return;

    
   
1807
	}

    
   
1808

   

    
   
1809
	sip_cc_agent_stop_offer_timer(agent);

    
   
1810
	if (agent_pvt->subscribe_pvt) {

    
   
1811
		sip_pvt_lock(agent_pvt->subscribe_pvt);

    
   
1812
		if (!ast_test_flag(&agent_pvt->subscribe_pvt->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED)) {

    
   
1813
			/* If we haven't sent a 200 OK for the SUBSCRIBE dialog yet, then we need to send a response letting

    
   
1814
			 * the subscriber know something went wrong

    
   
1815
			 */

    
   
1816
			transmit_response(agent_pvt->subscribe_pvt, "500 Internal Server Error", &agent_pvt->subscribe_pvt->initreq);

    
   
1817
		}

    
   
1818
		sip_pvt_unlock(agent_pvt->subscribe_pvt);

    
   
1819
		agent_pvt->subscribe_pvt = dialog_unref(agent_pvt->subscribe_pvt, "SIP CC agent destructor: Remove ref to subscription");

    
   
1820
	}

    
   
1821
	ast_free(agent_pvt);

    
   
1822
}

    
   
1823

   

    
   
1824
struct ao2_container *sip_monitor_instances;

    
   
1825

   

    
   
1826
static int sip_monitor_instance_hash_fn(const void *obj, const int flags)

    
   
1827
{

    
   
1828
	const struct sip_monitor_instance *monitor_instance = obj;

    
   
1829
	return monitor_instance->core_id;

    
   
1830
}

    
   
1831

   

    
   
1832
static int sip_monitor_instance_cmp_fn(void *obj, void *arg, int flags)

    
   
1833
{

    
   
1834
	struct sip_monitor_instance *monitor_instance1 = obj;

    
   
1835
	struct sip_monitor_instance *monitor_instance2 = arg;

    
   
1836

   

    
   
1837
	return monitor_instance1->core_id == monitor_instance2->core_id ? CMP_MATCH | CMP_STOP : 0;

    
   
1838
}

    
   
1839

   

    
   
1840
static void sip_monitor_instance_destructor(void *data)

    
   
1841
{

    
   
1842
	struct sip_monitor_instance *monitor_instance = data;

    
   
1843
	if (monitor_instance->subscription_pvt) {

    
   
1844
		sip_pvt_lock(monitor_instance->subscription_pvt);

    
   
1845
		monitor_instance->subscription_pvt->expiry = 0;

    
   
1846
		transmit_invite(monitor_instance->subscription_pvt, SIP_SUBSCRIBE, FALSE, 0, monitor_instance->subscribe_uri);

    
   
1847
		sip_pvt_unlock(monitor_instance->subscription_pvt);

    
   
1848
		dialog_unref(monitor_instance->subscription_pvt, "Unref monitor instance ref of subscription pvt");

    
   
1849
	}

    
   
1850
	if (monitor_instance->suspension_entry) {

    
   
1851
		monitor_instance->suspension_entry->body[0] = '\0';

    
   
1852
		transmit_publish(monitor_instance->suspension_entry, SIP_PUBLISH_REMOVE ,monitor_instance->notify_uri);

    
   
1853
		ao2_t_ref(monitor_instance->suspension_entry, -1, "Decrementing suspension entry refcount in sip_monitor_instance_destructor");

    
   
1854
	}

    
   
1855
	ast_string_field_free_memory(monitor_instance);

    
   
1856
}

    
   
1857

   

    
   
1858
static struct sip_monitor_instance *sip_monitor_instance_init(int core_id, const char * const subscribe_uri, const char * const peername, const char * const device_name)

    
   
1859
{

    
   
1860
	struct sip_monitor_instance *monitor_instance = ao2_alloc(sizeof(*monitor_instance), sip_monitor_instance_destructor);

    
   
1861

   

    
   
1862
	if (!monitor_instance) {

    
   
1863
		return NULL;

    
   
1864
	}

    
   
1865

   

    
   
1866
	if (ast_string_field_init(monitor_instance, 256)) {

    
   
1867
		ao2_ref(monitor_instance, -1);

    
   
1868
		return NULL;

    
   
1869
	}

    
   
1870

   

    
   
1871
	ast_string_field_set(monitor_instance, subscribe_uri, subscribe_uri);

    
   
1872
	ast_string_field_set(monitor_instance, peername, peername);

    
   
1873
	ast_string_field_set(monitor_instance, device_name, device_name);

    
   
1874
	monitor_instance->core_id = core_id;

    
   
1875
	ao2_link(sip_monitor_instances, monitor_instance);

    
   
1876
	return monitor_instance;

    
   
1877
}

    
   
1878

   

    
   
1879
static int find_sip_monitor_instance_by_subscription_pvt(void *obj, void *arg, int flags)

    
   
1880
{

    
   
1881
	struct sip_monitor_instance *monitor_instance = obj;

    
   
1882
	return monitor_instance->subscription_pvt == arg ? CMP_MATCH | CMP_STOP : 0;

    
   
1883
}

    
   
1884

   

    
   
1885
static int find_sip_monitor_instance_by_suspension_entry(void *obj, void *arg, int flags)

    
   
1886
{

    
   
1887
	struct sip_monitor_instance *monitor_instance = obj;

    
   
1888
	return monitor_instance->suspension_entry == arg ? CMP_MATCH | CMP_STOP : 0;

    
   
1889
}

    
   
1890

   

    
   
1891
static int sip_cc_monitor_request_cc(struct ast_cc_monitor *monitor, int *available_timer_id);

    
   
1892
static int sip_cc_monitor_suspend(struct ast_cc_monitor *monitor);

    
   
1893
static int sip_cc_monitor_unsuspend(struct ast_cc_monitor *monitor);

    
   
1894
static int sip_cc_monitor_cancel_available_timer(struct ast_cc_monitor *monitor, int *sched_id);

    
   
1895
static void sip_cc_monitor_destructor(void *private_data);

    
   
1896

   

    
   
1897
static struct ast_cc_monitor_callbacks sip_cc_monitor_callbacks = {

    
   
1898
	.type = "SIP",

    
   
1899
	.request_cc = sip_cc_monitor_request_cc,

    
   
1900
	.suspend = sip_cc_monitor_suspend,

    
   
1901
	.unsuspend = sip_cc_monitor_unsuspend,

    
   
1902
	.cancel_available_timer = sip_cc_monitor_cancel_available_timer,

    
   
1903
	.destructor = sip_cc_monitor_destructor,

    
   
1904
};

    
   
1905

   

    
   
1906
static int sip_cc_monitor_request_cc(struct ast_cc_monitor *monitor, int *available_timer_id)

    
   
1907
{

    
   
1908
	struct sip_monitor_instance *monitor_instance = monitor->private_data;

    
   
1909
	enum ast_cc_service_type service = monitor->service_offered;

    
   
1910
	int when;

    
   
1911

   

    
   
1912
	if (!monitor_instance) {

    
   
1913
		return -1;

    
   
1914
	}

    
   
1915

   

    
   
1916
	if (!(monitor_instance->subscription_pvt = sip_alloc(NULL, NULL, 0, SIP_SUBSCRIBE, NULL))) {

    
   
1917
		return -1;

    
   
1918
	}

    
   
1919

   

    
   
1920
	when = service == AST_CC_CCBS ? ast_get_ccbs_available_timer(monitor->interface->config_params) :

    
   
1921
		ast_get_ccnr_available_timer(monitor->interface->config_params);

    
   
1922

   

    
   
1923
	sip_pvt_lock(monitor_instance->subscription_pvt);

    
   
1924
	create_addr(monitor_instance->subscription_pvt, monitor_instance->peername, 0, 1, NULL);

    
   
1925
	ast_sip_ouraddrfor(&monitor_instance->subscription_pvt->sa.sin_addr, &monitor_instance->subscription_pvt->ourip, monitor_instance->subscription_pvt);

    
   
1926
	monitor_instance->subscription_pvt->subscribed = CALL_COMPLETION;

    
   
1927
	monitor_instance->subscription_pvt->expiry = when;

    
   
1928

   

    
   
1929
	transmit_invite(monitor_instance->subscription_pvt, SIP_SUBSCRIBE, FALSE, 2, monitor_instance->subscribe_uri);

    
   
1930
	sip_pvt_unlock(monitor_instance->subscription_pvt);

    
   
1931

   

    
   
1932
	ao2_t_ref(monitor, +1, "Adding a ref to the monitor for the scheduler");

    
   
1933
	*available_timer_id = ast_sched_add(sched, when * 1000, ast_cc_available_timer_expire, monitor);

    
   
1934
	return 0;

    
   
1935
}

    
   
1936

   

    
   
1937
static int construct_pidf_body(enum sip_cc_publish_state state, char *pidf_body, size_t size, const char *presentity)

    
   
1938
{

    
   
1939
	struct ast_str *body = ast_str_alloca(size);

    
   
1940
	char tuple_id[32];

    
   
1941

   

    
   
1942
	generate_random_string(tuple_id, sizeof(tuple_id));

    
   
1943

   

    
   
1944
	/* We'll make this a bare-bones pidf body. In state_notify_build_xml, the PIDF

    
   
1945
	 * body gets a lot more extra junk that isn't necessary, so we'll leave it out here.

    
   
1946
	 */

    
   
1947
	ast_str_append(&body, 0, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");

    
   
1948
	/* XXX The entity attribute is currently set to the peer name associated with the

    
   
1949
	 * dialog. This is because we currently only call this function for call-completion

    
   
1950
	 * PUBLISH bodies. In such cases, the entity is completely disregarded. For other

    
   
1951
	 * event packages, it may be crucial to have a proper URI as the presentity so this

    
   
1952
	 * should be revisited as support is expanded.

    
   
1953
	 */

    
   
1954
	ast_str_append(&body, 0, "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\" entity=\"%s\">\n", presentity);

    
   
1955
	ast_str_append(&body, 0, "<tuple id=\"%s\">\n", tuple_id);

    
   
1956
	ast_str_append(&body, 0, "<status><basic>%s</basic></status>\n", state == CC_OPEN ? "open" : "closed");

    
   
1957
	ast_str_append(&body, 0, "</tuple>\n");

    
   
1958
	ast_str_append(&body, 0, "</presence>\n");

    
   
1959
	ast_copy_string(pidf_body, ast_str_buffer(body), size);

    
   
1960
	return 0;

    
   
1961
}

    
   
1962

   

    
   
1963
static int sip_cc_monitor_suspend(struct ast_cc_monitor *monitor)

    
   
1964
{

    
   
1965
	struct sip_monitor_instance *monitor_instance = monitor->private_data;

    
   
1966
	enum sip_publish_type publish_type;

    
   
1967
	struct cc_epa_entry *cc_entry;

    
   
1968

   

    
   
1969
	if (!monitor_instance) {

    
   
1970
		return -1;

    
   
1971
	}

    
   
1972

   

    
   
1973
	if (!monitor_instance->suspension_entry) {

    
   
1974
		/* We haven't yet allocated the suspension entry, so let's give it a shot */

    
   
1975
		if (!(monitor_instance->suspension_entry = create_epa_entry("call-completion", monitor_instance->peername))) {

    
   
1976
			ast_log(LOG_WARNING, "Unable to allocate sip EPA entry for call-completion\n");

    
   
1977
			ao2_ref(monitor_instance, -1);

    
   
1978
			return -1;

    
   
1979
		}

    
   
1980
		if (!(cc_entry = ast_calloc(1, sizeof(*cc_entry)))) {

    
   
1981
			ast_log(LOG_WARNING, "Unable to allocate space for instance data of EPA entry for call-completion\n");

    
   
1982
			ao2_ref(monitor_instance, -1);

    
   
1983
			return -1;

    
   
1984
		}

    
   
1985
		cc_entry->core_id = monitor->core_id;

    
   
1986
		monitor_instance->suspension_entry->instance_data = cc_entry;

    
   
1987
		publish_type = SIP_PUBLISH_INITIAL;

    
   
1988
	} else {

    
   
1989
		publish_type = SIP_PUBLISH_MODIFY;

    
   
1990
		cc_entry = monitor_instance->suspension_entry->instance_data;

    
   
1991
	}

    
   
1992

   

    
   
1993
	cc_entry->current_state = CC_CLOSED;

    
   
1994

   

    
   
1995
	if (ast_strlen_zero(monitor_instance->notify_uri)) {

    
   
1996
		/* If we have no set notify_uri, then what this means is that we have

    
   
1997
		 * not received a NOTIFY from this destination stating that he is

    
   
1998
		 * currently available.

    
   
1999
		 *

    
   
2000
		 * This situation can arise when the core calls the suspend callbacks

    
   
2001
		 * of multiple destinations. If one of the other destinations aside

    
   
2002
		 * from this one notified Asterisk that he is available, then there

    
   
2003
		 * is no reason to take any suspension action on this device. Rather,

    
   
2004
		 * we should return now and if we receive a NOTIFY while monitoring

    
   
2005
		 * is still "suspended" then we can immediately respond with the

    
   
2006
		 * proper PUBLISH to let this endpoint know what is going on.

    
   
2007
		 */

    
   
2008
		return 0;

    
   
2009
	}

    
   
2010
	construct_pidf_body(CC_CLOSED, monitor_instance->suspension_entry->body, sizeof(monitor_instance->suspension_entry->body), monitor_instance->peername);

    
   
2011
	return transmit_publish(monitor_instance->suspension_entry, publish_type, monitor_instance->notify_uri);

    
   
2012
}

    
   
2013

   

    
   
2014
static int sip_cc_monitor_unsuspend(struct ast_cc_monitor *monitor)

    
   
2015
{

    
   
2016
	struct sip_monitor_instance *monitor_instance = monitor->private_data;

    
   
2017
	struct cc_epa_entry *cc_entry;

    
   
2018

   

    
   
2019
	if (!monitor_instance) {

    
   
2020
		return -1;

    
   
2021
	}

    
   
2022

   

    
   
2023
	ast_assert(monitor_instance->suspension_entry != NULL);

    
   
2024

   

    
   
2025
	cc_entry = monitor_instance->suspension_entry->instance_data;

    
   
2026
	cc_entry->current_state = CC_OPEN;

    
   
2027
	if (ast_strlen_zero(monitor_instance->notify_uri)) {

    
   
2028
		/* This means we are being asked to unsuspend a call leg we never

    
   
2029
		 * sent a PUBLISH on. As such, there is no reason to send another

    
   
2030
		 * PUBLISH at this point either. We can just return instead.

    
   
2031
		 */

    
   
2032
		return 0;

    
   
2033
	}

    
   
2034
	construct_pidf_body(CC_OPEN, monitor_instance->suspension_entry->body, sizeof(monitor_instance->suspension_entry->body), monitor_instance->peername);

    
   
2035
	return transmit_publish(monitor_instance->suspension_entry, SIP_PUBLISH_MODIFY, monitor_instance->notify_uri);

    
   
2036
}

    
   
2037

   

    
   
2038
static int sip_cc_monitor_cancel_available_timer(struct ast_cc_monitor *monitor, int *sched_id)

    
   
2039
{

    
   
2040
	if (*sched_id != -1) {

    
   
2041
		AST_SCHED_DEL(sched, *sched_id);

    
   
2042
		ao2_t_ref(monitor, -1, "Removing scheduler's reference to the monitor");

    
   
2043
	}

    
   
2044
	return 0;

    
   
2045
}

    
   
2046

   

    
   
2047
static void sip_cc_monitor_destructor(void *private_data)

    
   
2048
{

    
   
2049
	struct sip_monitor_instance *monitor_instance = private_data;

    
   
2050
	ao2_unlink(sip_monitor_instances, monitor_instance);

    
   
2051
	ast_module_unref(ast_module_info->self);

    
   
2052
}

    
   
2053

   

    
   
2054
static int sip_get_cc_information(struct sip_request *req, char *subscribe_uri, size_t size, enum ast_cc_service_type *service)

    
   
2055
{

    
   
2056
	char *call_info = ast_strdupa(get_header(req, "Call-Info"));

    
   
2057
	char *uri;

    
   
2058
	char *purpose;

    
   
2059
	char *service_str;

    
   
2060
	static const char cc_purpose[] = "purpose=call-completion";

    
   
2061
	static const int cc_purpose_len = sizeof(cc_purpose) - 1;

    
   
2062

   

    
   
2063
	if (ast_strlen_zero(call_info)) {

    
   
2064
		/* No Call-Info present. Definitely no CC offer */

    
   
2065
		return -1;

    
   
2066
	}

    
   
2067

   

    
   
2068
	uri = strsep(&call_info, ";");

    
   
2069

   

    
   
2070
	while ((purpose = strsep(&call_info, ";"))) {

    
   
2071
		if (!strncmp(purpose, cc_purpose, cc_purpose_len)) {

    
   
2072
			break;

    
   
2073
		}

    
   
2074
	}

    
   
2075
	if (!purpose) {

    
   
2076
		/* We didn't find the appropriate purpose= parameter. Oh well */

    
   
2077
		return -1;

    
   
2078
	}

    
   
2079

   

    
   
2080
	/* Okay, call-completion has been offered. Let's figure out what type of service this is */

    
   
2081
	while ((service_str = strsep(&call_info, ";"))) {

    
   
2082
		if (!strncmp(service_str, "m=", 2)) {

    
   
2083
			break;

    
   
2084
		}

    
   
2085
	}

    
   
2086
	if (!service_str) {

    
   
2087
		/* So they didn't offer a particular service, We'll just go with CCBS since it really

    
   
2088
		 * doesn't matter anyway

    
   
2089
		 */

    
   
2090
		service_str = "BS";

    
   
2091
	} else {

    
   
2092
		/* We already determined that there is an "m=" so no need to check

    
   
2093
		 * the result of this strsep

    
   
2094
		 */

    
   
2095
		strsep(&service_str, "=");

    
   
2096
	}

    
   
2097

   

    
   
2098
	if ((*service = service_string_to_service_type(service_str)) == AST_CC_NONE) {

    
   
2099
		/* Invalid service offered */

    
   
2100
		return -1;

    
   
2101
	}

    
   
2102

   

    
   
2103
	ast_copy_string(subscribe_uri, get_in_brackets(uri), size);

    
   
2104

   

    
   
2105
	return 0;

    
   
2106
}

    
   
2107

   

    
   
2108
/*

    
   
2109
 * \brief Determine what, if any, CC has been offered and queue a CC frame if possible

    
   
2110
 *

    
   
2111
 * After taking care of some formalities to be sure that this call is eligible for CC,

    
   
2112
 * we first try to see if we can make use of native CC. We grab the information from

    
   
2113
 * the passed-in sip_request (which is always a response to an INVITE). If we can

    
   
2114
 * use native CC monitoring for the call, then so be it.

    
   
2115
 *

    
   
2116
 * If native cc monitoring is not possible or not supported, then we will instead attempt

    
   
2117
 * to use generic monitoring. Falling back to generic from a failed attempt at using native

    
   
2118
 * monitoring will only work if the monitor policy of the endpoint is "always"

    
   
2119
 *

    
   
2120
 * \param pvt The current dialog. Contains CC parameters for the endpoint

    
   
2121
 * \param req The response to the INVITE we want to inspect

    
   
2122
 * \param service The service to use if generic monitoring is to be used. For native

    
   
2123
 * monitoring, we get the service from the SIP response itself

    
   
2124
 */

    
   
2125
static void sip_handle_cc(struct sip_pvt *pvt, struct sip_request *req, enum ast_cc_service_type service)

    
   
2126
{

    
   
2127
	enum ast_cc_monitor_policies monitor_policy = ast_get_cc_monitor_policy(pvt->cc_params);

    
   
2128
	int core_id;

    
   
2129
	char interface_name[AST_CHANNEL_NAME];

    
   
2130

   

    
   
2131
	if (monitor_policy == AST_CC_MONITOR_NEVER) {

    
   
2132
		/* Don't bother, just return */

    
   
2133
		return;

    
   
2134
	}

    
   
2135

   

    
   
2136
	if ((core_id = ast_cc_get_current_core_id(pvt->owner)) == -1) {

    
   
2137
		/* For some reason, CC is invalid, so don't try it! */

    
   
2138
		return;

    
   
2139
	}

    
   
2140

   

    
   
2141
	ast_channel_get_device_name(pvt->owner, interface_name, sizeof(interface_name));

    
   
2142

   

    
   
2143
	if (monitor_policy == AST_CC_MONITOR_ALWAYS || monitor_policy == AST_CC_MONITOR_NATIVE) {

    
   
2144
		char subscribe_uri[SIPBUFSIZE];

    
   
2145
		char device_name[AST_CHANNEL_NAME];

    
   
2146
		enum ast_cc_service_type offered_service;

    
   
2147
		struct sip_monitor_instance *monitor_instance;

    
   
2148
		if (sip_get_cc_information(req, subscribe_uri, sizeof(subscribe_uri), &offered_service)) {

    
   
2149
			/* If CC isn't being offered to us, or for some reason the CC offer is

    
   
2150
			 * not formatted correctly, then it may still be possible to use generic

    
   
2151
			 * call completion since the monitor policy may be "always"

    
   
2152
			 */

    
   
2153
			goto generic;

    
   
2154
		}

    
   
2155
		ast_channel_get_device_name(pvt->owner, device_name, sizeof(device_name));

    
   
2156
		if (!(monitor_instance = sip_monitor_instance_init(core_id, subscribe_uri, pvt->peername, device_name))) {

    
   
2157
			/* Same deal. We can try using generic still */

    
   
2158
			goto generic;

    
   
2159
		}

    
   
2160
		/* We bump the refcount of chan_sip because once we queue this frame, the CC core

    
   
2161
		 * will have a reference to callbacks in this module. We decrement the module

    
   
2162
		 * refcount once the monitor destructor is called

    
   
2163
		 */

    
   
2164
		ast_module_ref(ast_module_info->self);

    
   
2165
		ast_queue_cc_frame(pvt->owner, "SIP", pvt->dialstring, offered_service, monitor_instance);

    
   
2166
		ao2_ref(monitor_instance, -1);

    
   
2167
		return;

    
   
2168
	}

    
   
2169

   

    
   
2170
generic:

    
   
2171
	if (monitor_policy == AST_CC_MONITOR_GENERIC || monitor_policy == AST_CC_MONITOR_ALWAYS) {

    
   
2172
		ast_queue_cc_frame(pvt->owner, AST_CC_GENERIC_MONITOR_TYPE, interface_name, service, NULL);

    
   
2173
	}

    
   
2174
}

    
   
2175

   
1375
/*! \brief Working TLS connection configuration */
2176
/*! \brief Working TLS connection configuration */
1376
static struct ast_tls_config sip_tls_cfg;
2177
static struct ast_tls_config sip_tls_cfg;
1377

    
   
2178

   
1378
/*! \brief Default TLS connection configuration */
2179
/*! \brief Default TLS connection configuration */
1379
static struct ast_tls_config default_tls_cfg;
2180
static struct ast_tls_config default_tls_cfg;
[+20] [20] 699 lines
[+20] [+] static struct sip_proxy *proxy_allocate(char *name, char *port, int force)
2079
	if (!proxy)
2880
	if (!proxy)
2080
		return NULL;
2881
		return NULL;
2081
	proxy->force = force;
2882
	proxy->force = force;
2082
	ast_copy_string(proxy->name, name, sizeof(proxy->name));
2883
	ast_copy_string(proxy->name, name, sizeof(proxy->name));
2083
	proxy->ip.sin_port = htons(port_str2int(port, STANDARD_SIP_PORT));
2884
	proxy->ip.sin_port = htons(port_str2int(port, STANDARD_SIP_PORT));

    
   
2885
	proxy->ip.sin_family = AF_INET;
2084
	proxy_update(proxy);
2886
	proxy_update(proxy);
2085
	return proxy;
2887
	return proxy;
2086
}
2888
}
2087

    
   
2889

   
2088
/*! \brief Get default outbound proxy or global proxy */
2890
/*! \brief Get default outbound proxy or global proxy */
[+20] [20] 609 lines
[+20] [+] static enum sip_result __sip_reliable_xmit(struct sip_pvt *p, int seqno, int resp, struct ast_str *data, int len, int fatal, int sipmethod)
2698
static int __sip_autodestruct(const void *data)
3500
static int __sip_autodestruct(const void *data)
2699
{
3501
{
2700
	struct sip_pvt *p = (struct sip_pvt *)data;
3502
	struct sip_pvt *p = (struct sip_pvt *)data;
2701

    
   
3503

   
2702
	/* If this is a subscription, tell the phone that we got a timeout */
3504
	/* If this is a subscription, tell the phone that we got a timeout */
2703
	if (p->subscribed) {
3505
	if (p->subscribed && p->subscribed != MWI_NOTIFICATION && p->subscribed != CALL_COMPLETION) {
2704
		transmit_state_notify(p, AST_EXTENSION_DEACTIVATED, 1, TRUE);	/* Send last notification */
3506
		transmit_state_notify(p, AST_EXTENSION_DEACTIVATED, 1, TRUE);	/* Send last notification */
2705
		p->subscribed = NONE;
3507
		p->subscribed = NONE;
2706
		append_history(p, "Subscribestatus", "timeout");
3508
		append_history(p, "Subscribestatus", "timeout");
2707
		ast_debug(3, "Re-scheduled destruction of SIP subscription %s\n", p->callid ? p->callid : "<unknown>");
3509
		ast_debug(3, "Re-scheduled destruction of SIP subscription %s\n", p->callid ? p->callid : "<unknown>");
2708
		return 10000;	/* Reschedule this destruction so that we know that it's gone */
3510
		return 10000;	/* Reschedule this destruction so that we know that it's gone */
[+20] [20] 341 lines
[+20] [+] static void enable_dsp_detect(struct sip_pvt *p)
3050
		if (!p->rtp || ast_rtp_instance_dtmf_mode_set(p->rtp, AST_RTP_DTMF_MODE_INBAND)) {
3852
		if (!p->rtp || ast_rtp_instance_dtmf_mode_set(p->rtp, AST_RTP_DTMF_MODE_INBAND)) {
3051
			features |= DSP_FEATURE_DIGIT_DETECT;
3853
			features |= DSP_FEATURE_DIGIT_DETECT;
3052
                }
3854
                }
3053
	}
3855
	}
3054

    
   
3856

   
3055
	if (ast_test_flag(&p->flags[1], SIP_PAGE2_FAX_DETECT)) {
3857
	if (ast_test_flag(&p->flags[1], SIP_PAGE2_FAX_DETECT_CNG)) {
3056
		features |= DSP_FEATURE_FAX_DETECT;
3858
		features |= DSP_FEATURE_FAX_DETECT;
3057
	}
3859
	}
3058

    
   
3860

   
3059
	if (!features) {
3861
	if (!features) {
3060
		return;
3862
		return;
[+20] [20] 96 lines
[+20] [+] static int sip_queryoption(struct ast_channel *chan, int option, void *data, int *datalen)
3157
	case AST_OPTION_DIGIT_DETECT:
3959
	case AST_OPTION_DIGIT_DETECT:
3158
		cp = (char *) data;
3960
		cp = (char *) data;
3159
		*cp = p->dsp ? 1 : 0;
3961
		*cp = p->dsp ? 1 : 0;
3160
		ast_debug(1, "Reporting digit detection %sabled on %s\n", *cp ? "en" : "dis", chan->name);
3962
		ast_debug(1, "Reporting digit detection %sabled on %s\n", *cp ? "en" : "dis", chan->name);
3161
		break;
3963
		break;

    
   
3964
	case AST_OPTION_DEVICE_NAME:

    
   
3965
		if (p && p->outgoing_call) {

    
   
3966
			cp = (char *) data;

    
   
3967
			ast_copy_string(cp, p->dialstring, *datalen);

    
   
3968
			res = 0;

    
   
3969
		}

    
   
3970
		/* We purposely break with a return of -1 in the

    
   
3971
		 * implied else case here

    
   
3972
		 */

    
   
3973
		break;
3162
	default:
3974
	default:
3163
		break;
3975
		break;
3164
	}
3976
	}
3165

    
   
3977

   
3166
	return res;
3978
	return res;
[+20] [20] 214 lines
[+20] [+] static void sip_destroy_peer(struct sip_peer *peer)
3381
		peer->chanvars = NULL;
4193
		peer->chanvars = NULL;
3382
	}
4194
	}
3383
	
4195
	
3384
	register_peer_exten(peer, FALSE);
4196
	register_peer_exten(peer, FALSE);
3385
	ast_free_ha(peer->ha);
4197
	ast_free_ha(peer->ha);

    
   
4198
	ast_free_ha(peer->directmediaha);
3386
	if (peer->selfdestruct)
4199
	if (peer->selfdestruct)
3387
		ast_atomic_fetchadd_int(&apeerobjs, -1);
4200
		ast_atomic_fetchadd_int(&apeerobjs, -1);
3388
	else if (peer->is_realtime) {
4201
	else if (peer->is_realtime) {
3389
		ast_atomic_fetchadd_int(&rpeerobjs, -1);
4202
		ast_atomic_fetchadd_int(&rpeerobjs, -1);
3390
		ast_debug(3, "-REALTIME- peer Destroyed. Name: %s. Realtime Peer objects: %d\n", peer->name, rpeerobjs);
4203
		ast_debug(3, "-REALTIME- peer Destroyed. Name: %s. Realtime Peer objects: %d\n", peer->name, rpeerobjs);
[+20] [20] 8 lines
[+20] static void sip_destroy_peer(struct sip_peer *peer)
3399
	if (peer->socket.tcptls_session) {
4212
	if (peer->socket.tcptls_session) {
3400
		ao2_ref(peer->socket.tcptls_session, -1);
4213
		ao2_ref(peer->socket.tcptls_session, -1);
3401
		peer->socket.tcptls_session = NULL;
4214
		peer->socket.tcptls_session = NULL;
3402
	}
4215
	}
3403

    
   
4216

   

    
   
4217
	ast_cc_config_params_destroy(peer->cc_params);

    
   
4218

   
3404
	ast_string_field_free_memory(peer);
4219
	ast_string_field_free_memory(peer);
3405
}
4220
}
3406

    
   
4221

   
3407
/*! \brief Update peer data in database (if used) */
4222
/*! \brief Update peer data in database (if used) */
3408
static void update_peer(struct sip_peer *p, int expire)
4223
static void update_peer(struct sip_peer *p, int expire)
[+20] [20] 156 lines
[+20] [+] static struct sip_peer *realtime_peer(const char *newpeername, struct sockaddr_in *sin, int devstate_only)
3565
			ast_config_destroy(peerlist);
4380
			ast_config_destroy(peerlist);
3566
		return NULL;
4381
		return NULL;
3567
	}
4382
	}
3568

    
   
4383

   
3569
	for (tmp = var; tmp; tmp = tmp->next) {
4384
	for (tmp = var; tmp; tmp = tmp->next) {
3570
		/* If this is type=user, then skip this object. */
4385
		if (!newpeername && !strcasecmp(tmp->name, "name")) {
3571
		if (!strcasecmp(tmp->name, "type") &&

   
3572
		    !strcasecmp(tmp->value, "user")) {

   
3573
			if(peerlist)

   
3574
				ast_config_destroy(peerlist);

   
3575
			else {

   
3576
				ast_variables_destroy(var);

   
3577
				ast_variables_destroy(varregs);

   
3578
			}

   
3579
			return NULL;

   
3580
		} else if (!newpeername && !strcasecmp(tmp->name, "name")) {

   
3581
			newpeername = tmp->value;
4386
			newpeername = tmp->value;
3582
		}
4387
		}
3583
	}
4388
	}
3584
	
4389
	
3585
	if (!newpeername) {	/* Did not find peer in realtime */
4390
	if (!newpeername) {	/* Did not find peer in realtime */
[+20] [20] 110 lines
[+20] [+] static struct sip_peer *find_peer(const char *peer, struct sockaddr_in *sin, int realtime, int which_objects, int devstate_only, int transport)
3696
		}
4501
		}
3697
	}
4502
	}
3698

    
   
4503

   
3699
	if (!p && (realtime || devstate_only)) {
4504
	if (!p && (realtime || devstate_only)) {
3700
		p = realtime_peer(peer, sin, devstate_only);
4505
		p = realtime_peer(peer, sin, devstate_only);

    
   
4506
		if (p) {

    
   
4507
			switch (which_objects) {

    
   
4508
			case FINDUSERS:

    
   
4509
				if (!(p->type & SIP_TYPE_USER)) {

    
   
4510
					unref_peer(p, "Wrong type of realtime SIP endpoint");

    
   
4511
					return NULL;

    
   
4512
				}

    
   
4513
				break;

    
   
4514
			case FINDPEERS:

    
   
4515
				if (!(p->type & SIP_TYPE_PEER)) {

    
   
4516
					unref_peer(p, "Wrong type of realtime SIP endpoint");

    
   
4517
					return NULL;

    
   
4518
				}

    
   
4519
				break;

    
   
4520
			case FINDALLDEVICES:

    
   
4521
				break;

    
   
4522
			}

    
   
4523
		}
3701
	}
4524
	}
3702

    
   
4525

   
3703
	return p;
4526
	return p;
3704
}
4527
}
3705

    
   
4528

   
[+20] [20] 112 lines
[+20] [+] static int dialog_initialize_rtp(struct sip_pvt *dialog)
3818

    
   
4641

   
3819
	if (!(dialog->rtp = ast_rtp_instance_new(dialog->engine, sched, &bindaddr, NULL))) {
4642
	if (!(dialog->rtp = ast_rtp_instance_new(dialog->engine, sched, &bindaddr, NULL))) {
3820
		return -1;
4643
		return -1;
3821
	}
4644
	}
3822

    
   
4645

   
3823
	if (ast_test_flag(&dialog->flags[1], SIP_PAGE2_VIDEOSUPPORT) && (dialog->capability & AST_FORMAT_VIDEO_MASK)) {
4646
	if (ast_test_flag(&dialog->flags[1], SIP_PAGE2_VIDEOSUPPORT_ALWAYS) ||

    
   
4647
			(ast_test_flag(&dialog->flags[1], SIP_PAGE2_VIDEOSUPPORT) && (dialog->capability & AST_FORMAT_VIDEO_MASK))) {
3824
		if (!(dialog->vrtp = ast_rtp_instance_new(dialog->engine, sched, &bindaddr, NULL))) {
4648
		if (!(dialog->vrtp = ast_rtp_instance_new(dialog->engine, sched, &bindaddr, NULL))) {
3825
			return -1;
4649
			return -1;
3826
		}
4650
		}
3827
		ast_rtp_instance_set_timeout(dialog->vrtp, global_rtptimeout);
4651
		ast_rtp_instance_set_timeout(dialog->vrtp, global_rtptimeout);
3828
		ast_rtp_instance_set_hold_timeout(dialog->vrtp, global_rtpholdtimeout);
4652
		ast_rtp_instance_set_hold_timeout(dialog->vrtp, global_rtpholdtimeout);
[+20] [20] 49 lines
[+20] [+] static int create_addr_from_peer(struct sip_pvt *dialog, struct sip_peer *peer)
3878
	} else
4702
	} else
3879
		return -1;
4703
		return -1;
3880

    
   
4704

   
3881
	ast_copy_flags(&dialog->flags[0], &peer->flags[0], SIP_FLAGS_TO_COPY);
4705
	ast_copy_flags(&dialog->flags[0], &peer->flags[0], SIP_FLAGS_TO_COPY);
3882
	ast_copy_flags(&dialog->flags[1], &peer->flags[1], SIP_PAGE2_FLAGS_TO_COPY);
4706
	ast_copy_flags(&dialog->flags[1], &peer->flags[1], SIP_PAGE2_FLAGS_TO_COPY);

    
   
4707
	ast_copy_flags(&dialog->flags[2], &peer->flags[2], SIP_PAGE3_FLAGS_TO_COPY);
3883
	dialog->capability = peer->capability;
4708
	dialog->capability = peer->capability;
3884
	dialog->prefs = peer->prefs;
4709
	dialog->prefs = peer->prefs;
3885
	if (ast_test_flag(&dialog->flags[1], SIP_PAGE2_T38SUPPORT)) {
4710
	if (ast_test_flag(&dialog->flags[1], SIP_PAGE2_T38SUPPORT)) {
3886
		if (!dialog->udptl) {

   
3887
			/* t38pt_udptl was enabled in the peer and not in [general] */
4711
		/* t38pt_udptl was enabled in the peer and not in [general] */
3888
			dialog->udptl = ast_udptl_new_with_bindaddr(sched, io, 0, bindaddr.sin_addr);
4712
		if (dialog->udptl || (!dialog->udptl && (dialog->udptl = ast_udptl_new_with_bindaddr(sched, io, 0, bindaddr.sin_addr)))) {
3889
		}

   
3890
		dialog->t38_maxdatagram = peer->t38_maxdatagram;
4713
			dialog->t38_maxdatagram = peer->t38_maxdatagram;
3891
		set_t38_capabilities(dialog);
4714
			set_t38_capabilities(dialog);

    
   
4715
		} else {

    
   
4716
			/* It is impossible to support T38 without udptl */

    
   
4717
			ast_debug(1, "UDPTL creation failed on dialog.\n");

    
   
4718
			ast_clear_flag(&dialog->flags[1], SIP_PAGE2_T38SUPPORT);

    
   
4719
		}
3892
	} else if (dialog->udptl) {
4720
	} else if (dialog->udptl) {
3893
		ast_udptl_destroy(dialog->udptl);
4721
		ast_udptl_destroy(dialog->udptl);
3894
		dialog->udptl = NULL;
4722
		dialog->udptl = NULL;
3895
	}
4723
	}
3896

    
   
4724

   
[+20] [20] 32 lines
[+20] static int create_addr_from_peer(struct sip_pvt *dialog, struct sip_peer *peer)
3929
	ast_string_field_set(dialog, fullcontact, peer->fullcontact);
4757
	ast_string_field_set(dialog, fullcontact, peer->fullcontact);
3930
	ast_string_field_set(dialog, accountcode, peer->accountcode);
4758
	ast_string_field_set(dialog, accountcode, peer->accountcode);
3931
	ast_string_field_set(dialog, context, peer->context);
4759
	ast_string_field_set(dialog, context, peer->context);
3932
	ast_string_field_set(dialog, cid_num, peer->cid_num);
4760
	ast_string_field_set(dialog, cid_num, peer->cid_num);
3933
	ast_string_field_set(dialog, cid_name, peer->cid_name);
4761
	ast_string_field_set(dialog, cid_name, peer->cid_name);

    
   
4762
	ast_string_field_set(dialog, cid_tag, peer->cid_tag);
3934
	ast_string_field_set(dialog, mwi_from, peer->mwi_from);
4763
	ast_string_field_set(dialog, mwi_from, peer->mwi_from);
3935
	ast_string_field_set(dialog, parkinglot, peer->parkinglot);
4764
	ast_string_field_set(dialog, parkinglot, peer->parkinglot);
3936
	ast_string_field_set(dialog, engine, peer->engine);
4765
	ast_string_field_set(dialog, engine, peer->engine);
3937
	ref_proxy(dialog, obproxy_get(dialog, peer));
4766
	ref_proxy(dialog, obproxy_get(dialog, peer));
3938
	dialog->callgroup = peer->callgroup;
4767
	dialog->callgroup = peer->callgroup;
3939
	dialog->pickupgroup = peer->pickupgroup;
4768
	dialog->pickupgroup = peer->pickupgroup;
3940
	dialog->allowtransfer = peer->allowtransfer;
4769
	dialog->allowtransfer = peer->allowtransfer;
3941
	dialog->jointnoncodeccapability = dialog->noncodeccapability;
4770
	dialog->jointnoncodeccapability = dialog->noncodeccapability;
3942
	dialog->rtptimeout = peer->rtptimeout;
4771
	dialog->rtptimeout = peer->rtptimeout;
3943
	dialog->peerauth = peer->auth;
4772
	dialog->peerauth = peer->auth;
3944
	dialog->maxcallbitrate = peer->maxcallbitrate;
4773
	dialog->maxcallbitrate = peer->maxcallbitrate;
3945
	dialog->disallowed_methods = peer->disallowed_methods;
4774
	dialog->disallowed_methods = peer->disallowed_methods;

    
   
4775
	ast_cc_copy_config_params(dialog->cc_params, peer->cc_params);
3946
	if (ast_strlen_zero(dialog->tohost))
4776
	if (ast_strlen_zero(dialog->tohost))
3947
		ast_string_field_set(dialog, tohost, ast_inet_ntoa(dialog->sa.sin_addr));
4777
		ast_string_field_set(dialog, tohost, ast_inet_ntoa(dialog->sa.sin_addr));
3948
	if (!ast_strlen_zero(peer->fromdomain)) {
4778
	if (!ast_strlen_zero(peer->fromdomain)) {
3949
		ast_string_field_set(dialog, fromdomain, peer->fromdomain);
4779
		ast_string_field_set(dialog, fromdomain, peer->fromdomain);
3950
		if (!dialog->initreq.headers) {
4780
		if (!dialog->initreq.headers) {
[+20] [20] 32 lines
[+20] static int create_addr_from_peer(struct sip_pvt *dialog, struct sip_peer *peer)
3983
	if ((ast_test_flag(&dialog->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833) ||
4813
	if ((ast_test_flag(&dialog->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833) ||
3984
	    (ast_test_flag(&dialog->flags[0], SIP_DTMF) == SIP_DTMF_AUTO))
4814
	    (ast_test_flag(&dialog->flags[0], SIP_DTMF) == SIP_DTMF_AUTO))
3985
		dialog->noncodeccapability |= AST_RTP_DTMF;
4815
		dialog->noncodeccapability |= AST_RTP_DTMF;
3986
	else
4816
	else
3987
		dialog->noncodeccapability &= ~AST_RTP_DTMF;
4817
		dialog->noncodeccapability &= ~AST_RTP_DTMF;

    
   
4818
	dialog->directmediaha = ast_duplicate_ha_list(peer->directmediaha);
3988
	if (peer->call_limit)
4819
	if (peer->call_limit)
3989
		ast_set_flag(&dialog->flags[0], SIP_CALL_LIMIT);
4820
		ast_set_flag(&dialog->flags[0], SIP_CALL_LIMIT);
3990
	if (!dialog->portinuri)
4821
	if (!dialog->portinuri)
3991
		dialog->portinuri = peer->portinuri;
4822
		dialog->portinuri = peer->portinuri;
3992
	

   
3993
	dialog->chanvars = copy_vars(peer->chanvars);
4823
	dialog->chanvars = copy_vars(peer->chanvars);

    
   
4824
	if (peer->fromdomainport)

    
   
4825
		dialog->fromdomainport = peer->fromdomainport;
3994

    
   
4826

   
3995
	return 0;
4827
	return 0;
3996
}
4828
}
3997

    
   
4829

   
3998
/*! \brief create address structure from device name
4830
/*! \brief create address structure from device name
3999
 *      Or, if peer not found, find it in the global DNS
4831
 *      Or, if peer not found, find it in the global DNS
4000
 *      returns TRUE (-1) on failure, FALSE on success */
4832
 *      returns TRUE (-1) on failure, FALSE on success */
4001
static int create_addr(struct sip_pvt *dialog, const char *opeer, struct sockaddr_in *sin, int newdialog)
4833
static int create_addr(struct sip_pvt *dialog, const char *opeer, struct sockaddr_in *sin, int newdialog, struct sockaddr_in *remote_address)
4002
{
4834
{
4003
	struct hostent *hp;
4835
	struct hostent *hp;
4004
	struct ast_hostent ahp;
4836
	struct ast_hostent ahp;
4005
	struct sip_peer *peer;
4837
	struct sip_peer *peer;
4006
	char *port;
4838
	char *port;
[+20] [20] 17 lines
[+20] static int create_addr(struct sip_pvt *dialog, const char *opeer, struct sockaddr_in *sin, int newdialog) [+] static int create_addr(struct sip_pvt *dialog, const char *opeer, struct sockaddr_in *sin, int newdialog, struct sockaddr_in *remote_address)
4024
		int res;
4856
		int res;
4025
		if (newdialog) {
4857
		if (newdialog) {
4026
			set_socket_transport(&dialog->socket, 0);
4858
			set_socket_transport(&dialog->socket, 0);
4027
		}
4859
		}
4028
		res = create_addr_from_peer(dialog, peer);
4860
		res = create_addr_from_peer(dialog, peer);
4029
		if (!ast_strlen_zero(port)) {
4861
		if (remote_address && remote_address->sin_addr.s_addr) {

    
   
4862
			dialog->sa = dialog->recv = *remote_address;

    
   
4863
		} else if (!ast_strlen_zero(port)) {
4030
			if ((portno = atoi(port))) {
4864
			if ((portno = atoi(port))) {
4031
				dialog->sa.sin_port = dialog->recv.sin_port = htons(portno);
4865
				dialog->sa.sin_port = dialog->recv.sin_port = htons(portno);
4032
			}
4866
			}
4033
		}
4867
		}
4034
		unref_peer(peer, "create_addr: unref peer from find_peer hashtab lookup");
4868
		unref_peer(peer, "create_addr: unref peer from find_peer hashtab lookup");
[+20] [20] 92 lines
[+20] [+] static int sip_call(struct ast_channel *ast, char *dest, int timeout)
4127
	int res;
4961
	int res;
4128
	struct sip_pvt *p = ast->tech_pvt;	/* chan is locked, so the reference cannot go away */
4962
	struct sip_pvt *p = ast->tech_pvt;	/* chan is locked, so the reference cannot go away */
4129
	struct varshead *headp;
4963
	struct varshead *headp;
4130
	struct ast_var_t *current;
4964
	struct ast_var_t *current;
4131
	const char *referer = NULL;   /* SIP referrer */
4965
	const char *referer = NULL;   /* SIP referrer */

    
   
4966
	int cc_core_id;

    
   
4967
	char uri[SIPBUFSIZE] = "";
4132

    
   
4968

   
4133
	if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) {
4969
	if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) {
4134
		ast_log(LOG_WARNING, "sip_call called on %s, neither down nor reserved\n", ast->name);
4970
		ast_log(LOG_WARNING, "sip_call called on %s, neither down nor reserved\n", ast->name);
4135
		return -1;
4971
		return -1;
4136
	}
4972
	}
4137

    
   
4973

   

    
   
4974
	if (ast_cc_is_recall(ast, &cc_core_id, "SIP")) {

    
   
4975
		char device_name[AST_CHANNEL_NAME];

    
   
4976
		struct ast_cc_monitor *recall_monitor;

    
   
4977
		struct sip_monitor_instance *monitor_instance;

    
   
4978
		ast_channel_get_device_name(ast, device_name, sizeof(device_name));

    
   
4979
		if ((recall_monitor = ast_cc_get_monitor_by_recall_core_id(cc_core_id, device_name))) {

    
   
4980
			monitor_instance = recall_monitor->private_data;

    
   
4981
			ast_copy_string(uri, monitor_instance->notify_uri, sizeof(uri));

    
   
4982
			ao2_t_ref(recall_monitor, -1, "Got the URI we need so unreffing monitor");

    
   
4983
		}

    
   
4984
	}

    
   
4985

   
4138
	/* Check whether there is vxml_url, distinctive ring variables */
4986
	/* Check whether there is vxml_url, distinctive ring variables */
4139
	headp=&ast->varshead;
4987
	headp=&ast->varshead;
4140
	AST_LIST_TRAVERSE(headp, current, entries) {
4988
	AST_LIST_TRAVERSE(headp, current, entries) {
4141
		/* Check whether there is a VXML_URL variable */
4989
		/* Check whether there is a VXML_URL variable */
4142
		if (!p->options->vxml_url && !strcasecmp(ast_var_name(current), "VXML_URL")) {
4990
		if (!p->options->vxml_url && !strcasecmp(ast_var_name(current), "VXML_URL")) {
[+20] [20] 18 lines
[+20] static int sip_call(struct ast_channel *ast, char *dest, int timeout)
4161
	}
5009
	}
4162

    
   
5010

   
4163
	res = 0;
5011
	res = 0;
4164
	ast_set_flag(&p->flags[0], SIP_OUTGOING);
5012
	ast_set_flag(&p->flags[0], SIP_OUTGOING);
4165

    
   
5013

   

    
   
5014
	/* T.38 re-INVITE FAX detection should never be done for outgoing calls,

    
   
5015
	 * so ensure it is disabled.

    
   
5016
	 */

    
   
5017
	ast_clear_flag(&p->flags[1], SIP_PAGE2_FAX_DETECT_T38);

    
   
5018

   
4166
	if (p->options->transfer) {
5019
	if (p->options->transfer) {
4167
		char buf[SIPBUFSIZE/2];
5020
		char buf[SIPBUFSIZE/2];
4168

    
   
5021

   
4169
		if (referer) {
5022
		if (referer) {
4170
			if (sipdebug)
5023
			if (sipdebug)
[+20] [20] 21 lines
[+20] static int sip_call(struct ast_channel *ast, char *dest, int timeout)
4192
		res = -1;
5045
		res = -1;
4193
	} else {
5046
	} else {
4194
		int xmitres;
5047
		int xmitres;
4195

    
   
5048

   
4196
		sip_pvt_lock(p);
5049
		sip_pvt_lock(p);
4197
		xmitres = transmit_invite(p, SIP_INVITE, 1, 2);
5050
		xmitres = transmit_invite(p, SIP_INVITE, 1, 2, uri);
4198
		sip_pvt_unlock(p);
5051
		sip_pvt_unlock(p);
4199
		if (xmitres == XMIT_ERROR)
5052
		if (xmitres == XMIT_ERROR)
4200
			return -1;
5053
			return -1;
4201
		p->invitestate = INV_CALLING;
5054
		p->invitestate = INV_CALLING;
4202

    
   
5055

   
[+20] [20] 157 lines
[+20] [+] void __sip_destroy(struct sip_pvt *p, int lockowner, int lockdialoglist)
4360
	if (p->chanvars) {
5213
	if (p->chanvars) {
4361
		ast_variables_destroy(p->chanvars);
5214
		ast_variables_destroy(p->chanvars);
4362
		p->chanvars = NULL;
5215
		p->chanvars = NULL;
4363
	}
5216
	}
4364

    
   
5217

   

    
   
5218
	if (p->directmediaha) {

    
   
5219
		ast_free_ha(p->directmediaha);

    
   
5220
		p->directmediaha = NULL;

    
   
5221
	}

    
   
5222

   
4365
	ast_string_field_free_memory(p);
5223
	ast_string_field_free_memory(p);
4366

    
   
5224

   

    
   
5225
	ast_cc_config_params_destroy(p->cc_params);

    
   
5226

   

    
   
5227
	if (p->epa_entry) {

    
   
5228
		ao2_ref(p->epa_entry, -1);

    
   
5229
		p->epa_entry = NULL;

    
   
5230
	}

    
   
5231

   
4367
	if (p->socket.tcptls_session) {
5232
	if (p->socket.tcptls_session) {
4368
		ao2_ref(p->socket.tcptls_session, -1);
5233
		ao2_ref(p->socket.tcptls_session, -1);
4369
		p->socket.tcptls_session = NULL;
5234
		p->socket.tcptls_session = NULL;
4370
	}
5235
	}
4371
}
5236
}
[+20] [20] 463 lines
[+20] [+] static int sip_hangup(struct ast_channel *ast)
4835
					needdestroy = 0;
5700
					needdestroy = 0;
4836
					sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
5701
					sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
4837
				}
5702
				}
4838
			} else {	/* Incoming call, not up */
5703
			} else {	/* Incoming call, not up */
4839
				const char *res;
5704
				const char *res;
4840
				AST_SCHED_DEL(sched, p->provisional_keepalive_sched_id);
5705
				AST_SCHED_DEL_UNREF(sched, p->provisional_keepalive_sched_id, dialog_unref(p, "when you delete the provisional_keepalive_sched_id, you should dec the refcount for the stored dialog ptr"));
4841
				if (p->hangupcause && (res = hangup_cause2sip(p->hangupcause)))
5706
				if (p->hangupcause && (res = hangup_cause2sip(p->hangupcause)))
4842
					transmit_response_reliable(p, res, &p->initreq);
5707
					transmit_response_reliable(p, res, &p->initreq);
4843
				else
5708
				else
4844
					transmit_response_reliable(p, "603 Declined", &p->initreq);
5709
					transmit_response_reliable(p, "603 Declined", &p->initreq);
4845
				p->invitestate = INV_TERMINATED;
5710
				p->invitestate = INV_TERMINATED;
[+20] [20] 351 lines
[+20] [+] static int sip_transfer(struct ast_channel *ast, const char *dest)
5197
	sip_pvt_unlock(p);
6062
	sip_pvt_unlock(p);
5198
	return res;
6063
	return res;
5199
}
6064
}
5200

    
   
6065

   
5201
/*! \brief Helper function which updates T.38 capability information and triggers a reinvite */
6066
/*! \brief Helper function which updates T.38 capability information and triggers a reinvite */
5202
static void interpret_t38_parameters(struct sip_pvt *p, const struct ast_control_t38_parameters *parameters)
6067
static int interpret_t38_parameters(struct sip_pvt *p, const struct ast_control_t38_parameters *parameters)
5203
{
6068
{
5204
	if (!ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT)) {
6069
	int res = 0;
5205
		return;
6070

   

    
   
6071
	if (!ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT) || !p->udptl) {

    
   
6072
		return -1;
5206
	}
6073
	}
5207
	switch (parameters->request_response) {
6074
	switch (parameters->request_response) {
5208
	case AST_T38_NEGOTIATED:
6075
	case AST_T38_NEGOTIATED:
5209
	case AST_T38_REQUEST_NEGOTIATE:         /* Request T38 */
6076
	case AST_T38_REQUEST_NEGOTIATE:         /* Request T38 */
5210
		/* Negotiation can not take place without a valid max_ifp value. */
6077
		/* Negotiation can not take place without a valid max_ifp value. */
[+20] [20] 43 lines
[+20] static void interpret_t38_parameters(struct sip_pvt *p, const struct ast_control_t38_parameters *parameters) [+] static int interpret_t38_parameters(struct sip_pvt *p, const struct ast_control_t38_parameters *parameters)
5254
			change_t38_state(p, T38_DISABLED);
6121
			change_t38_state(p, T38_DISABLED);
5255
			transmit_response_reliable(p, "488 Not acceptable here", &p->initreq);
6122
			transmit_response_reliable(p, "488 Not acceptable here", &p->initreq);
5256
		} else if (p->t38.state == T38_ENABLED)
6123
		} else if (p->t38.state == T38_ENABLED)
5257
			transmit_reinvite_with_sdp(p, FALSE, FALSE);
6124
			transmit_reinvite_with_sdp(p, FALSE, FALSE);
5258
		break;
6125
		break;

    
   
6126
	case AST_T38_REQUEST_PARMS: {		/* Application wants remote's parameters re-sent */

    
   
6127
		struct ast_control_t38_parameters parameters = p->t38.their_parms;

    
   
6128

   

    
   
6129
		if (p->t38.state == T38_PEER_REINVITE) {

    
   
6130
			AST_SCHED_DEL(sched, p->t38id);

    
   
6131
			parameters.max_ifp = ast_udptl_get_far_max_ifp(p->udptl);

    
   
6132
			parameters.request_response = AST_T38_REQUEST_NEGOTIATE;

    
   
6133
			ast_queue_control_data(p->owner, AST_CONTROL_T38_PARAMETERS, &parameters, sizeof(parameters));

    
   
6134
			/* we need to return a positive value here, so that applications that

    
   
6135
			 * send this request can determine conclusively whether it was accepted or not...

    
   
6136
			 * older versions of chan_sip would just silently accept it and return zero.

    
   
6137
			 */

    
   
6138
			res = AST_T38_REQUEST_PARMS;

    
   
6139
		}

    
   
6140
		break;

    
   
6141
	}
5259
	default:
6142
	default:

    
   
6143
		res = -1;
5260
		break;
6144
		break;
5261
	}
6145
	}

    
   
6146

   

    
   
6147
	return res;
5262
}
6148
}
5263

    
   
6149

   
5264
/*! \brief Play indication to user
6150
/*! \brief Play indication to user
5265
 * With SIP a lot of indications is sent as messages, letting the device play
6151
 * With SIP a lot of indications is sent as messages, letting the device play
5266
   the indication - busy signal, congestion etc
6152
   the indication - busy signal, congestion etc
[+20] [20] 79 lines
[+20] [+] static int sip_indicate(struct ast_channel *ast, int condition, const void *data, size_t datalen)
5346
			res = -1;
6232
			res = -1;
5347
		break;
6233
		break;
5348
	case AST_CONTROL_T38_PARAMETERS:
6234
	case AST_CONTROL_T38_PARAMETERS:
5349
		if (datalen != sizeof(struct ast_control_t38_parameters)) {
6235
		if (datalen != sizeof(struct ast_control_t38_parameters)) {
5350
			ast_log(LOG_ERROR, "Invalid datalen for AST_CONTROL_T38_PARAMETERS. Expected %d, got %d\n", (int) sizeof(struct ast_control_t38_parameters), (int) datalen);
6236
			ast_log(LOG_ERROR, "Invalid datalen for AST_CONTROL_T38_PARAMETERS. Expected %d, got %d\n", (int) sizeof(struct ast_control_t38_parameters), (int) datalen);

    
   
6237
			res = -1;
5351
		} else {
6238
		} else {
5352
			const struct ast_control_t38_parameters *parameters = data;
6239
			const struct ast_control_t38_parameters *parameters = data;
5353
			interpret_t38_parameters(p, parameters);
6240
			res = interpret_t38_parameters(p, parameters);
5354
		}
6241
		}
5355
		break;
6242
		break;
5356
	case AST_CONTROL_SRCUPDATE:
6243
	case AST_CONTROL_SRCUPDATE:
5357
		ast_rtp_instance_update_source(p->rtp);
6244
		ast_rtp_instance_update_source(p->rtp);
5358
		break;
6245
		break;
[+20] [20] 4 lines
[+20] static int sip_indicate(struct ast_channel *ast, int condition, const void *data, size_t datalen)
5363
		update_connectedline(p, data, datalen);
6250
		update_connectedline(p, data, datalen);
5364
		break;
6251
		break;
5365
	case AST_CONTROL_REDIRECTING:
6252
	case AST_CONTROL_REDIRECTING:
5366
		update_redirecting(p, data, datalen);
6253
		update_redirecting(p, data, datalen);
5367
		break;
6254
		break;
5368
	case -1:
6255
	case AST_CONTROL_AOC:
5369
		res = -1;
6256
		{
5370
		break;
6257
			struct ast_aoc_decoded *decoded = ast_aoc_decode((struct ast_aoc_encoded *) data, datalen, ast);
5371
	default:
6258
			if (!decoded) {
5372
		ast_log(LOG_WARNING, "Don't know how to indicate condition %d\n", condition);
6259
				ast_log(LOG_ERROR, "Error decoding indicated AOC data\n");
5373
		res = -1;
6260
				res = -1;
5374
		break;
6261
				break;
5375
	}
6262
			}
5376
	sip_pvt_unlock(p);
6263
			switch (ast_aoc_get_msg_type(decoded)) {
5377
	return res;
6264
			case AST_AOC_REQUEST:

    
   
6265
				if (ast_aoc_get_termination_request(decoded)) {

    
   
6266
					/* TODO, once there is a way to get AOC-E on hangup, attempt that here

    
   
6267
					 * before hanging up the channel.*/

    
   
6268

   

    
   
6269
					/* The other side has already initiated the hangup. This frame

    
   
6270
					 * just says they are waiting to get AOC-E before completely tearing

    
   
6271
					 * the call down.  Since SIP does not support this at the moment go

    
   
6272
					 * ahead and terminate the call here to avoid an unnecessary timeout. */

    
   
6273
					ast_log(LOG_DEBUG, "AOC-E termination request received on %s. This is not yet supported on sip. Continue with hangup \n", p->owner->name);

    
   
6274
					ast_softhangup_nolock(p->owner, AST_SOFTHANGUP_DEV);
5378
}
6275
				}
5379

    
   
6276
				break;
5380
/*! \brief Initiate a call in the SIP channel
6277
			case AST_AOC_D:
5381
	called from sip_request_call (calls from the pbx ) for outbound channels
6278
			case AST_AOC_E:
5382
	and from handle_request_invite for inbound channels
6279
				if (ast_test_flag(&p->flags[2], SIP_PAGE3_SNOM_AOC)) {
5383
	
6280
					transmit_info_with_aoc(p, decoded);
5384
*/
6281
				}
5385
static struct ast_channel *sip_new(struct sip_pvt *i, int state, const char *title, const char *linkedid)
6282
				break;
5386
{
6283
			case AST_AOC_S: /* S not supported yet */
5387
	struct ast_channel *tmp;
6284
			default:
5388
	struct ast_variable *v = NULL;
6285
				break;
5389
	format_t fmt;
Moved to 6311

   
5390
	format_t what;
Moved to 6312

   
5391
	format_t video;
Moved to 6313

   
5392
	format_t text;
Moved to 6314

   
5393
	format_t needvideo = 0;
Moved to 6315

   
5394
	int needtext = 0;
Moved to 6316

   
5395
	char buf[SIPBUFSIZE];
Moved to 6317

   
5396
	char *decoded_exten;
Moved to 6318

   
5397

    
   

   
5398
	{

   
5399
		const char *my_name;	/* pick a good name */

   
5400
	

   
5401
		if (title) {

   
5402
			my_name = title;

   
5403
		} else {

   
5404
			char *port = NULL;

   
5405
			my_name = ast_strdupa(i->fromdomain);

   
5406
			if ((port = strchr(i->fromdomain, ':'))) {

   
5407
				*port = '\0';

   
5408
			}
6286
			}

    
   
6287
			ast_aoc_destroy_decoded(decoded);

    
   
6288
		}

    
   
6289
		break;

    
   
6290
	case -1:

    
   
6291
		res = -1;

    
   
6292
		break;

    
   
6293
	default:

    
   
6294
		ast_log(LOG_WARNING, "Don't know how to indicate condition %d\n", condition);

    
   
6295
		res = -1;

    
   
6296
		break;

    
   
6297
	}

    
   
6298
	sip_pvt_unlock(p);

    
   
6299
	return res;

    
   
6300
}

    
   
6301

   

    
   
6302
/*! \brief Initiate a call in the SIP channel

    
   
6303
	called from sip_request_call (calls from the pbx ) for outbound channels

    
   
6304
	and from handle_request_invite for inbound channels

    
   
6305
	

    
   
6306
*/

    
   
6307
static struct ast_channel *sip_new(struct sip_pvt *i, int state, const char *title, const char *linkedid)

    
   
6308
{

    
   
6309
	struct ast_channel *tmp;

    
   
6310
	struct ast_variable *v = NULL;
Moved from 5389

    
   
6311
	format_t fmt;
Moved from 5390

    
   
6312
	format_t what;
Moved from 5391

    
   
6313
	format_t video;
Moved from 5392

    
   
6314
	format_t text;
Moved from 5393

    
   
6315
	format_t needvideo = 0;
Moved from 5394

    
   
6316
	int needtext = 0;
Moved from 5395

    
   
6317
	char buf[SIPBUFSIZE];
Moved from 5396

    
   
6318
	char *decoded_exten;

    
   
6319

   

    
   
6320
	{

    
   
6321
		const char *my_name;	/* pick a good name */

    
   
6322
	

    
   
6323
		if (title) {

    
   
6324
			my_name = title;

    
   
6325
		} else {

    
   
6326
			my_name = ast_strdupa(i->fromdomain);
5409
		}
6327
		}
5410

    
   
6328

   
5411
		sip_pvt_unlock(i);
6329
		sip_pvt_unlock(i);
5412
		/* Don't hold a sip pvt lock while we allocate a channel */
6330
		/* Don't hold a sip pvt lock while we allocate a channel */
5413
		tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, i->accountcode, i->exten, i->context, linkedid, i->amaflags, "SIP/%s-%08x", my_name, ast_atomic_fetchadd_int((int *)&chan_idx, +1));
6331
		tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, i->accountcode, i->exten, i->context, linkedid, i->amaflags, "SIP/%s-%08x", my_name, ast_atomic_fetchadd_int((int *)&chan_idx, +1));
5414
	}
6332
	}
5415
	if (!tmp) {
6333
	if (!tmp) {
5416
		ast_log(LOG_WARNING, "Unable to allocate AST channel structure for SIP channel\n");
6334
		ast_log(LOG_WARNING, "Unable to allocate AST channel structure for SIP channel\n");
5417
		sip_pvt_lock(i);
6335
		sip_pvt_lock(i);
5418
		return NULL;
6336
		return NULL;
5419
	}
6337
	}

    
   
6338
	ast_channel_lock(tmp);
5420
	sip_pvt_lock(i);
6339
	sip_pvt_lock(i);

    
   
6340
	ast_channel_cc_params_init(tmp, i->cc_params);

    
   
6341
	tmp->cid.cid_tag = ast_strdup(i->cid_tag);

    
   
6342
	ast_channel_unlock(tmp);
5421

    
   
6343

   
5422
	tmp->tech = ( ast_test_flag(&i->flags[0], SIP_DTMF) == SIP_DTMF_INFO || ast_test_flag(&i->flags[0], SIP_DTMF) == SIP_DTMF_SHORTINFO) ?  &sip_tech_info : &sip_tech;
6344
	tmp->tech = ( ast_test_flag(&i->flags[0], SIP_DTMF) == SIP_DTMF_INFO || ast_test_flag(&i->flags[0], SIP_DTMF) == SIP_DTMF_SHORTINFO) ?  &sip_tech_info : &sip_tech;
5423

    
   
6345

   
5424
	/* Select our native format based on codec preference until we receive
6346
	/* Select our native format based on codec preference until we receive
5425
	   something from another device to the contrary. */
6347
	   something from another device to the contrary. */
[+20] [20] 113 lines
[+20] static struct ast_channel *sip_new(struct sip_pvt *i, int state, const char *title, const char *linkedid)
5539

    
   
6461

   
5540
	/* Don't use ast_set_callerid() here because it will
6462
	/* Don't use ast_set_callerid() here because it will
5541
	 * generate an unnecessary NewCallerID event  */
6463
	 * generate an unnecessary NewCallerID event  */
5542
	tmp->cid.cid_ani = ast_strdup(i->cid_num);
6464
	tmp->cid.cid_ani = ast_strdup(i->cid_num);
5543
	if (!ast_strlen_zero(i->rdnis))
6465
	if (!ast_strlen_zero(i->rdnis))
5544
		tmp->cid.cid_rdnis = ast_strdup(i->rdnis);
6466
		tmp->redirecting.from.number = ast_strdup(i->rdnis);
5545
	
6467
	
5546
	if (!ast_strlen_zero(i->exten) && strcmp(i->exten, "s"))
6468
	if (!ast_strlen_zero(i->exten) && strcmp(i->exten, "s"))
5547
		tmp->cid.cid_dnid = ast_strdup(i->exten);
6469
		tmp->cid.cid_dnid = ast_strdup(i->exten);
5548

    
   
6470

   
5549
	tmp->priority = 1;
6471
	tmp->priority = 1;
[+20] [20] 286 lines
[+20] [+] static struct ast_frame *sip_read(struct ast_channel *ast)
5836
	sip_pvt_lock(p);
6758
	sip_pvt_lock(p);
5837
	fr = sip_rtp_read(ast, p, &faxdetected);
6759
	fr = sip_rtp_read(ast, p, &faxdetected);
5838
	p->lastrtprx = time(NULL);
6760
	p->lastrtprx = time(NULL);
5839

    
   
6761

   
5840
	/* If we detect a CNG tone and fax detection is enabled then send us off to the fax extension */
6762
	/* If we detect a CNG tone and fax detection is enabled then send us off to the fax extension */
5841
	if (faxdetected && ast_test_flag(&p->flags[1], SIP_PAGE2_FAX_DETECT)) {
6763
	if (faxdetected && ast_test_flag(&p->flags[1], SIP_PAGE2_FAX_DETECT_CNG)) {
5842
		ast_channel_lock(ast);
6764
		ast_channel_lock(ast);
5843
		if (strcmp(ast->exten, "fax")) {
6765
		if (strcmp(ast->exten, "fax")) {
5844
			const char *target_context = S_OR(ast->macrocontext, ast->context);
6766
			const char *target_context = S_OR(ast->macrocontext, ast->context);
5845
			ast_channel_unlock(ast);
6767
			ast_channel_unlock(ast);
5846
			if (ast_exists_extension(ast, target_context, "fax", 1, ast->cid.cid_num)) {
6768
			if (ast_exists_extension(ast, target_context, "fax", 1, ast->cid.cid_num)) {
5847
				ast_verbose(VERBOSE_PREFIX_2 "Redirecting '%s' to fax extension\n", ast->name);
6769
				ast_verbose(VERBOSE_PREFIX_2 "Redirecting '%s' to fax extension due to CNG detection\n", ast->name);
5848
				pbx_builtin_setvar_helper(ast, "FAXEXTEN", ast->exten);
6770
				pbx_builtin_setvar_helper(ast, "FAXEXTEN", ast->exten);
5849
				if (ast_async_goto(ast, target_context, "fax", 1)) {
6771
				if (ast_async_goto(ast, target_context, "fax", 1)) {
5850
					ast_log(LOG_NOTICE, "Failed to async goto '%s' into fax of '%s'\n", ast->name, target_context);
6772
					ast_log(LOG_NOTICE, "Failed to async goto '%s' into fax of '%s'\n", ast->name, target_context);
5851
				}
6773
				}
5852
				fr = &ast_null_frame;
6774
				fr = &ast_null_frame;
5853
			} else {
6775
			} else {
5854
				ast_log(LOG_NOTICE, "Fax detected but no fax extension\n");
6776
				ast_log(LOG_NOTICE, "FAX CNG detected but no fax extension\n");
5855
                        }
6777
                        }
5856
		} else {
6778
		} else {
5857
			ast_channel_unlock(ast);
6779
			ast_channel_unlock(ast);
5858
                }
6780
                }
5859
        }
6781
        }
[+20] [20] 20 lines
[+20] [+] static char *generate_random_string(char *buf, size_t size)
5880
	snprintf(buf, size, "%08lx%08lx%08lx%08lx", val[0], val[1], val[2], val[3]);
6802
	snprintf(buf, size, "%08lx%08lx%08lx%08lx", val[0], val[1], val[2], val[3]);
5881

    
   
6803

   
5882
	return buf;
6804
	return buf;
5883
}
6805
}
5884

    
   
6806

   

    
   
6807
static char *generate_uri(struct sip_pvt *pvt, char *buf, size_t size)

    
   
6808
{

    
   
6809
	struct ast_str *uri = ast_str_alloca(size);

    
   
6810
	int ourport = ntohs(pvt->ourip.sin_port);

    
   
6811
	ast_str_set(&uri, 0, "%s", pvt->socket.type == SIP_TRANSPORT_TLS ? "sips:" : "sip:");

    
   
6812
	/* Here would be a great place to generate a UUID, but for now we'll

    
   
6813
	 * use the handy random string generation function we already have

    
   
6814
	 */

    
   
6815
	ast_str_append(&uri, 0, "%s", generate_random_string(buf, size));

    
   
6816
	ast_str_append(&uri, 0, "@%s", ast_inet_ntoa(pvt->ourip.sin_addr));

    
   
6817
	if (!sip_standard_port(pvt->socket.type, ourport)) {

    
   
6818
		ast_str_append(&uri, 0, ":%d", ourport);

    
   
6819
	}

    
   
6820
	ast_copy_string(buf, ast_str_buffer(uri), size);

    
   
6821
	return buf;

    
   
6822
}

    
   
6823

   
5885
/*! \brief Build SIP Call-ID value for a non-REGISTER transaction */
6824
/*! \brief Build SIP Call-ID value for a non-REGISTER transaction */
5886
static void build_callid_pvt(struct sip_pvt *pvt)
6825
static void build_callid_pvt(struct sip_pvt *pvt)
5887
{
6826
{
5888
	char buf[33];
6827
	char buf[33];
5889

    
   
6828

   
[+20] [20] 54 lines
[+20] [+] struct sip_pvt *sip_alloc(ast_string_field callid, struct sockaddr_in *sin,
5944
	if (ast_string_field_init(p, 512)) {
6883
	if (ast_string_field_init(p, 512)) {
5945
		ao2_t_ref(p, -1, "failed to string_field_init, drop p");
6884
		ao2_t_ref(p, -1, "failed to string_field_init, drop p");
5946
		return NULL;
6885
		return NULL;
5947
	}
6886
	}
5948

    
   
6887

   

    
   
6888
	if (!(p->cc_params = ast_cc_config_params_init())) {

    
   
6889
		ao2_t_ref(p, -1, "Yuck, couldn't allocate cc_params struct. Get rid o' p");

    
   
6890
		return NULL;

    
   
6891
	}

    
   
6892

   
5949
	if (req) {
6893
	if (req) {
5950
		set_socket_transport(&p->socket, req->socket.type); /* Later in ast_sip_ouraddrfor we need this to choose the right ip and port for the specific transport */
6894
		set_socket_transport(&p->socket, req->socket.type); /* Later in ast_sip_ouraddrfor we need this to choose the right ip and port for the specific transport */
5951
	} else {
6895
	} else {
5952
		set_socket_transport(&p->socket, SIP_TRANSPORT_UDP);
6896
		set_socket_transport(&p->socket, SIP_TRANSPORT_UDP);
5953
	}
6897
	}
[+20] [20] 26 lines
[+20] struct sip_pvt *sip_alloc(ast_string_field callid, struct sockaddr_in *sin,
5980
	}
6924
	}
5981

    
   
6925

   
5982
	/* Copy global flags to this PVT at setup. */
6926
	/* Copy global flags to this PVT at setup. */
5983
	ast_copy_flags(&p->flags[0], &global_flags[0], SIP_FLAGS_TO_COPY);
6927
	ast_copy_flags(&p->flags[0], &global_flags[0], SIP_FLAGS_TO_COPY);
5984
	ast_copy_flags(&p->flags[1], &global_flags[1], SIP_PAGE2_FLAGS_TO_COPY);
6928
	ast_copy_flags(&p->flags[1], &global_flags[1], SIP_PAGE2_FLAGS_TO_COPY);

    
   
6929
	ast_copy_flags(&p->flags[2], &global_flags[2], SIP_PAGE3_FLAGS_TO_COPY);
5985

    
   
6930

   
5986
	p->do_history = recordhistory;
6931
	p->do_history = recordhistory;
5987

    
   
6932

   
5988
	p->branch = ast_random();	
6933
	p->branch = ast_random();	
5989
	make_our_tag(p->tag, sizeof(p->tag));
6934
	make_our_tag(p->tag, sizeof(p->tag));
5990
	p->ocseq = INITIAL_CSEQ;
6935
	p->ocseq = INITIAL_CSEQ;
5991
	p->allowed_methods = UINT_MAX;
6936
	p->allowed_methods = UINT_MAX;
5992

    
   
6937

   
5993
	if (sip_methods[intended_method].need_rtp) {
6938
	if (sip_methods[intended_method].need_rtp) {
5994
		if (ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT) && (p->udptl = ast_udptl_new_with_bindaddr(sched, io, 0, bindaddr.sin_addr))) {
6939
		if (ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT)) {

    
   
6940
			if ((p->udptl = ast_udptl_new_with_bindaddr(sched, io, 0, bindaddr.sin_addr))) {
5995
			ast_udptl_setqos(p->udptl, global_tos_audio, global_cos_audio);
6941
				ast_udptl_setqos(p->udptl, global_tos_audio, global_cos_audio);
5996
			p->t38_maxdatagram = global_t38_maxdatagram;
6942
				p->t38_maxdatagram = global_t38_maxdatagram;

    
   
6943
			} else {

    
   
6944
				/* udptl creation failed, T38 can not be supported on this dialog */

    
   
6945
				ast_log(LOG_ERROR, "UDPTL creation failed\n");

    
   
6946
				ast_clear_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT);

    
   
6947
			}
5997
		}
6948
		}
5998
		p->maxcallbitrate = default_maxcallbitrate;
6949
		p->maxcallbitrate = default_maxcallbitrate;
5999
		p->autoframing = global_autoframing;
6950
		p->autoframing = global_autoframing;
6000
	}
6951
	}
6001

    
   
6952

   
6002
	if (useglobal_nat && sin) {
6953
	if (useglobal_nat && sin) {
6003
		/* Setup NAT structure according to global settings if we have an address */
6954
		/* Setup NAT structure according to global settings if we have an address */
6004
		ast_copy_flags(&p->flags[0], &global_flags[0], SIP_NAT_FORCE_RPORT);
6955
		ast_copy_flags(&p->flags[0], &global_flags[0], SIP_NAT_FORCE_RPORT);
6005
		p->recv = *sin;
6956
		p->recv = *sin;
6006
		do_setnat(p);
6957
		do_setnat(p);
6007
	}
6958
	}
6008

    
   
6959

   
6009
	if (p->method != SIP_REGISTER)
6960
	if (p->method != SIP_REGISTER) {
6010
		ast_string_field_set(p, fromdomain, default_fromdomain);
6961
		ast_string_field_set(p, fromdomain, default_fromdomain);

    
   
6962
		p->fromdomainport = default_fromdomainport;

    
   
6963
	}
6011
	build_via(p);
6964
	build_via(p);
6012
	if (!callid)
6965
	if (!callid)
6013
		build_callid_pvt(p);
6966
		build_callid_pvt(p);
6014
	else
6967
	else
6015
		ast_string_field_set(p, callid, callid);
6968
		ast_string_field_set(p, callid, callid);
[+20] [20] 1088 lines
[+20] [+] static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action)
7104
			tsin.sin_family = AF_INET;
8057
			tsin.sin_family = AF_INET;
7105
			tsin.sin_port = htons(tportno);
8058
			tsin.sin_port = htons(tportno);
7106
			memcpy(&tsin.sin_addr, thp->h_addr, sizeof(tsin.sin_addr));
8059
			memcpy(&tsin.sin_addr, thp->h_addr, sizeof(tsin.sin_addr));
7107
			ast_rtp_instance_set_remote_address(p->trtp, &tsin);
8060
			ast_rtp_instance_set_remote_address(p->trtp, &tsin);
7108
			if (debug) 
8061
			if (debug) 
7109
				ast_verbose("Peer T.140 RTP is at port %s:%d\n", ast_inet_ntoa(vsin.sin_addr), ntohs(vsin.sin_port));
8062
				ast_verbose("Peer T.140 RTP is at port %s:%d\n", ast_inet_ntoa(tsin.sin_addr), ntohs(tsin.sin_port));
7110
			if ((p->jointcapability & AST_FORMAT_T140RED)) {
8063
			if ((p->jointcapability & AST_FORMAT_T140RED)) {
7111
				p->red = 1;
8064
				p->red = 1;
7112
				ast_rtp_red_init(p->trtp, 300, red_data_pt, 2);
8065
				ast_rtp_red_init(p->trtp, 300, red_data_pt, 2);
7113
			} else {
8066
			} else {
7114
				p->red = 0;
8067
				p->red = 0;
[+20] [20] 18 lines
[+20] static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action)
7133
					if (debug) {
8086
					if (debug) {
7134
						ast_log(LOG_DEBUG, "Peer T.38 UDPTL is set behind NAT and with destination, destination address now %s\n", ast_inet_ntoa(isin.sin_addr));
8087
						ast_log(LOG_DEBUG, "Peer T.38 UDPTL is set behind NAT and with destination, destination address now %s\n", ast_inet_ntoa(isin.sin_addr));
7135
					}
8088
					}
7136
				}
8089
				}
7137
			} else {
8090
			} else {
7138
				memcpy(&isin.sin_addr, ihp->h_addr, sizeof(sin.sin_addr));
8091
				memcpy(&isin.sin_addr, ihp->h_addr, sizeof(isin.sin_addr));
7139
			}
8092
			}
7140
			ast_udptl_set_peer(p->udptl, &isin);
8093
			ast_udptl_set_peer(p->udptl, &isin);
7141
			if (debug)
8094
			if (debug)
7142
				ast_debug(1,"Peer T.38 UDPTL is at port %s:%d\n", ast_inet_ntoa(isin.sin_addr), ntohs(isin.sin_port));
8095
				ast_debug(1,"Peer T.38 UDPTL is at port %s:%d\n", ast_inet_ntoa(isin.sin_addr), ntohs(isin.sin_port));
7143

    
   
8096

   
[+20] [20] 8 lines
[+20] static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action)
7152
			    (p->t38.state == T38_LOCAL_REINVITE)) {
8105
			    (p->t38.state == T38_LOCAL_REINVITE)) {
7153
				change_t38_state(p, T38_ENABLED);
8106
				change_t38_state(p, T38_ENABLED);
7154
			} else if ((t38action == SDP_T38_INITIATE) &&
8107
			} else if ((t38action == SDP_T38_INITIATE) &&
7155
				   p->owner && p->lastinvite) {
8108
				   p->owner && p->lastinvite) {
7156
				change_t38_state(p, T38_PEER_REINVITE); /* T38 Offered in re-invite from remote party */
8109
				change_t38_state(p, T38_PEER_REINVITE); /* T38 Offered in re-invite from remote party */

    
   
8110
				/* If fax detection is enabled then send us off to the fax extension */

    
   
8111
				if (ast_test_flag(&p->flags[1], SIP_PAGE2_FAX_DETECT_T38)) {

    
   
8112
					ast_channel_lock(p->owner);

    
   
8113
					if (strcmp(p->owner->exten, "fax")) {

    
   
8114
						const char *target_context = S_OR(p->owner->macrocontext, p->owner->context);

    
   
8115
						ast_channel_unlock(p->owner);

    
   
8116
						if (ast_exists_extension(p->owner, target_context, "fax", 1, p->owner->cid.cid_num)) {

    
   
8117
							ast_verbose(VERBOSE_PREFIX_2 "Redirecting '%s' to fax extension due to peer T.38 re-INVITE\n", p->owner->name);

    
   
8118
							pbx_builtin_setvar_helper(p->owner, "FAXEXTEN", p->owner->exten);

    
   
8119
							if (ast_async_goto(p->owner, target_context, "fax", 1)) {

    
   
8120
								ast_log(LOG_NOTICE, "Failed to async goto '%s' into fax of '%s'\n", p->owner->name, target_context);

    
   
8121
							}

    
   
8122
						} else {

    
   
8123
							ast_log(LOG_NOTICE, "T.38 re-INVITE detected but no fax extension\n");

    
   
8124
						}

    
   
8125
					} else {

    
   
8126
						ast_channel_unlock(p->owner);

    
   
8127
					}

    
   
8128
				}
7157
			}
8129
			}
7158
		} else {
8130
		} else {
7159
			ast_udptl_stop(p->udptl);
8131
			ast_udptl_stop(p->udptl);
7160
			if (debug)
8132
			if (debug)
7161
				ast_debug(1, "Peer doesn't provide T.38 UDPTL\n");
8133
				ast_debug(1, "Peer doesn't provide T.38 UDPTL\n");
[+20] [20] 1022 lines
[+20] [+] static int __transmit_response(struct sip_pvt *p, const char *msg, const struct sip_request *req, enum xmittype reliable)
8184
			&& ast_test_flag(&p->flags[1], SIP_PAGE2_CONNECTLINEUPDATE_PEND)
9156
			&& ast_test_flag(&p->flags[1], SIP_PAGE2_CONNECTLINEUPDATE_PEND)
8185
			&& (!strncmp(msg, "180", 3) || !strncmp(msg, "183", 3))) {
9157
			&& (!strncmp(msg, "180", 3) || !strncmp(msg, "183", 3))) {
8186
		ast_clear_flag(&p->flags[1], SIP_PAGE2_CONNECTLINEUPDATE_PEND);
9158
		ast_clear_flag(&p->flags[1], SIP_PAGE2_CONNECTLINEUPDATE_PEND);
8187
		add_rpid(&resp, p);
9159
		add_rpid(&resp, p);
8188
	}
9160
	}

    
   
9161
	if (ast_test_flag(&p->flags[0], SIP_OFFER_CC)) {

    
   
9162
		add_cc_call_info_to_response(p, &resp);

    
   
9163
	}
8189

    
   
9164

   
8190
	add_header_contentLength(&resp, 0);
9165
	add_header_contentLength(&resp, 0);
8191
	/* If we are cancelling an incoming invite for some reason, add information
9166
	/* If we are cancelling an incoming invite for some reason, add information
8192
		about the reason why we are doing this in clear text */
9167
		about the reason why we are doing this in clear text */
8193
	if (p->method == SIP_INVITE && msg[0] != '1') {
9168
	if (p->method == SIP_INVITE && msg[0] != '1') {
[+20] [20] 25 lines
[+20] static int __transmit_response(struct sip_pvt *p, const char *msg, const struct sip_request *req, enum xmittype reliable)
8219
		}
9194
		}
8220
	}
9195
	}
8221
	return send_response(p, &resp, reliable, seqno);
9196
	return send_response(p, &resp, reliable, seqno);
8222
}
9197
}
8223

    
   
9198

   

    
   
9199
static int transmit_response_with_sip_etag(struct sip_pvt *p, const char *msg, const struct sip_request *req, struct sip_esc_entry *esc_entry, int need_new_etag)

    
   
9200
{

    
   
9201
	struct sip_request resp;

    
   
9202

   

    
   
9203
	if (need_new_etag) {

    
   
9204
		create_new_sip_etag(esc_entry, 1);

    
   
9205
	}

    
   
9206
	respprep(&resp, p, msg, req);

    
   
9207
	add_header(&resp, "SIP-ETag", esc_entry->entity_tag);

    
   
9208

   

    
   
9209
	return send_response(p, &resp, 0, 0);

    
   
9210
}

    
   
9211

   
8224
static int temp_pvt_init(void *data)
9212
static int temp_pvt_init(void *data)
8225
{
9213
{
8226
	struct sip_pvt *p = data;
9214
	struct sip_pvt *p = data;
8227

    
   
9215

   
8228
	p->do_history = 0;	/* XXX do we need it ? isn't already all 0 ? */
9216
	p->do_history = 0;	/* XXX do we need it ? isn't already all 0 ? */
[+20] [20] 45 lines
[+20] [+] 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)
8274
		p->recv = *sin;
9262
		p->recv = *sin;
8275
		do_setnat(p);
9263
		do_setnat(p);
8276
	}
9264
	}
8277

    
   
9265

   
8278
	ast_string_field_set(p, fromdomain, default_fromdomain);
9266
	ast_string_field_set(p, fromdomain, default_fromdomain);

    
   
9267
	p->fromdomainport = default_fromdomainport;
8279
	build_via(p);
9268
	build_via(p);
8280
	ast_string_field_set(p, callid, callid);
9269
	ast_string_field_set(p, callid, callid);
8281

    
   
9270

   
8282
	copy_socket_data(&p->socket, &req->socket);
9271
	copy_socket_data(&p->socket, &req->socket);
8283

    
   
9272

   
[+20] [20] 261 lines
[+20] [+] static int add_rpid(struct sip_request *req, struct sip_pvt *p)
8545

    
   
9534

   
8546
	if (ast_strlen_zero(lid_num))
9535
	if (ast_strlen_zero(lid_num))
8547
		return 0;
9536
		return 0;
8548
	if (ast_strlen_zero(lid_name))
9537
	if (ast_strlen_zero(lid_name))
8549
		lid_name = lid_num;
9538
		lid_name = lid_num;
8550
	fromdomain = S_OR(p->fromdomain, ast_inet_ntoa(p->ourip.sin_addr));
9539
	fromdomain = S_OR(p->fromdomain, ast_strdupa(ast_inet_ntoa(p->ourip.sin_addr)));
8551

    
   
9540

   
8552
	lid_num = ast_uri_encode(lid_num, tmp2, sizeof(tmp2), 1);
9541
	lid_num = ast_uri_encode(lid_num, tmp2, sizeof(tmp2), 1);
8553

    
   
9542

   
8554
	if (ast_test_flag(&p->flags[0], SIP_SENDRPID_PAI)) {
9543
	if (ast_test_flag(&p->flags[0], SIP_SENDRPID_PAI)) {
8555
		if ((lid_pres & AST_PRES_RESTRICTION) != AST_PRES_ALLOWED) {
9544
		if ((lid_pres & AST_PRES_RESTRICTION) != AST_PRES_ALLOWED) {
[+20] [20] 228 lines
[+20] [+] static void add_noncodec_to_sdp(const struct sip_pvt *p, int format,
8784
				  struct sockaddr_in *sin, struct sockaddr_in *vsin, struct sockaddr_in *tsin,
9773
				  struct sockaddr_in *sin, struct sockaddr_in *vsin, struct sockaddr_in *tsin,
8785
				  struct sockaddr_in *dest, struct sockaddr_in *vdest, struct sockaddr_in *tdest)
9774
				  struct sockaddr_in *dest, struct sockaddr_in *vdest, struct sockaddr_in *tdest)
8786
{
9775
{
8787
	/* First, get our address */
9776
	/* First, get our address */
8788
	ast_rtp_instance_get_local_address(p->rtp, sin);
9777
	ast_rtp_instance_get_local_address(p->rtp, sin);
8789
	if (p->ourip.sin_addr.s_addr && (sin->sin_addr.s_addr != p->ourip.sin_addr.s_addr))
9778
	if ((p->ourip.sin_addr.s_addr && (sin->sin_addr.s_addr != p->ourip.sin_addr.s_addr)))
8790
		sin->sin_addr.s_addr = p->ourip.sin_addr.s_addr;
9779
		sin->sin_addr.s_addr = p->ourip.sin_addr.s_addr;
8791
	if (p->vrtp) {
9780
	if (p->vrtp) {
8792
		ast_rtp_instance_get_local_address(p->vrtp, vsin);
9781
		ast_rtp_instance_get_local_address(p->vrtp, vsin);
8793
		if (p->ourip.sin_addr.s_addr && (vsin->sin_addr.s_addr != p->ourip.sin_addr.s_addr))
9782
		if ((p->ourip.sin_addr.s_addr && (vsin->sin_addr.s_addr != p->ourip.sin_addr.s_addr)))
8794
			vsin->sin_addr.s_addr = p->ourip.sin_addr.s_addr;
9783
			vsin->sin_addr.s_addr = p->ourip.sin_addr.s_addr;
8795
	}
9784
	}
8796
	if (p->trtp) {
9785
	if (p->trtp) {
8797
		ast_rtp_instance_get_local_address(p->trtp, tsin);
9786
		ast_rtp_instance_get_local_address(p->trtp, tsin);
8798
		if (p->ourip.sin_addr.s_addr && (tsin->sin_addr.s_addr != p->ourip.sin_addr.s_addr))
9787
		if ((p->ourip.sin_addr.s_addr && (tsin->sin_addr.s_addr != p->ourip.sin_addr.s_addr)))
8799
			tsin->sin_addr.s_addr = p->ourip.sin_addr.s_addr;
9788
			tsin->sin_addr.s_addr = p->ourip.sin_addr.s_addr;
8800
	}
9789
	}
8801

    
   
9790

   
8802
	/* Now, try to figure out where we want them to send data */
9791
	/* Now, try to figure out where we want them to send data */
8803
	/* Is this a re-invite to move the media out, then use the original offer from caller  */
9792
	/* Is this a re-invite to move the media out, then use the original offer from caller  */
[+20] [20] 459 lines
[+20] [+] static void copy_request(struct sip_request *dst, const struct sip_request *src)
9263
		
10252
		
9264
	memcpy(dst->data->str, src->data->str, src->data->used + 1);
10253
	memcpy(dst->data->str, src->data->str, src->data->used + 1);
9265
	dst->data->used = src->data->used;
10254
	dst->data->used = src->data->used;
9266
}
10255
}
9267

    
   
10256

   

    
   
10257
static void add_cc_call_info_to_response(struct sip_pvt *p, struct sip_request *resp)

    
   
10258
{

    
   
10259
	char uri[SIPBUFSIZE];

    
   
10260
	struct ast_str *header = ast_str_alloca(SIPBUFSIZE);

    
   
10261
	struct ast_cc_agent *agent = find_sip_cc_agent_by_original_callid(p);

    
   
10262
	struct sip_cc_agent_pvt *agent_pvt;

    
   
10263

   

    
   
10264
	if (!agent) {

    
   
10265
		/* Um, what? How could the SIP_OFFER_CC flag be set but there not be an

    
   
10266
		 * agent? Oh well, we'll just warn and return without adding the header.

    
   
10267
		 */

    
   
10268
		ast_log(LOG_WARNING, "Can't find SIP CC agent for call '%s' even though OFFER_CC flag was set?\n", p->callid);

    
   
10269
		return;

    
   
10270
	}

    
   
10271

   

    
   
10272
	agent_pvt = agent->private_data;

    
   
10273

   

    
   
10274
	if (!ast_strlen_zero(agent_pvt->subscribe_uri)) {

    
   
10275
		ast_copy_string(uri, agent_pvt->subscribe_uri, sizeof(uri));

    
   
10276
	} else {

    
   
10277
		generate_uri(p, uri, sizeof(uri));

    
   
10278
		ast_copy_string(agent_pvt->subscribe_uri, uri, sizeof(agent_pvt->subscribe_uri));

    
   
10279
	}

    
   
10280
	/* XXX Hardcode "NR" as the m reason for now. This should perhaps be changed

    
   
10281
	 * to be more accurate. This parameter has no bearing on the actual operation

    
   
10282
	 * of the feature; it's just there for informational purposes.

    
   
10283
	 */

    
   
10284
	ast_str_set(&header, 0, "<%s>;purpose=call-completion;m=%s", uri, "NR");

    
   
10285
	add_header(resp, "Call-Info", ast_str_buffer(header));

    
   
10286
	ao2_ref(agent, -1);

    
   
10287
}

    
   
10288

   
9268
/*! \brief Used for 200 OK and 183 early media
10289
/*! \brief Used for 200 OK and 183 early media
9269
	\return Will return XMIT_ERROR for network errors.
10290
	\return Will return XMIT_ERROR for network errors.
9270
*/
10291
*/
9271
static int transmit_response_with_sdp(struct sip_pvt *p, const char *msg, const struct sip_request *req, enum xmittype reliable, int oldsdp, int rpid)
10292
static int transmit_response_with_sdp(struct sip_pvt *p, const char *msg, const struct sip_request *req, enum xmittype reliable, int oldsdp, int rpid)
9272
{
10293
{
[+20] [20] 5 lines
[+20] static int transmit_response_with_sdp(struct sip_pvt *p, const char *msg, const struct sip_request *req, enum xmittype reliable, int oldsdp, int rpid)
9278
	}
10299
	}
9279
	respprep(&resp, p, msg, req);
10300
	respprep(&resp, p, msg, req);
9280
	if (rpid == TRUE) {
10301
	if (rpid == TRUE) {
9281
		add_rpid(&resp, p);
10302
		add_rpid(&resp, p);
9282
	}
10303
	}

    
   
10304
	if (ast_test_flag(&p->flags[0], SIP_OFFER_CC)) {

    
   
10305
		add_cc_call_info_to_response(p, &resp);

    
   
10306
	}
9283
	if (p->rtp) {
10307
	if (p->rtp) {
9284
		if (!p->autoframing && !ast_test_flag(&p->flags[0], SIP_OUTGOING)) {
10308
		if (!p->autoframing && !ast_test_flag(&p->flags[0], SIP_OUTGOING)) {
9285
			ast_debug(1, "Setting framing from config on incoming call\n");
10309
			ast_debug(1, "Setting framing from config on incoming call\n");
9286
			ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(p->rtp), p->rtp, &p->prefs);
10310
			ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(p->rtp), p->rtp, &p->prefs);
9287
		}
10311
		}
[+20] [20] 149 lines
[+20] [+] static void build_contact(struct sip_pvt *p)
9437
			ast_string_field_build(p, our_contact, "<sip:%s%s%s;transport=%s>", p->exten, ast_strlen_zero(p->exten) ? "" : "@", ast_inet_ntoa(p->ourip.sin_addr), get_transport(p->socket.type));
10461
			ast_string_field_build(p, our_contact, "<sip:%s%s%s;transport=%s>", p->exten, ast_strlen_zero(p->exten) ? "" : "@", ast_inet_ntoa(p->ourip.sin_addr), get_transport(p->socket.type));
9438
	}
10462
	}
9439
}
10463
}
9440

    
   
10464

   
9441
/*! \brief Initiate new SIP request to peer/user */
10465
/*! \brief Initiate new SIP request to peer/user */
9442
static void initreqprep(struct sip_request *req, struct sip_pvt *p, int sipmethod)
10466
static void initreqprep(struct sip_request *req, struct sip_pvt *p, int sipmethod, const char * const explicit_uri)
9443
{
10467
{
9444
	struct ast_str *invite = ast_str_alloca(256);
10468
	struct ast_str *invite = ast_str_alloca(256);
9445
	char from[256];
10469
	char from[256];
9446
	char to[256];
10470
	char to[256];
9447
	char tmp_n[SIPBUFSIZE/2];	/* build a local copy of 'n' if needed */
10471
	char tmp_n[SIPBUFSIZE/2];	/* build a local copy of 'n' if needed */
[+20] [20] 68 lines
[+20] static void initreqprep(struct sip_request *req, struct sip_pvt *p, int sipmethod) [+] static void initreqprep(struct sip_request *req, struct sip_pvt *p, int sipmethod, const char * const explicit_uri)
9516
		n = tmp_n;
10540
		n = tmp_n;
9517
		ast_uri_encode(l, tmp_l, sizeof(tmp_l), 0);
10541
		ast_uri_encode(l, tmp_l, sizeof(tmp_l), 0);
9518
		l = tmp_l;
10542
		l = tmp_l;
9519
	}
10543
	}
9520

    
   
10544

   
9521
	ourport = ntohs(p->ourip.sin_port);
10545
	ourport = (p->fromdomainport) ? p->fromdomainport : ntohs(p->ourip.sin_port);
9522
	if (!sip_standard_port(p->socket.type, ourport) && ast_strlen_zero(p->fromdomain))
10546
	if (!sip_standard_port(p->socket.type, ourport))
9523
		snprintf(from, sizeof(from), "\"%s\" <sip:%s@%s:%d>;tag=%s", n, l, d, ourport, p->tag);
10547
		snprintf(from, sizeof(from), "\"%s\" <sip:%s@%s:%d>;tag=%s", n, l, d, ourport, p->tag);
9524
	else
10548
	else
9525
		snprintf(from, sizeof(from), "\"%s\" <sip:%s@%s>;tag=%s", n, l, d, p->tag);
10549
		snprintf(from, sizeof(from), "\"%s\" <sip:%s@%s>;tag=%s", n, l, d, p->tag);
9526

    
   
10550

   

    
   
10551

   

    
   
10552
	if (!ast_strlen_zero(explicit_uri)) {

    
   
10553
		ast_str_set(&invite, 0, "%s", explicit_uri);

    
   
10554
	} else {
9527
	/* If we're calling a registered SIP peer, use the fullcontact to dial to the peer */
10555
		/* If we're calling a registered SIP peer, use the fullcontact to dial to the peer */
9528
	if (!ast_strlen_zero(p->fullcontact)) {
10556
		if (!ast_strlen_zero(p->fullcontact)) {
9529
		/* If we have full contact, trust it */
10557
			/* If we have full contact, trust it */
9530
		ast_str_append(&invite, 0, "%s", p->fullcontact);
10558
			ast_str_append(&invite, 0, "%s", p->fullcontact);
9531
	} else {
10559
		} else {
[+20] [20] 10 lines
[+20] static void initreqprep(struct sip_request *req, struct sip_pvt *p, int sipmethod) [+] static void initreqprep(struct sip_request *req, struct sip_pvt *p, int sipmethod, const char * const explicit_uri)
9542
		ast_str_append(&invite, 0, "%s", p->tohost);
10570
			ast_str_append(&invite, 0, "%s", p->tohost);
9543
		if (p->portinuri)
10571
			if (p->portinuri)
9544
			ast_str_append(&invite, 0, ":%d", ntohs(p->sa.sin_port));
10572
				ast_str_append(&invite, 0, ":%d", ntohs(p->sa.sin_port));
9545
		ast_str_append(&invite, 0, "%s", urioptions);
10573
			ast_str_append(&invite, 0, "%s", urioptions);
9546
	}
10574
		}

    
   
10575
	}
9547

    
   
10576

   
9548
	/* If custom URI options have been provided, append them */
10577
	/* If custom URI options have been provided, append them */
9549
	if (p->options && !ast_strlen_zero(p->options->uri_options))
10578
	if (p->options && !ast_strlen_zero(p->options->uri_options))
9550
		ast_str_append(&invite, 0, ";%s", p->options->uri_options);
10579
		ast_str_append(&invite, 0, ";%s", p->options->uri_options);
9551
	
10580
	
[+20] [20] 11 lines
[+20] static void initreqprep(struct sip_request *req, struct sip_pvt *p, int sipmethod) [+] static void initreqprep(struct sip_request *req, struct sip_pvt *p, int sipmethod, const char * const explicit_uri)
9563
 			snprintf(to, sizeof(to), "<sip:%s>%s%s", p->todnid, ast_strlen_zero(p->theirtag) ? "" : ";tag=", p->theirtag);
10592
 			snprintf(to, sizeof(to), "<sip:%s>%s%s", p->todnid, ast_strlen_zero(p->theirtag) ? "" : ";tag=", p->theirtag);
9564
 		}
10593
 		}
9565
 	} else {
10594
 	} else {
9566
 		if (sipmethod == SIP_NOTIFY && !ast_strlen_zero(p->theirtag)) {
10595
 		if (sipmethod == SIP_NOTIFY && !ast_strlen_zero(p->theirtag)) {
9567
 			/* If this is a NOTIFY, use the From: tag in the subscribe (RFC 3265) */
10596
 			/* If this is a NOTIFY, use the From: tag in the subscribe (RFC 3265) */
9568
			snprintf(to, sizeof(to), "<%s%s>;tag=%s", (!strncasecmp(p->uri, "sip:", 4) ? "sip:" : ""), p->uri, p->theirtag);
10597
			snprintf(to, sizeof(to), "<%s%s>;tag=%s", (strncasecmp(p->uri, "sip:", 4) ? "sip:" : ""), p->uri, p->theirtag);
9569
 		} else if (p->options && p->options->vxml_url) {
10598
 		} else if (p->options && p->options->vxml_url) {
9570
 			/* If there is a VXML URL append it to the SIP URL */
10599
 			/* If there is a VXML URL append it to the SIP URL */
9571
 			snprintf(to, sizeof(to), "<%s>;%s", p->uri, p->options->vxml_url);
10600
 			snprintf(to, sizeof(to), "<%s>;%s", p->uri, p->options->vxml_url);
9572
 		} else
10601
 		} else
9573
 			snprintf(to, sizeof(to), "<%s>", p->uri);
10602
 			snprintf(to, sizeof(to), "<%s>", p->uri);
[+20] [20] 40 lines
[+20] [+] static void add_diversion_header(struct sip_request *req, struct sip_pvt *pvt)
9614

    
   
10643

   
9615
	if (!pvt->owner) {
10644
	if (!pvt->owner) {
9616
		return;
10645
		return;
9617
	}
10646
	}
9618

    
   
10647

   
9619
	diverting_number = pvt->owner->cid.cid_rdnis;
10648
	diverting_number = pvt->owner->redirecting.from.number;
9620
	diverting_name = pvt->owner->redirecting.from.name;
10649
	diverting_name = pvt->owner->redirecting.from.name;
9621
	reason = sip_reason_code_to_str(pvt->owner->redirecting.reason);
10650
	reason = sip_reason_code_to_str(pvt->owner->redirecting.reason);
9622

    
   
10651

   
9623
	if (ast_strlen_zero(diverting_number)) {
10652
	if (ast_strlen_zero(diverting_number)) {
9624
		return;
10653
		return;
[+20] [20] 7 lines
[+20] static void add_diversion_header(struct sip_request *req, struct sip_pvt *pvt)
9632
	}
10661
	}
9633

    
   
10662

   
9634
	add_header(req, "Diversion", header_text);
10663
	add_header(req, "Diversion", header_text);
9635
}
10664
}
9636

    
   
10665

   

    
   
10666
static int transmit_publish(struct sip_epa_entry *epa_entry, enum sip_publish_type publish_type, const char * const explicit_uri)

    
   
10667
{

    
   
10668
	struct sip_pvt *pvt;

    
   
10669
	int expires;

    
   
10670

   

    
   
10671
	epa_entry->publish_type = publish_type;

    
   
10672

   

    
   
10673
	if (!(pvt = sip_alloc(NULL, NULL, 0, SIP_PUBLISH, NULL))) {

    
   
10674
		return -1;

    
   
10675
	}

    
   
10676

   

    
   
10677
	sip_pvt_lock(pvt);

    
   
10678

   

    
   
10679
	if (create_addr(pvt, epa_entry->destination, NULL, TRUE, NULL)) {

    
   
10680
		dialog_unlink_all(pvt, TRUE, TRUE);

    
   
10681
		dialog_unref(pvt, "create_addr failed in transmit_publish. Unref dialog");

    
   
10682
	}

    
   
10683
	ast_sip_ouraddrfor(&pvt->sa.sin_addr, &pvt->ourip, pvt);

    
   
10684
	ast_set_flag(&pvt->flags[0], SIP_OUTGOING);

    
   
10685
	expires = (publish_type == SIP_PUBLISH_REMOVE) ? 0 : DEFAULT_PUBLISH_EXPIRES;

    
   
10686
	pvt->expiry = expires;

    
   
10687

   

    
   
10688
	/* Bump refcount for sip_pvt's reference */

    
   
10689
	ao2_ref(epa_entry, +1);

    
   
10690
	pvt->epa_entry = epa_entry;

    
   
10691

   

    
   
10692
	transmit_invite(pvt, SIP_PUBLISH, FALSE, 2, explicit_uri);

    
   
10693
	sip_pvt_unlock(pvt);

    
   
10694
	sip_scheddestroy(pvt, DEFAULT_TRANS_TIMEOUT);

    
   
10695
	dialog_unref(pvt, "Done with the sip_pvt allocated for transmitting PUBLISH");

    
   
10696
	return 0;

    
   
10697
}

    
   
10698

   
9637
/*! \brief Build REFER/INVITE/OPTIONS/SUBSCRIBE message and transmit it
10699
/*! \brief Build REFER/INVITE/OPTIONS/SUBSCRIBE message and transmit it
9638
	\param init 0 = Prepare request within dialog, 1= prepare request, new branch, 2= prepare new request and new dialog. do_proxy_auth calls this with init!=2
10700
	\param init 0 = Prepare request within dialog, 1= prepare request, new branch, 2= prepare new request and new dialog. do_proxy_auth calls this with init!=2
9639
 \param p sip_pvt structure
10701
 \param p sip_pvt structure
9640
 \param sdp unknown
10702
 \param sdp unknown
9641
 \param sipmethod unknown
10703
 \param sipmethod unknown
9642

    
   
10704

   
9643
*/
10705
*/
9644
static int transmit_invite(struct sip_pvt *p, int sipmethod, int sdp, int init)
10706
static int transmit_invite(struct sip_pvt *p, int sipmethod, int sdp, int init, const char * const explicit_uri)
9645
{
10707
{
9646
	struct sip_request req;
10708
	struct sip_request req;
9647
	struct ast_variable *var;
10709
	struct ast_variable *var;
9648
	
10710
	
9649
	req.method = sipmethod;
10711
	req.method = sipmethod;
9650
	if (init) {/* Bump branch even on initial requests */
10712
	if (init) {/* Bump branch even on initial requests */
9651
		p->branch ^= ast_random();
10713
		p->branch ^= ast_random();
9652
		p->invite_branch = p->branch;
10714
		p->invite_branch = p->branch;
9653
		build_via(p);
10715
		build_via(p);
9654
	}
10716
	}
9655
	if (init > 1)
10717
	if (init > 1)
9656
		initreqprep(&req, p, sipmethod);
10718
		initreqprep(&req, p, sipmethod, explicit_uri);
9657
	else
10719
	else
9658
		/* If init=1, we should not generate a new branch. If it's 0, we need a new branch. */
10720
		/* If init=1, we should not generate a new branch. If it's 0, we need a new branch. */
9659
		reqprep(&req, p, sipmethod, 0, init ? 0 : 1);
10721
		reqprep(&req, p, sipmethod, 0, init ? 0 : 1);
9660
		
10722
		
9661
	if (p->options && p->options->auth)
10723
	if (p->options && p->options->auth)
[+20] [20] 7 lines
[+20] static int transmit_invite(struct sip_pvt *p, int sipmethod, int sdp, int init) [+] static int transmit_invite(struct sip_pvt *p, int sipmethod, int sdp, int init, const char * const explicit_uri)
9669
			if (!ast_strlen_zero(p->refer->referred_by)) {
10731
			if (!ast_strlen_zero(p->refer->referred_by)) {
9670
				snprintf(buf, sizeof(buf), "%s <%s>", p->refer->referred_by_name, p->refer->referred_by);
10732
				snprintf(buf, sizeof(buf), "%s <%s>", p->refer->referred_by_name, p->refer->referred_by);
9671
				add_header(&req, "Referred-By", buf);
10733
				add_header(&req, "Referred-By", buf);
9672
			}
10734
			}
9673
		}
10735
		}
9674
	} else if (sipmethod == SIP_SUBSCRIBE) { /* We only support sending MWI subscriptions right now */
10736
	} else if (sipmethod == SIP_SUBSCRIBE) {
9675
		char buf[SIPBUFSIZE];
10737
		char buf[SIPBUFSIZE];
9676

    
   
10738
		if (p->subscribed == MWI_NOTIFICATION) {
9677
		add_header(&req, "Event", "message-summary");
10739
			add_header(&req, "Event", "message-summary");
9678
		add_header(&req, "Accept", "application/simple-message-summary");
10740
			add_header(&req, "Accept", "application/simple-message-summary");
9679
		snprintf(buf, sizeof(buf), "%d", mwi_expiry);
10741
		} else if (p->subscribed == CALL_COMPLETION) {

    
   
10742
			add_header(&req, "Event", "call-completion");

    
   
10743
			add_header(&req, "Accept", "application/call-completion");

    
   
10744
		}

    
   
10745
		snprintf(buf, sizeof(buf), "%d", p->expiry);
9680
		add_header(&req, "Expires", buf);
10746
		add_header(&req, "Expires", buf);
9681
	}
10747
	}
9682

    
   
10748

   
9683
	/* This new INVITE is part of an attended transfer. Make sure that the
10749
	/* This new INVITE is part of an attended transfer. Make sure that the
9684
	other end knows and replace the current call with this new call */
10750
	other end knows and replace the current call with this new call */
[+20] [20] 78 lines
[+20] static int transmit_invite(struct sip_pvt *p, int sipmethod, int sdp, int init) [+] static int transmit_invite(struct sip_pvt *p, int sipmethod, int sdp, int init, const char * const explicit_uri)
9763
		for (var = p->notify->headers; var; var = var->next)
10829
		for (var = p->notify->headers; var; var = var->next)
9764
			add_header(&req, var->name, var->value);
10830
			add_header(&req, var->name, var->value);
9765
		add_header_contentLength(&req, ast_str_strlen(p->notify->content));
10831
		add_header_contentLength(&req, ast_str_strlen(p->notify->content));
9766
		if (ast_str_strlen(p->notify->content))
10832
		if (ast_str_strlen(p->notify->content))
9767
			add_line(&req, ast_str_buffer(p->notify->content));
10833
			add_line(&req, ast_str_buffer(p->notify->content));

    
   
10834
	} else if (sipmethod == SIP_PUBLISH) {

    
   
10835
		char expires[SIPBUFSIZE];

    
   
10836
		switch (p->epa_entry->static_data->event) {

    
   
10837
		case CALL_COMPLETION:

    
   
10838
			snprintf(expires, sizeof(expires), "%d", p->expiry);

    
   
10839
			add_header(&req, "Event", "call-completion");

    
   
10840
			add_header(&req, "Expires", expires);

    
   
10841
			if (p->epa_entry->publish_type != SIP_PUBLISH_INITIAL) {

    
   
10842
				add_header(&req, "SIP-If-Match", p->epa_entry->entity_tag);

    
   
10843
			}

    
   
10844
			if (!ast_strlen_zero(p->epa_entry->body)) {

    
   
10845
				add_header(&req, "Content-Type", "application/pidf+xml");

    
   
10846
				add_header_contentLength(&req, strlen(p->epa_entry->body));

    
   
10847
				add_line(&req, p->epa_entry->body);

    
   
10848
			} else {

    
   
10849
				add_header_contentLength(&req, 0);

    
   
10850
			}

    
   
10851
		default:

    
   
10852
			break;

    
   
10853
		}
9768
	} else {
10854
	} else {
9769
		add_header_contentLength(&req, 0);
10855
		add_header_contentLength(&req, 0);
9770
    }
10856
    }
9771

    
   
10857

   
9772
	if (!p->initreq.headers || init > 2)
10858
	if (!p->initreq.headers || init > 2)
9773
		initialize_initreq(p, &req);
10859
		initialize_initreq(p, &req);
9774
	if (sipmethod == SIP_INVITE) {
10860
	if (sipmethod == SIP_INVITE || sipmethod == SIP_SUBSCRIBE) {
9775
		p->lastinvite = p->ocseq;
10861
		p->lastinvite = p->ocseq;
9776
	}
10862
	}
9777
	return send_request(p, &req, init ? XMIT_CRITICAL : XMIT_RELIABLE, p->ocseq);
10863
	return send_request(p, &req, init ? XMIT_CRITICAL : XMIT_RELIABLE, p->ocseq);
9778
}
10864
}
9779

    
   
10865

   
[+20] [20] 23 lines
[+20] [+] static int __sip_subscribe_mwi_do(struct sip_subscription_mwi *mwi)
9803
		ast_dnsmgr_lookup(mwi->hostname, &mwi->us, &mwi->dnsmgr, sip_cfg.srvlookup ? transport : NULL);
10889
		ast_dnsmgr_lookup(mwi->hostname, &mwi->us, &mwi->dnsmgr, sip_cfg.srvlookup ? transport : NULL);
9804
	}
10890
	}
9805

    
   
10891

   
9806
	/* If we already have a subscription up simply send a resubscription */
10892
	/* If we already have a subscription up simply send a resubscription */
9807
	if (mwi->call) {
10893
	if (mwi->call) {
9808
		transmit_invite(mwi->call, SIP_SUBSCRIBE, 0, 0);
10894
		transmit_invite(mwi->call, SIP_SUBSCRIBE, 0, 0, NULL);
9809
		return 0;
10895
		return 0;
9810
	}
10896
	}
9811
	
10897
	
9812
	/* Create a dialog that we will use for the subscription */
10898
	/* Create a dialog that we will use for the subscription */
9813
	if (!(mwi->call = sip_alloc(NULL, NULL, 0, SIP_SUBSCRIBE, NULL))) {
10899
	if (!(mwi->call = sip_alloc(NULL, NULL, 0, SIP_SUBSCRIBE, NULL))) {
[+20] [20] 5 lines
[+20] static int __sip_subscribe_mwi_do(struct sip_subscription_mwi *mwi)
9819
	if (!mwi->us.sin_port && mwi->portno) {
10905
	if (!mwi->us.sin_port && mwi->portno) {
9820
		mwi->us.sin_port = htons(mwi->portno);
10906
		mwi->us.sin_port = htons(mwi->portno);
9821
	}
10907
	}
9822
	
10908
	
9823
	/* Setup the destination of our subscription */
10909
	/* Setup the destination of our subscription */
9824
	if (create_addr(mwi->call, mwi->hostname, &mwi->us, 0)) {
10910
	if (create_addr(mwi->call, mwi->hostname, &mwi->us, 0, NULL)) {
9825
		dialog_unlink_all(mwi->call, TRUE, TRUE);
10911
		dialog_unlink_all(mwi->call, TRUE, TRUE);
9826
		mwi->call = dialog_unref(mwi->call, "unref dialog after unlink_all");
10912
		mwi->call = dialog_unref(mwi->call, "unref dialog after unlink_all");
9827
		return 0;
10913
		return 0;
9828
	}
10914
	}

    
   
10915

   

    
   
10916
	mwi->call->expiry = mwi_expiry;
9829
	
10917
	
9830
	if (!mwi->dnsmgr && mwi->portno) {
10918
	if (!mwi->dnsmgr && mwi->portno) {
9831
		mwi->call->sa.sin_port = htons(mwi->portno);
10919
		mwi->call->sa.sin_port = htons(mwi->portno);
9832
		mwi->call->recv.sin_port = htons(mwi->portno);
10920
		mwi->call->recv.sin_port = htons(mwi->portno);
9833
	} else {
10921
	} else {
[+20] [20] 24 lines
[+20] static int __sip_subscribe_mwi_do(struct sip_subscription_mwi *mwi)
9858
	
10946
	
9859
	/* Associate the call with us */
10947
	/* Associate the call with us */
9860
	mwi->call->mwi = ASTOBJ_REF(mwi);
10948
	mwi->call->mwi = ASTOBJ_REF(mwi);
9861
	
10949
	
9862
	/* Actually send the packet */
10950
	/* Actually send the packet */
9863
	transmit_invite(mwi->call, SIP_SUBSCRIBE, 0, 2);
10951
	transmit_invite(mwi->call, SIP_SUBSCRIBE, 0, 2, NULL);
9864

    
   
10952

   
9865
	return 0;
10953
	return 0;
9866
}
10954
}
9867

    
   
10955

   
9868
/*! \brief Find the channel that is causing the RINGING update */
10956
/*! \brief Find the channel that is causing the RINGING update */
[+20] [20] 173 lines
[+20] [+] static void state_notify_build_xml(int state, int full, const char *exten, const char *context, struct ast_str **tmp, struct sip_pvt *p, int subscribed, const char *mfrom, const char *mto)
10042
	default:
11130
	default:
10043
		break;
11131
		break;
10044
	}
11132
	}
10045
}
11133
}
10046

    
   
11134

   

    
   
11135
static int transmit_cc_notify(struct ast_cc_agent *agent, struct sip_pvt *subscription, enum sip_cc_notify_state state)

    
   
11136
{

    
   
11137
	struct sip_request req;

    
   
11138
	struct sip_cc_agent_pvt *agent_pvt = agent->private_data;

    
   
11139
	char uri[SIPBUFSIZE];

    
   
11140
	char state_str[64];

    
   
11141

   

    
   
11142
	if (state < CC_QUEUED || state > CC_READY) {

    
   
11143
		ast_log(LOG_WARNING, "Invalid state provided for transmit_cc_notify (%d)\n", state);

    
   
11144
		return -1;

    
   
11145
	}

    
   
11146

   

    
   
11147
	reqprep(&req, subscription, SIP_NOTIFY, 0, TRUE);

    
   
11148
	snprintf(state_str, sizeof(state_str), "%s\r\n", sip_cc_notify_state_map[state].state_string);

    
   
11149
	add_header(&req, "Event", "call-completion");

    
   
11150
	add_header(&req, "Content-Type", "application/call-completion");

    
   
11151
	if (state == CC_READY) {

    
   
11152
		generate_uri(subscription, agent_pvt->notify_uri, sizeof(agent_pvt->notify_uri));

    
   
11153
		snprintf(uri, sizeof(uri) - 1, "cc-URI: %s\r\n", agent_pvt->notify_uri);

    
   
11154
	}

    
   
11155
	add_header_contentLength(&req, strlen(state_str) +

    
   
11156
			(state == CC_READY ? strlen(uri) : 0));

    
   
11157
	add_line(&req, state_str);

    
   
11158
	if (state == CC_READY) {

    
   
11159
		add_line(&req, uri);

    
   
11160
	}

    
   
11161
	return send_request(subscription, &req, XMIT_RELIABLE, subscription->ocseq);

    
   
11162
}
10047

    
   
11163

   
10048
/*! \brief Used in the SUBSCRIBE notification subsystem (RFC3265) */
11164
/*! \brief Used in the SUBSCRIBE notification subsystem (RFC3265) */
10049
static int transmit_state_notify(struct sip_pvt *p, int state, int full, int timeout)
11165
static int transmit_state_notify(struct sip_pvt *p, int state, int full, int timeout)
10050
{
11166
{
10051
	struct ast_str *tmp = ast_str_alloca(4000);
11167
	struct ast_str *tmp = ast_str_alloca(4000);
[+20] [20] 86 lines
[+20] static int transmit_state_notify(struct sip_pvt *p, int state, int full, int timeout)
10138
 */
11254
 */
10139
static int transmit_notify_with_mwi(struct sip_pvt *p, int newmsgs, int oldmsgs, const char *vmexten)
11255
static int transmit_notify_with_mwi(struct sip_pvt *p, int newmsgs, int oldmsgs, const char *vmexten)
10140
{
11256
{
10141
	struct sip_request req;
11257
	struct sip_request req;
10142
	struct ast_str *out = ast_str_alloca(500);
11258
	struct ast_str *out = ast_str_alloca(500);
10143
	int ourport = ntohs(p->ourip.sin_port);
11259
	int ourport = (p->fromdomainport) ? p->fromdomainport : ntohs(p->ourip.sin_port);

    
   
11260
	const char *domain = S_OR(p->fromdomain,ast_inet_ntoa(p->ourip.sin_addr));
10144
	const char *exten = S_OR(vmexten, default_vmexten);
11261
	const char *exten = S_OR(vmexten, default_vmexten);
10145

    
   
11262

   
10146
	initreqprep(&req, p, SIP_NOTIFY);
11263
	initreqprep(&req, p, SIP_NOTIFY, NULL);
10147
	add_header(&req, "Event", "message-summary");
11264
	add_header(&req, "Event", "message-summary");
10148
	add_header(&req, "Content-Type", default_notifymime);
11265
	add_header(&req, "Content-Type", default_notifymime);
10149
	ast_str_append(&out, 0, "Messages-Waiting: %s\r\n", newmsgs ? "yes" : "no");
11266
	ast_str_append(&out, 0, "Messages-Waiting: %s\r\n", newmsgs ? "yes" : "no");
10150

    
   
11267

   
10151
	if (!ast_strlen_zero(p->fromdomain)) {
11268

   
10152
		ast_str_append(&out, 0, "Message-Account: sip:%s@%s\r\n", exten, p->fromdomain);
11269
	if (!sip_standard_port(p->socket.type, ourport)) {
10153
	} else if (!sip_standard_port(p->socket.type, ourport)) {

   
10154
		if (p->socket.type == SIP_TRANSPORT_UDP) {
11270
		if (p->socket.type == SIP_TRANSPORT_UDP) {
10155
			ast_str_append(&out, 0, "Message-Account: sip:%s@%s:%d\r\n", exten, ast_inet_ntoa(p->ourip.sin_addr), ourport);
11271
			ast_str_append(&out, 0, "Message-Account: sip:%s@%s:%d\r\n", exten, domain, ourport);
10156
		} else {
11272
		} else {
10157
			ast_str_append(&out, 0, "Message-Account: sip:%s@%s:%d;transport=%s\r\n", exten, ast_inet_ntoa(p->ourip.sin_addr), ourport, get_transport(p->socket.type));
11273
			ast_str_append(&out, 0, "Message-Account: sip:%s@%s:%d;transport=%s\r\n", exten, domain, ourport, get_transport(p->socket.type));
10158
		}
11274
		}
10159
	} else {
11275
	} else {
10160
		if (p->socket.type == SIP_TRANSPORT_UDP) {
11276
		if (p->socket.type == SIP_TRANSPORT_UDP) {
10161
			ast_str_append(&out, 0, "Message-Account: sip:%s@%s\r\n", exten, ast_inet_ntoa(p->ourip.sin_addr));
11277
			ast_str_append(&out, 0, "Message-Account: sip:%s@%s\r\n", exten, domain);
10162
		} else {
11278
		} else {
10163
			ast_str_append(&out, 0, "Message-Account: sip:%s@%s;transport=%s\r\n", exten, ast_inet_ntoa(p->ourip.sin_addr), get_transport(p->socket.type));
11279
			ast_str_append(&out, 0, "Message-Account: sip:%s@%s;transport=%s\r\n", exten, domain, get_transport(p->socket.type));
10164
		}
11280
		}
10165
	}
11281
	}
10166
	/* Cisco has a bug in the SIP stack where it can't accept the
11282
	/* Cisco has a bug in the SIP stack where it can't accept the
10167
		(0/0) notification. This can temporarily be disabled in
11283
		(0/0) notification. This can temporarily be disabled in
10168
		sip.conf with the "buggymwi" option */
11284
		sip.conf with the "buggymwi" option */
[+20] [20] 58 lines
[+20] [+] static int manager_sipnotify(struct mansession *s, const struct message *m)
10227
	if (!(p = sip_alloc(NULL, NULL, 0, SIP_NOTIFY, NULL))) {
11343
	if (!(p = sip_alloc(NULL, NULL, 0, SIP_NOTIFY, NULL))) {
10228
		astman_send_error(s, m, "Unable to build sip pvt data for notify (memory/socket error)");
11344
		astman_send_error(s, m, "Unable to build sip pvt data for notify (memory/socket error)");
10229
		return 0;
11345
		return 0;
10230
	}
11346
	}
10231

    
   
11347

   
10232
	if (create_addr(p, channame, NULL, 0)) {
11348
	if (create_addr(p, channame, NULL, 0, NULL)) {
10233
		/* Maybe they're not registered, etc. */
11349
		/* Maybe they're not registered, etc. */
10234
		dialog_unlink_all(p, TRUE, TRUE);
11350
		dialog_unlink_all(p, TRUE, TRUE);
10235
		dialog_unref(p, "unref dialog inside for loop" );
11351
		dialog_unref(p, "unref dialog inside for loop" );
10236
		/* sip_destroy(p); */
11352
		/* sip_destroy(p); */
10237
		astman_send_error(s, m, "Could not create address");
11353
		astman_send_error(s, m, "Could not create address");
[+20] [20] 17 lines
[+20] static int manager_sipnotify(struct mansession *s, const struct message *m)
10255
		}
11371
		}
10256
	}
11372
	}
10257

    
   
11373

   
10258
	dialog_ref(p, "bump the count of p, which transmit_sip_request will decrement.");
11374
	dialog_ref(p, "bump the count of p, which transmit_sip_request will decrement.");
10259
	sip_scheddestroy(p, SIP_TRANS_TIMEOUT);
11375
	sip_scheddestroy(p, SIP_TRANS_TIMEOUT);
10260
	transmit_invite(p, SIP_NOTIFY, 0, 2);
11376
	transmit_invite(p, SIP_NOTIFY, 0, 2, NULL);
10261

    
   
11377

   
10262
	astman_send_ack(s, m, "Notify Sent");
11378
	astman_send_ack(s, m, "Notify Sent");
10263
	ast_variables_destroy(vars);
11379
	ast_variables_destroy(vars);
10264
	return 0;
11380
	return 0;
10265
}
11381
}
[+20] [20] 203 lines
[+20] [+] static int transmit_register(struct sip_registry *r, int sipmethod, const char *auth, const char *authheader)
10469
	char tmp[80];
11585
	char tmp[80];
10470
	char addr[80];
11586
	char addr[80];
10471
	struct sip_pvt *p;
11587
	struct sip_pvt *p;
10472
	struct sip_peer *peer = NULL;
11588
	struct sip_peer *peer = NULL;
10473
	int res;
11589
	int res;
10474
	char *fromdomain;
11590
	int portno = 0;
10475
	char *domainport = NULL;

   
10476

    
   
11591

   
10477
	/* exit if we are already in process with this registrar ?*/
11592
	/* exit if we are already in process with this registrar ?*/
10478
	if (r == NULL || ((auth == NULL) && (r->regstate == REG_STATE_REGSENT || r->regstate == REG_STATE_AUTHSENT))) {
11593
	if (r == NULL || ((auth == NULL) && (r->regstate == REG_STATE_REGSENT || r->regstate == REG_STATE_AUTHSENT))) {
10479
		if (r) {
11594
		if (r) {
10480
			ast_log(LOG_NOTICE, "Strange, trying to register %s@%s when registration already pending\n", r->username, r->hostname);
11595
			ast_log(LOG_NOTICE, "Strange, trying to register %s@%s when registration already pending\n", r->username, r->hostname);
[+20] [20] 33 lines
[+20] static int transmit_register(struct sip_registry *r, int sipmethod, const char *auth, const char *authheader)
10514
		}
11629
		}
10515
		
11630
		
10516
		if (p->do_history)
11631
		if (p->do_history)
10517
			append_history(p, "RegistryInit", "Account: %s@%s", r->username, r->hostname);
11632
			append_history(p, "RegistryInit", "Account: %s@%s", r->username, r->hostname);
10518

    
   
11633

   
10519
		if (!ast_strlen_zero(r->peername)) {

   
10520
			if (!(peer = find_peer(r->peername, NULL, 1, FINDPEERS, FALSE, 0))) {

   
10521
				ast_log(LOG_WARNING, "Could not find peer %s in transmit_register\n", r->peername);

   
10522
			} else {

   
10523
				p->peerauth = peer->auth;

   
10524
			}

   
10525
		}

   
10526
		ref_proxy(p, obproxy_get(p, peer)); /* it is ok to pass a NULL peer into obproxy_get() */

   
10527
		if (peer) {

   
10528
			unref_peer(peer, "transmit_registration: from find_peer operation");

   
10529
		}

   
10530
		/* Use port number specified if no SRV record was found */
11634
		/* Use port number specified if no SRV record was found */
10531
		if (!r->us.sin_port && r->portno)
11635
		if (!r->us.sin_port && r->portno)
10532
			r->us.sin_port = htons(r->portno);
11636
			r->us.sin_port = htons(r->portno);
10533

    
   
11637

   
10534
		/* Find address to hostname */
11638
		/* Find address to hostname */
10535
		if (create_addr(p, r->hostname, &r->us, 0)) {
11639
		if (create_addr(p, S_OR(r->peername, r->hostname), &r->us, 0, NULL)) {
10536
			/* we have what we hope is a temporary network error,
11640
			/* we have what we hope is a temporary network error,
10537
			 * probably DNS.  We need to reschedule a registration try */
11641
			 * probably DNS.  We need to reschedule a registration try */
10538
			dialog_unlink_all(p, TRUE, TRUE);
11642
			dialog_unlink_all(p, TRUE, TRUE);
10539
			p = dialog_unref(p, "unref dialog after unlink_all");
11643
			p = dialog_unref(p, "unref dialog after unlink_all");
10540
			if (r->timeout > -1) {
11644
			if (r->timeout > -1) {
[+20] [20] 4 lines
[+20] static int transmit_register(struct sip_registry *r, int sipmethod, const char *auth, const char *authheader)
10545
				ast_log(LOG_WARNING, "Still have a registration timeout for %s@%s (create_addr() error), %d\n", r->username, r->hostname, r->timeout);
11649
				ast_log(LOG_WARNING, "Still have a registration timeout for %s@%s (create_addr() error), %d\n", r->username, r->hostname, r->timeout);
10546
			} else {
11650
			} else {
10547
				r->timeout = ast_sched_add(sched, global_reg_timeout * 1000, sip_reg_timeout, registry_addref(r, "add for REPLACE registry ptr"));
11651
				r->timeout = ast_sched_add(sched, global_reg_timeout * 1000, sip_reg_timeout, registry_addref(r, "add for REPLACE registry ptr"));
10548
				ast_log(LOG_WARNING, "Probably a DNS error for registration to %s@%s, trying REGISTER again (after %d seconds)\n", r->username, r->hostname, global_reg_timeout);
11652
				ast_log(LOG_WARNING, "Probably a DNS error for registration to %s@%s, trying REGISTER again (after %d seconds)\n", r->username, r->hostname, global_reg_timeout);
10549
			}
11653
			}
10550
			r->regattempts++;
11654
			r->regattempts++;
10551
			return 0;
11655
			return 0;
10552
		}
11656
		}
10553

    
   
11657

   
10554
		/* Copy back Call-ID in case create_addr changed it */
11658
		/* Copy back Call-ID in case create_addr changed it */
10555
		ast_string_field_set(r, callid, p->callid);
11659
		ast_string_field_set(r, callid, p->callid);
10556
		if (!r->dnsmgr && r->portno) {
11660

   
10557
			p->sa.sin_port = htons(r->portno);
11661
		if (!r->dnsmgr && r->portno) {
10558
 			p->recv.sin_port = htons(r->portno);
11662
			p->sa.sin_port = htons(r->portno);
10559
		} else {	/* Set registry port to the port set from the peer definition/srv or default */
11663
 			p->recv.sin_port = htons(r->portno);
10560
			r->portno = ntohs(p->sa.sin_port);
11664
		}
10561
		}
11665
		if (!ast_strlen_zero(p->fromdomain)) {
10562
		ast_set_flag(&p->flags[0], SIP_OUTGOING);	/* Registration is outgoing call */
11666
			portno = (p->fromdomainport) ? p->fromdomainport : STANDARD_SIP_PORT;
10563
		r->call = dialog_ref(p, "copying dialog into registry r->call");		/* Save pointer to SIP dialog */
11667
		} else if (!ast_strlen_zero(r->regdomain)) {
10564
		p->registry = registry_addref(r, "transmit_register: addref to p->registry in transmit_register");	/* Add pointer to registry in packet */
11668
			portno = (r->regdomainport) ? r->regdomainport : STANDARD_SIP_PORT;
10565
		if (!ast_strlen_zero(r->secret)) {	/* Secret (password) */
11669
		} else {
10566
			ast_string_field_set(p, peersecret, r->secret);
11670
			portno = ntohs(p->sa.sin_port);
10567
		}
11671
		}
10568
		if (!ast_strlen_zero(r->md5secret))
11672

   
10569
			ast_string_field_set(p, peermd5secret, r->md5secret);
11673
		ast_set_flag(&p->flags[0], SIP_OUTGOING);	/* Registration is outgoing call */
10570
		/* User name in this realm
11674
		r->call = dialog_ref(p, "copying dialog into registry r->call");		/* Save pointer to SIP dialog */
10571
		- if authuser is set, use that, otherwise use username */
11675
		p->registry = registry_addref(r, "transmit_register: addref to p->registry in transmit_register");	/* Add pointer to registry in packet */
10572
		if (!ast_strlen_zero(r->authuser)) {
11676
		if (!ast_strlen_zero(r->secret)) {	/* Secret (password) */
10573
			ast_string_field_set(p, peername, r->authuser);
11677
			ast_string_field_set(p, peersecret, r->secret);
10574
			ast_string_field_set(p, authname, r->authuser);
11678
		}
10575
		} else if (!ast_strlen_zero(r->username)) {
11679
		if (!ast_strlen_zero(r->md5secret))
10576
			ast_string_field_set(p, peername, r->username);
11680
			ast_string_field_set(p, peermd5secret, r->md5secret);
10577
			ast_string_field_set(p, authname, r->username);
11681
		/* User name in this realm
10578
			ast_string_field_set(p, fromuser, r->username);
11682
		- if authuser is set, use that, otherwise use username */
10579
		}
11683
		if (!ast_strlen_zero(r->authuser)) {
10580
		if (!ast_strlen_zero(r->username))
11684
			ast_string_field_set(p, peername, r->authuser);
10581
			ast_string_field_set(p, username, r->username);
11685
			ast_string_field_set(p, authname, r->authuser);
10582
		/* Save extension in packet */
11686
		} else if (!ast_strlen_zero(r->username)) {
10583
		if (!ast_strlen_zero(r->callback))
11687
			ast_string_field_set(p, peername, r->username);
10584
			ast_string_field_set(p, exten, r->callback);
11688
			ast_string_field_set(p, authname, r->username);
10585

    
   
11689
			ast_string_field_set(p, fromuser, r->username);
10586
		/* Set transport and port so the correct contact is built */
11690
		}
10587
		set_socket_transport(&p->socket, r->transport);
11691
		if (!ast_strlen_zero(r->username))
10588
		if (r->transport == SIP_TRANSPORT_TLS || r->transport == SIP_TRANSPORT_TCP) {
11692
			ast_string_field_set(p, username, r->username);
10589
			p->socket.port = sip_tcp_desc.local_address.sin_port;
11693
		/* Save extension in packet */
10590
		}
11694
		if (!ast_strlen_zero(r->callback))
10591

    
   
11695
			ast_string_field_set(p, exten, r->callback);
10592
		/*
11696

   
10593
		  check which address we should use in our contact header
11697
		/* Set transport and port so the correct contact is built */
10594
		  based on whether the remote host is on the external or
11698
		set_socket_transport(&p->socket, r->transport);
10595
		  internal network so we can register through nat
11699
		if (r->transport == SIP_TRANSPORT_TLS || r->transport == SIP_TRANSPORT_TCP) {
10596
		 */
11700
			p->socket.port = sip_tcp_desc.local_address.sin_port;
10597
		ast_sip_ouraddrfor(&p->sa.sin_addr, &p->ourip, p);
11701
		}
10598
		build_contact(p);
11702

   
10599
	}
11703
		/*
10600

    
   
11704
		  check which address we should use in our contact header
10601
	/* set up a timeout */
11705
		  based on whether the remote host is on the external or
10602
	if (auth == NULL)  {
11706
		  internal network so we can register through nat
10603
		if (r->timeout > -1)
11707
		 */
10604
			ast_log(LOG_WARNING, "Still have a registration timeout, #%d - deleting it\n", r->timeout);
11708
		ast_sip_ouraddrfor(&p->sa.sin_addr, &p->ourip, p);
10605
		AST_SCHED_REPLACE_UNREF(r->timeout, sched, global_reg_timeout * 1000, sip_reg_timeout, r,
11709
		build_contact(p);
10606
								registry_unref(_data,"reg ptr unrefed from del in SCHED_REPLACE"),
11710
	}
10607
								registry_unref(r,"reg ptr unrefed from add failure in SCHED_REPLACE"),
11711

   
10608
								registry_addref(r,"reg ptr reffed from add in SCHED_REPLACE"));
11712
	/* set up a timeout */
10609
		ast_debug(1, "Scheduled a registration timeout for %s id  #%d \n", r->hostname, r->timeout);
11713
	if (auth == NULL)  {
10610
	}
11714
		if (r->timeout > -1)
10611

    
   
11715
			ast_log(LOG_WARNING, "Still have a registration timeout, #%d - deleting it\n", r->timeout);
10612
	if ((fromdomain = strchr(r->username, '@'))) {
11716
		AST_SCHED_REPLACE_UNREF(r->timeout, sched, global_reg_timeout * 1000, sip_reg_timeout, r,
10613
		/* the domain name is just behind '@' */
11717
								registry_unref(_data,"reg ptr unrefed from del in SCHED_REPLACE"),
10614
		fromdomain++ ;
11718
								registry_unref(r,"reg ptr unrefed from add failure in SCHED_REPLACE"),
10615
		/* We have a domain in the username for registration */
11719
								registry_addref(r,"reg ptr reffed from add in SCHED_REPLACE"));
10616
		snprintf(from, sizeof(from), "<sip:%s>;tag=%s", r->username, p->tag);
11720
		ast_debug(1, "Scheduled a registration timeout for %s id  #%d \n", r->hostname, r->timeout);
10617
		if (!ast_strlen_zero(p->theirtag))
11721
	}
10618
			snprintf(to, sizeof(to), "<sip:%s>;tag=%s", r->username, p->theirtag);
11722

   
10619
		else
11723
	snprintf(from, sizeof(from), "<sip:%s@%s>;tag=%s", r->username, S_OR(r->regdomain,p->tohost), p->tag);
10620
			snprintf(to, sizeof(to), "<sip:%s>", r->username);
11724
	if (!ast_strlen_zero(p->theirtag)) {
10621

    
   
11725
		snprintf(to, sizeof(to), "<sip:%s@%s>;tag=%s", r->username, S_OR(r->regdomain,p->tohost), p->theirtag);
10622
		/* If the registration username contains '@', then the domain should be used as
11726
	} else {
10623
		   the equivalent of "fromdomain" for the registration */
11727
		snprintf(to, sizeof(to), "<sip:%s@%s>", r->username, S_OR(r->regdomain,p->tohost));
10624
		if (ast_strlen_zero(p->fromdomain)) {
11728
	}
10625
			ast_string_field_set(p, fromdomain, fromdomain);
11729

   
10626
		}
11730
	/* Fromdomain is what we are registering to, regardless of actual
10627
	} else {
11731
  	   host name from SRV */
10628
		snprintf(from, sizeof(from), "<sip:%s@%s>;tag=%s", r->username, p->tohost, p->tag);
11732
	if (portno && portno != STANDARD_SIP_PORT) {
10629
		if (!ast_strlen_zero(p->theirtag))
11733
		snprintf(addr, sizeof(addr), "sip:%s:%d", S_OR(p->fromdomain,S_OR(r->regdomain,r->hostname)), portno);
10630
			snprintf(to, sizeof(to), "<sip:%s@%s>;tag=%s", r->username, p->tohost, p->theirtag);
11734
	} else {
10631
		else
11735
		snprintf(addr, sizeof(addr), "sip:%s", S_OR(p->fromdomain,S_OR(r->regdomain,r->hostname)));
10632
			snprintf(to, sizeof(to), "<sip:%s@%s>", r->username, p->tohost);
11736
	}
10633
	}
11737

   
10634

    
   

   
10635
	/* Fromdomain is what we are registering to, regardless of actual

   
10636
  	   host name from SRV */

   
10637
	if (!ast_strlen_zero(p->fromdomain)) {

   
10638
		domainport = strrchr(p->fromdomain, ':');

   
10639
		if (domainport) {

   
10640
			*domainport++ = '\0'; /* trim off domainport from p->fromdomain */

   
10641
			if (ast_strlen_zero(domainport))

   
10642
				domainport = NULL;

   
10643
		}

   
10644
		if (domainport) {

   
10645
			if (atoi(domainport) != STANDARD_SIP_PORT)

   
10646
				snprintf(addr, sizeof(addr), "sip:%s:%s", p->fromdomain, domainport);

   
10647
			else

   
10648
				snprintf(addr, sizeof(addr), "sip:%s", p->fromdomain);

   
10649
		} else {

   
10650
			if (r->portno && r->portno != STANDARD_SIP_PORT)

   
10651
				snprintf(addr, sizeof(addr), "sip:%s:%d", p->fromdomain, r->portno);

   
10652
			else

   
10653
				snprintf(addr, sizeof(addr), "sip:%s", p->fromdomain);

   
10654
		}

   
10655
	} else {

   
10656
		if (r->portno && r->portno != STANDARD_SIP_PORT)

   
10657
			snprintf(addr, sizeof(addr), "sip:%s:%d", r->hostname, r->portno);

   
10658
		else

   
10659
			snprintf(addr, sizeof(addr), "sip:%s", r->hostname);

   
10660
	}

   
10661
	ast_string_field_set(p, uri, addr);
11738
	ast_string_field_set(p, uri, addr);
10662

    
   
11739

   
10663
	p->branch ^= ast_random();
11740
	p->branch ^= ast_random();
10664

    
   
11741

   
10665
	init_req(&req, sipmethod, addr);
11742
	init_req(&req, sipmethod, addr);
[+20] [20] 24 lines
[+20] static int transmit_register(struct sip_registry *r, int sipmethod, const char *auth, const char *authheader)
10690
		 */
11767
		 */
10691
		if (sipdebug)
11768
		if (sipdebug)
10692
			ast_debug(1, "   >>> Re-using Auth data for %s@%s\n", r->username, r->hostname);
11769
			ast_debug(1, "   >>> Re-using Auth data for %s@%s\n", r->username, r->hostname);
10693
		ast_string_field_set(p, realm, r->realm);
11770
		ast_string_field_set(p, realm, r->realm);
10694
		ast_string_field_set(p, nonce, r->nonce);
11771
		ast_string_field_set(p, nonce, r->nonce);
10695
		ast_string_field_set(p, domain, r->domain);
11772
		ast_string_field_set(p, domain, r->authdomain);
10696
		ast_string_field_set(p, opaque, r->opaque);
11773
		ast_string_field_set(p, opaque, r->opaque);
10697
		ast_string_field_set(p, qop, r->qop);
11774
		ast_string_field_set(p, qop, r->qop);
10698
		p->noncecount = ++r->noncecount;
11775
		p->noncecount = ++r->noncecount;
10699

    
   
11776

   
10700
		memset(digest, 0, sizeof(digest));
11777
		memset(digest, 0, sizeof(digest));
[+20] [20] 123 lines
[+20] [+] static int transmit_refer(struct sip_pvt *p, const char *dest)
10824
	affect the transfer() app or the pbx, but, well, to make this
11901
	affect the transfer() app or the pbx, but, well, to make this
10825
	useful we should have a STATUS code on transfer().
11902
	useful we should have a STATUS code on transfer().
10826
	*/
11903
	*/
10827
}
11904
}
10828

    
   
11905

   

    
   
11906
/*! \brief Send SIP INFO advice of charge message */

    
   
11907
static int transmit_info_with_aoc(struct sip_pvt *p, struct ast_aoc_decoded *decoded)

    
   
11908
{

    
   
11909
	struct sip_request req;

    
   
11910
	struct ast_str *str = ast_str_alloca(512);

    
   
11911
	const struct ast_aoc_unit_entry *unit_entry = ast_aoc_get_unit_info(decoded, 0);

    
   
11912
	enum ast_aoc_charge_type charging = ast_aoc_get_charge_type(decoded);

    
   
11913

   

    
   
11914
	reqprep(&req, p, SIP_INFO, 0, 1);

    
   
11915

   

    
   
11916
	if (ast_aoc_get_msg_type(decoded) == AST_AOC_D) {

    
   
11917
		ast_str_append(&str, 0, "type=active;");

    
   
11918
	} else if (ast_aoc_get_msg_type(decoded) == AST_AOC_E) {

    
   
11919
		ast_str_append(&str, 0, "type=terminated;");

    
   
11920
	} else {

    
   
11921
		/* unsupported message type */

    
   
11922
		return -1;

    
   
11923
	}

    
   
11924

   

    
   
11925
	switch (charging) {

    
   
11926
	case AST_AOC_CHARGE_FREE:

    
   
11927
		ast_str_append(&str, 0, "free-of-charge;");

    
   
11928
		break;

    
   
11929
	case AST_AOC_CHARGE_CURRENCY:

    
   
11930
		ast_str_append(&str, 0, "charging;");

    
   
11931
		ast_str_append(&str, 0, "charging-info=currency;");

    
   
11932
		ast_str_append(&str, 0, "amount=%u;", ast_aoc_get_currency_amount(decoded));

    
   
11933
		ast_str_append(&str, 0, "multiplier=%s;", ast_aoc_get_currency_multiplier_decimal(decoded));

    
   
11934
		if (!ast_strlen_zero(ast_aoc_get_currency_name(decoded))) {

    
   
11935
			ast_str_append(&str, 0, "currency=%s;", ast_aoc_get_currency_name(decoded));

    
   
11936
		}

    
   
11937
		break;

    
   
11938
	case AST_AOC_CHARGE_UNIT:

    
   
11939
		ast_str_append(&str, 0, "charging;");

    
   
11940
		ast_str_append(&str, 0, "charging-info=pulse;");

    
   
11941
		if (unit_entry) {

    
   
11942
			ast_str_append(&str, 0, "recorded-units=%u;", unit_entry->amount);

    
   
11943
		}

    
   
11944
		break;

    
   
11945
	default:

    
   
11946
		ast_str_append(&str, 0, "not-available;");

    
   
11947
	};

    
   
11948

   

    
   
11949
	add_header(&req, "AOC", ast_str_buffer(str));

    
   
11950

   

    
   
11951
	return send_request(p, &req, XMIT_RELIABLE, p->ocseq);

    
   
11952
}
10829

    
   
11953

   
10830
/*! \brief Send SIP INFO dtmf message, see Cisco documentation on cisco.com */
11954
/*! \brief Send SIP INFO dtmf message, see Cisco documentation on cisco.com */
10831
static int transmit_info_with_digit(struct sip_pvt *p, const char digit, unsigned int duration)
11955
static int transmit_info_with_digit(struct sip_pvt *p, const char digit, unsigned int duration)
10832
{
11956
{
10833
	struct sip_request req;
11957
	struct sip_request req;
[+20] [20] 1071 lines
[+20] [+] static enum check_auth_result register_verify(struct sip_pvt *p, struct sockaddr_in *sin,
11905
		}
13029
		}
11906
	}
13030
	}
11907

    
   
13031

   
11908
	ast_string_field_set(p, exten, name);
13032
	ast_string_field_set(p, exten, name);
11909
	build_contact(p);
13033
	build_contact(p);

    
   
13034
	if (req->ignore) {

    
   
13035
		/* Expires is a special case, where we only want to load the peer if this isn't a deregistration attempt */

    
   
13036
		const char *expires = get_header(req, "Expires");

    
   
13037
		int expire = atoi(expires);

    
   
13038

   

    
   
13039
		if (ast_strlen_zero(expires)) { /* No expires header; look in Contact */

    
   
13040
			if ((expires = strcasestr(get_header(req, "Contact"), ";expires="))) {

    
   
13041
				expire = atoi(expires + 9);

    
   
13042
			}

    
   
13043
		}

    
   
13044
		if (!ast_strlen_zero(expires) && expire == 0) {

    
   
13045
			transmit_response_with_date(p, "200 OK", req);

    
   
13046
			return 0;

    
   
13047
		}

    
   
13048
	}
11910
	peer = find_peer(name, NULL, TRUE, FINDPEERS, FALSE, 0);
13049
	peer = find_peer(name, NULL, TRUE, FINDPEERS, FALSE, 0);
11911
	if (!(peer && ast_apply_ha(peer->ha, sin))) {
13050
	if (!(peer && ast_apply_ha(peer->ha, sin))) {
11912
		/* Peer fails ACL check */
13051
		/* Peer fails ACL check */
11913
		if (peer) {
13052
		if (peer) {
11914
			unref_peer(peer, "register_verify: unref_peer: from find_peer operation");
13053
			unref_peer(peer, "register_verify: unref_peer: from find_peer operation");
[+20] [20] 217 lines
[+20] [+] static int get_pai(struct sip_pvt *p, struct sip_request *req)
12132
	char pai[256];
13271
	char pai[256];
12133
	char privacy[64];
13272
	char privacy[64];
12134
	char *cid_num = "";
13273
	char *cid_num = "";
12135
	char *cid_name = "";
13274
	char *cid_name = "";
12136
	int callingpres = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;
13275
	int callingpres = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;
12137
	char *start = NULL, *end = NULL;
13276
	char *start = NULL, *end = NULL, *uri = NULL;
12138

    
   
13277

   
12139
	ast_copy_string(pai, get_header(req, "P-Asserted-Identity"), sizeof(pai));
13278
	ast_copy_string(pai, get_header(req, "P-Asserted-Identity"), sizeof(pai));
12140

    
   
13279

   
12141
	if (ast_strlen_zero(pai)) {
13280
	if (ast_strlen_zero(pai)) {
12142
		return 0;
13281
		return 0;
[+20] [20] 10 lines
[+20] static int get_pai(struct sip_pvt *p, struct sip_request *req)
12153
		start = ast_skip_blanks(end);
13292
		start = ast_skip_blanks(end);
12154
	}
13293
	}
12155

    
   
13294

   
12156
	if (*start != '<')
13295
	if (*start != '<')
12157
		return 0;
13296
		return 0;

    
   
13297
	/* At this point, 'start' points to the URI in brackets.

    
   
13298
	 * We need a copy so that our comparison to the anonymous

    
   
13299
	 * URI is valid.

    
   
13300
	 */

    
   
13301
	uri = ast_strdupa(start);
12158
	*start++ = '\0';
13302
	*start++ = '\0';
12159
	end = strchr(start, '@');
13303
	end = strchr(start, '@');
12160
	if (!end)
13304
	if (!end)
12161
		return 0;
13305
		return 0;
12162
	*end++ = '\0';
13306
	*end++ = '\0';
12163
	if (!strncasecmp(start, "anonymous@anonymous.invalid", 27)) {
13307
	if (!strncasecmp(uri, "anonymous@anonymous.invalid", 27)) {
12164
		callingpres = AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED;
13308
		callingpres = AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED;
12165
		/*XXX Assume no change in cid_num. Perhaps it should be
13309
		/*XXX Assume no change in cid_num. Perhaps it should be
12166
		 * blanked?
13310
		 * blanked?
12167
		 */
13311
		 */
12168
		cid_num = (char *)p->cid_num;
13312
		cid_num = (char *)p->cid_num;
[+20] [20] 164 lines
[+20] [+] static int get_rdnis(struct sip_pvt *p, struct sip_request *oreq, char **name, char **number, int *reason)
12333
		params++;
13477
		params++;
12334
		while (*params == ';' || *params == ' ')
13478
		while (*params == ';' || *params == ' ')
12335
			params++;
13479
			params++;
12336
		/* Check if we have a reason parameter */
13480
		/* Check if we have a reason parameter */
12337
		if ((reason_param = strcasestr(params, "reason="))) {
13481
		if ((reason_param = strcasestr(params, "reason="))) {

    
   
13482
			char *end;
12338
			reason_param+=7;
13483
			reason_param+=7;

    
   
13484
			if ((end = strchr(reason_param, ';'))) {

    
   
13485
				*end = '\0';

    
   
13486
			}
12339
			/* Remove enclosing double-quotes */
13487
			/* Remove enclosing double-quotes */
12340
			if (*reason_param == '"')
13488
			if (*reason_param == '"')
12341
				ast_strip_quoted(reason_param, "\"", "\"");
13489
				ast_strip_quoted(reason_param, "\"", "\"");
12342
			if (!ast_strlen_zero(reason_param)) {
13490
			if (!ast_strlen_zero(reason_param)) {
12343
				sip_set_redirstr(p, reason_param);
13491
				sip_set_redirstr(p, reason_param);
[+20] [20] 47 lines
[+20] static int get_rdnis(struct sip_pvt *p, struct sip_request *oreq, char **name, char **number, int *reason)
12391

    
   
13539

   
12392
  \note If the incoming uri is a SIPS: uri, we are required to carry this across
13540
  \note If the incoming uri is a SIPS: uri, we are required to carry this across
12393
	the dialplan, so that the outbound call also is a sips: call or encrypted
13541
	the dialplan, so that the outbound call also is a sips: call or encrypted
12394
	IAX2 call. If that's not available, the call should FAIL.
13542
	IAX2 call. If that's not available, the call should FAIL.
12395
*/
13543
*/
12396
static int get_destination(struct sip_pvt *p, struct sip_request *oreq)
13544
static int get_destination(struct sip_pvt *p, struct sip_request *oreq, int *cc_recall_core_id)
12397
{
13545
{
12398
	char tmp[256] = "", *uri, *domain, *dummy = NULL;
13546
	char tmp[256] = "", *uri, *domain, *dummy = NULL;
12399
	char tmpf[256] = "", *from = NULL;
13547
	char tmpf[256] = "", *from = NULL;
12400
	struct sip_request *req;
13548
	struct sip_request *req;
12401
	char *decoded_uri;
13549
	char *decoded_uri;
12402
	
13550

   
12403
	req = oreq;
13551
	req = oreq;
12404
	if (!req)
13552
	if (!req)
12405
		req = &p->initreq;
13553
		req = &p->initreq;
12406

    
   
13554

   
12407
	/* Find the request URI */
13555
	/* Find the request URI */
12408
	if (req->rlPart2)
13556
	if (req->rlPart2)
12409
		ast_copy_string(tmp, REQ_OFFSET_TO_STR(req, rlPart2), sizeof(tmp));
13557
		ast_copy_string(tmp, REQ_OFFSET_TO_STR(req, rlPart2), sizeof(tmp));
12410
	
13558
	
12411
	uri = get_in_brackets(tmp);
13559
	uri = ast_strdupa(get_in_brackets(tmp));
12412

    
   
13560

   
12413
	if (parse_uri(uri, "sip:,sips:", &uri, &dummy, &domain, &dummy, NULL)) {
13561
	if (parse_uri(uri, "sip:,sips:", &uri, &dummy, &domain, &dummy, NULL)) {
12414
		ast_log(LOG_WARNING, "Not a SIP header (%s)?\n", uri);
13562
		ast_log(LOG_WARNING, "Not a SIP header (%s)?\n", uri);
12415
		return -1;
13563
		return -1;
12416
	}
13564
	}
[+20] [20] 29 lines
[+20] static int get_destination(struct sip_pvt *p, struct sip_request *oreq) [+] static int get_destination(struct sip_pvt *p, struct sip_request *oreq, int *cc_recall_core_id)
12446
			if (!sip_cfg.allow_external_domains && (req->method == SIP_INVITE || req->method == SIP_REFER)) {
13594
			if (!sip_cfg.allow_external_domains && (req->method == SIP_INVITE || req->method == SIP_REFER)) {
12447
				ast_debug(1, "Got SIP %s to non-local domain '%s'; refusing request.\n", sip_methods[req->method].text, p->domain);
13595
				ast_debug(1, "Got SIP %s to non-local domain '%s'; refusing request.\n", sip_methods[req->method].text, p->domain);
12448
				return -2;
13596
				return -2;
12449
			}
13597
			}
12450
		}
13598
		}
12451
		/* If we have a context defined, overwrite the original context */
13599
		/* If we don't have a peer (i.e. we're a guest call),
12452
		if (!ast_strlen_zero(domain_context))
13600
		 * overwrite the original context */

    
   
13601
		if (!ast_test_flag(&p->flags[1], SIP_PAGE2_HAVEPEERCONTEXT) && !ast_strlen_zero(domain_context))
12453
			ast_string_field_set(p, context, domain_context);
13602
			ast_string_field_set(p, context, domain_context);
12454
	}
13603
	}
12455

    
   
13604

   
12456
	/* If the request coming in is a subscription and subscribecontext has been specified use it */
13605
	/* If the request coming in is a subscription and subscribecontext has been specified use it */
12457
	if (req->method == SIP_SUBSCRIBE && !ast_strlen_zero(p->subscribecontext))
13606
	if (req->method == SIP_SUBSCRIBE && !ast_strlen_zero(p->subscribecontext))
[+20] [20] 5 lines
[+20] static int get_destination(struct sip_pvt *p, struct sip_request *oreq) [+] static int get_destination(struct sip_pvt *p, struct sip_request *oreq, int *cc_recall_core_id)
12463
	/* If this is a subscription we actually just need to see if a hint exists for the extension */
13612
	/* If this is a subscription we actually just need to see if a hint exists for the extension */
12464
	if (req->method == SIP_SUBSCRIBE) {
13613
	if (req->method == SIP_SUBSCRIBE) {
12465
		char hint[AST_MAX_EXTENSION];
13614
		char hint[AST_MAX_EXTENSION];
12466
		return (ast_get_hint(hint, sizeof(hint), NULL, 0, NULL, p->context, p->exten) ? 0 : -1);
13615
		return (ast_get_hint(hint, sizeof(hint), NULL, 0, NULL, p->context, p->exten) ? 0 : -1);
12467
	} else {
13616
	} else {

    
   
13617
		struct ast_cc_agent *agent;
12468
		decoded_uri = ast_strdupa(uri);
13618
		decoded_uri = ast_strdupa(uri);
12469
		ast_uri_decode(decoded_uri);
13619
		ast_uri_decode(decoded_uri);
12470
		/* Check the dialplan for the username part of the request URI,
13620
		/* Check the dialplan for the username part of the request URI,
12471
		   the domain will be stored in the SIPDOMAIN variable
13621
		   the domain will be stored in the SIPDOMAIN variable
12472
		   Since extensions.conf can have unescaped characters, try matching a decoded
13622
		   Since extensions.conf can have unescaped characters, try matching a decoded
12473
		   uri in addition to the non-decoded uri
13623
		   uri in addition to the non-decoded uri
12474
		   Return 0 if we have a matching extension */
13624
		   Return 0 if we have a matching extension */
12475
		if (ast_exists_extension(NULL, p->context, uri, 1, S_OR(p->cid_num, from)) || ast_exists_extension(NULL, p->context, decoded_uri, 1, S_OR(p->cid_num, from)) ||
13625
		if (ast_exists_extension(NULL, p->context, uri, 1, S_OR(p->cid_num, from)) || ast_exists_extension(NULL, p->context, decoded_uri, 1, S_OR(p->cid_num, from)) ||
12476
		    !strcmp(decoded_uri, ast_pickup_ext())) {
13626
		    !strcmp(decoded_uri, ast_pickup_ext())) {
12477
			if (!oreq)
13627
			if (!oreq)
12478
				ast_string_field_set(p, exten, decoded_uri);
13628
				ast_string_field_set(p, exten, decoded_uri);
12479
			return 0;
13629
			return 0;

    
   
13630
		} else if ((agent = find_sip_cc_agent_by_notify_uri(tmp))) {

    
   
13631
			struct sip_cc_agent_pvt *agent_pvt = agent->private_data;

    
   
13632
			/* This is a CC recall. We can set p's extension to the exten from

    
   
13633
			 * the original INVITE

    
   
13634
			 */

    
   
13635
			ast_string_field_set(p, exten, agent_pvt->original_exten);

    
   
13636
			/* And we need to let the CC core know that the caller is attempting

    
   
13637
			 * his recall

    
   
13638
			 */

    
   
13639
			ast_cc_agent_recalling(agent->core_id, "SIP caller %s is attempting recall",

    
   
13640
					agent->device_name);

    
   
13641
			if (cc_recall_core_id) {

    
   
13642
				*cc_recall_core_id = agent->core_id;

    
   
13643
			}

    
   
13644
			ao2_ref(agent, -1);

    
   
13645
			return 0;
12480
		}
13646
		}
12481
	}
13647
	}
12482

    
   
13648

   
12483
	/* Return 1 for pickup extension or overlap dialling support (if we support it) */
13649
	/* Return 1 for pickup extension or overlap dialling support (if we support it) */
12484
	if((ast_test_flag(&global_flags[1], SIP_PAGE2_ALLOWOVERLAP) &&
13650
	if((ast_test_flag(&global_flags[1], SIP_PAGE2_ALLOWOVERLAP) &&
[+20] [20] 172 lines
[+20] [+] static int get_refer_info(struct sip_pvt *transferer, struct sip_request *outgoing_req)
12657
		char *to = NULL, *from = NULL;
13823
		char *to = NULL, *from = NULL;
12658
		
13824
		
12659
		/* This is an attended transfer */
13825
		/* This is an attended transfer */
12660
		referdata->attendedtransfer = 1;
13826
		referdata->attendedtransfer = 1;
12661
		ast_copy_string(referdata->replaces_callid, ptr+9, sizeof(referdata->replaces_callid));
13827
		ast_copy_string(referdata->replaces_callid, ptr+9, sizeof(referdata->replaces_callid));

    
   
13828
		ast_uri_decode(referdata->replaces_callid);
12662
		if ((ptr = strchr(referdata->replaces_callid, ';'))) 	/* Find options */ {
13829
		if ((ptr = strchr(referdata->replaces_callid, ';'))) 	/* Find options */ {
12663
			*ptr++ = '\0';
13830
			*ptr++ = '\0';
12664
		}
13831
		}
12665
		
13832
		
12666
		if (ptr) {
13833
		if (ptr) {
[+20] [20] 7 lines
[+20] static int get_refer_info(struct sip_pvt *transferer, struct sip_request *outgoing_req)
12674
			ptr = to + 7;
13841
			ptr = to + 7;
12675
			if ((to = strchr(ptr, '&')))
13842
			if ((to = strchr(ptr, '&')))
12676
				*to = '\0';
13843
				*to = '\0';
12677
			if ((to = strchr(ptr, ';')))
13844
			if ((to = strchr(ptr, ';')))
12678
				*to = '\0';
13845
				*to = '\0';
12679
			ast_uri_decode(ptr);

   
12680
			ast_copy_string(referdata->replaces_callid_totag, ptr, sizeof(referdata->replaces_callid_totag));
13846
			ast_copy_string(referdata->replaces_callid_totag, ptr, sizeof(referdata->replaces_callid_totag));
12681
		}
13847
		}
12682
		
13848
		
12683
		if (from) {
13849
		if (from) {
12684
			ptr = from + 9;
13850
			ptr = from + 9;
12685
			if ((to = strchr(ptr, '&')))
13851
			if ((to = strchr(ptr, '&')))
12686
				*to = '\0';
13852
				*to = '\0';
12687
			if ((to = strchr(ptr, ';')))
13853
			if ((to = strchr(ptr, ';')))
12688
				*to = '\0';
13854
				*to = '\0';
12689
			ast_uri_decode(ptr);

   
12690
			ast_copy_string(referdata->replaces_callid_fromtag, ptr, sizeof(referdata->replaces_callid_fromtag));
13855
			ast_copy_string(referdata->replaces_callid_fromtag, ptr, sizeof(referdata->replaces_callid_fromtag));
12691
		}
13856
		}
12692
		
13857
		
12693
		if (!sip_cfg.pedanticsipchecking)
13858
		if (!sip_cfg.pedanticsipchecking)
12694
			ast_debug(2, "Attended transfer: Will use Replace-Call-ID : %s (No check of from/to tags)\n", referdata->replaces_callid );
13859
			ast_debug(2, "Attended transfer: Will use Replace-Call-ID : %s (No check of from/to tags)\n", referdata->replaces_callid );
[+20] [20] 269 lines
[+20] [+] static enum check_auth_result check_peer_ok(struct sip_pvt *p, char *of,
12964
	}
14129
	}
12965

    
   
14130

   
12966
	/* Take the peer */
14131
	/* Take the peer */
12967
	ast_copy_flags(&p->flags[0], &peer->flags[0], SIP_FLAGS_TO_COPY);
14132
	ast_copy_flags(&p->flags[0], &peer->flags[0], SIP_FLAGS_TO_COPY);
12968
	ast_copy_flags(&p->flags[1], &peer->flags[1], SIP_PAGE2_FLAGS_TO_COPY);
14133
	ast_copy_flags(&p->flags[1], &peer->flags[1], SIP_PAGE2_FLAGS_TO_COPY);

    
   
14134
	ast_copy_flags(&p->flags[2], &peer->flags[2], SIP_PAGE3_FLAGS_TO_COPY);
12969

    
   
14135

   
12970
	if (ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT) && p->udptl) {
14136
	if (ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT) && p->udptl) {
12971
		p->t38_maxdatagram = peer->t38_maxdatagram;
14137
		p->t38_maxdatagram = peer->t38_maxdatagram;
12972
		set_t38_capabilities(p);
14138
		set_t38_capabilities(p);
12973
	}
14139
	}
[+20] [20] 12 lines
[+20] static enum check_auth_result check_peer_ok(struct sip_pvt *p, char *of,
12986
	ast_string_field_set(p, mohsuggest, peer->mohsuggest);
14152
	ast_string_field_set(p, mohsuggest, peer->mohsuggest);
12987
	ast_string_field_set(p, parkinglot, peer->parkinglot);
14153
	ast_string_field_set(p, parkinglot, peer->parkinglot);
12988
	ast_string_field_set(p, engine, peer->engine);
14154
	ast_string_field_set(p, engine, peer->engine);
12989
	p->disallowed_methods = peer->disallowed_methods;
14155
	p->disallowed_methods = peer->disallowed_methods;
12990
	set_pvt_allowed_methods(p, req);
14156
	set_pvt_allowed_methods(p, req);

    
   
14157
	ast_cc_copy_config_params(p->cc_params, peer->cc_params);
12991
	if (peer->callingpres)	/* Peer calling pres setting will override RPID */
14158
	if (peer->callingpres)	/* Peer calling pres setting will override RPID */
12992
		p->callingpres = peer->callingpres;
14159
		p->callingpres = peer->callingpres;
12993
	if (peer->maxms && peer->lastms)
14160
	if (peer->maxms && peer->lastms)
12994
		p->timer_t1 = peer->lastms < global_t1min ? global_t1min : peer->lastms;
14161
		p->timer_t1 = peer->lastms < global_t1min ? global_t1min : peer->lastms;
12995
 	else
14162
 	else
[+20] [20] 11 lines
[+20] static enum check_auth_result check_peer_ok(struct sip_pvt *p, char *of,
13007
		ast_string_field_set(p, peermd5secret, NULL);
14174
		ast_string_field_set(p, peermd5secret, NULL);
13008
	}
14175
	}
13009
	if (!(res = check_auth(p, req, peer->name, p->peersecret, p->peermd5secret, sipmethod, uri2, reliable, req->ignore))) {
14176
	if (!(res = check_auth(p, req, peer->name, p->peersecret, p->peermd5secret, sipmethod, uri2, reliable, req->ignore))) {
13010
		ast_copy_flags(&p->flags[0], &peer->flags[0], SIP_FLAGS_TO_COPY);
14177
		ast_copy_flags(&p->flags[0], &peer->flags[0], SIP_FLAGS_TO_COPY);
13011
		ast_copy_flags(&p->flags[1], &peer->flags[1], SIP_PAGE2_FLAGS_TO_COPY);
14178
		ast_copy_flags(&p->flags[1], &peer->flags[1], SIP_PAGE2_FLAGS_TO_COPY);

    
   
14179
		ast_copy_flags(&p->flags[2], &peer->flags[2], SIP_PAGE3_FLAGS_TO_COPY);
13012
		/* If we have a call limit, set flag */
14180
		/* If we have a call limit, set flag */
13013
		if (peer->call_limit)
14181
		if (peer->call_limit)
13014
			ast_set_flag(&p->flags[0], SIP_CALL_LIMIT);
14182
			ast_set_flag(&p->flags[0], SIP_CALL_LIMIT);
13015
		ast_string_field_set(p, peername, peer->name);
14183
		ast_string_field_set(p, peername, peer->name);
13016
		ast_string_field_set(p, authname, peer->name);
14184
		ast_string_field_set(p, authname, peer->name);
[+20] [20] 21 lines
[+20] static enum check_auth_result check_peer_ok(struct sip_pvt *p, char *of,
13038
					ast_shrink_phone_number(tmp);
14206
					ast_shrink_phone_number(tmp);
13039
				ast_string_field_set(p, cid_num, tmp);
14207
				ast_string_field_set(p, cid_num, tmp);
13040
			}
14208
			}
13041
			if (!ast_strlen_zero(peer->cid_name))
14209
			if (!ast_strlen_zero(peer->cid_name))
13042
				ast_string_field_set(p, cid_name, peer->cid_name);
14210
				ast_string_field_set(p, cid_name, peer->cid_name);

    
   
14211
			if (!ast_strlen_zero(peer->cid_tag))

    
   
14212
				ast_string_field_set(p, cid_tag, peer->cid_tag);
13043
			if (peer->callingpres)
14213
			if (peer->callingpres)
13044
				p->callingpres = peer->callingpres;
14214
				p->callingpres = peer->callingpres;
13045
		}
14215
		}
13046
		ast_string_field_set(p, fullcontact, peer->fullcontact);
14216
		ast_string_field_set(p, fullcontact, peer->fullcontact);
13047
		if (!ast_strlen_zero(peer->context))
14217
		if (!ast_strlen_zero(peer->context))
[+20] [20] 358 lines
[+20] [+] static int peer_status(struct sip_peer *peer, char *status, int statuslen)
13406
		res = -1;
14576
		res = -1;
13407
	}
14577
	}
13408
	return res;
14578
	return res;
13409
}
14579
}
13410

    
   
14580

   
13411
/*! \brief return Yes or No depending on the argument.

   
13412
 * This is used in many places in CLI command, having a function to generate

   
13413
 * this helps maintaining a consistent output (and possibly emitting the

   
13414
 * output in other languages, at some point).

   
13415
 */

   
13416
static const char *cli_yesno(int x)

   
13417
{

   
13418
	return x ? "Yes" : "No";

   
13419
}

   
13420

    
   

   
13421
/*! \brief  Show active TCP connections */
14581
/*! \brief  Show active TCP connections */
13422
static char *sip_show_tcp(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
14582
static char *sip_show_tcp(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
13423
{
14583
{
13424
	struct sip_threadinfo *th;
14584
	struct sip_threadinfo *th;
13425
	struct ao2_iterator i;
14585
	struct ao2_iterator i;
[+20] [20] 87 lines
[+20] [+] static char *sip_show_users(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
13513

    
   
14673

   
13514
		ast_cli(a->fd, FORMAT, user->name,
14674
		ast_cli(a->fd, FORMAT, user->name,
13515
			user->secret,
14675
			user->secret,
13516
			user->accountcode,
14676
			user->accountcode,
13517
			user->context,
14677
			user->context,
13518
			cli_yesno(user->ha != NULL),
14678
			AST_CLI_YESNO(user->ha != NULL),
13519
			cli_yesno(ast_test_flag(&user->flags[0], SIP_NAT_FORCE_RPORT)));
14679
			AST_CLI_YESNO(ast_test_flag(&user->flags[0], SIP_NAT_FORCE_RPORT)));
13520
		ao2_unlock(user);
14680
		ao2_unlock(user);
13521
		unref_peer(user, "sip show users");
14681
		unref_peer(user, "sip show users");
13522
	}
14682
	}
13523
	ao2_iterator_destroy(&user_iter);
14683
	ao2_iterator_destroy(&user_iter);
13524

    
   
14684

   
[+20] [20] 22 lines
[+20] [+] static int manager_show_registry(struct mansession *s, const struct message *m)
13547
			"Event: RegistryEntry\r\n"
14707
			"Event: RegistryEntry\r\n"
13548
			"%s"
14708
			"%s"
13549
			"Host: %s\r\n"
14709
			"Host: %s\r\n"
13550
			"Port: %d\r\n"
14710
			"Port: %d\r\n"
13551
			"Username: %s\r\n"
14711
			"Username: %s\r\n"

    
   
14712
			"Domain: %s\r\n"

    
   
14713
			"DomainPort: %d\r\n"
13552
			"Refresh: %d\r\n"
14714
			"Refresh: %d\r\n"
13553
			"State: %s\r\n"
14715
			"State: %s\r\n"
13554
			"RegistrationTime: %ld\r\n"
14716
			"RegistrationTime: %ld\r\n"
13555
			"\r\n", idtext, iterator->hostname, iterator->portno ? iterator->portno : STANDARD_SIP_PORT,
14717
			"\r\n",
13556
					  iterator->username, iterator->refresh, regstate2str(iterator->regstate), (long) iterator->regtime.tv_sec);
14718
			idtext,

    
   
14719
			iterator->hostname,

    
   
14720
			iterator->portno ? iterator->portno : STANDARD_SIP_PORT,

    
   
14721
			iterator->username,

    
   
14722
			S_OR(iterator->regdomain,iterator->hostname),

    
   
14723
			iterator->regdomainport ? iterator->regdomainport : STANDARD_SIP_PORT,

    
   
14724
			iterator->refresh,

    
   
14725
			regstate2str(iterator->regstate),

    
   
14726
			(long) iterator->regtime.tv_sec);
13557
		ASTOBJ_UNLOCK(iterator);
14727
		ASTOBJ_UNLOCK(iterator);
13558
		total++;
14728
		total++;
13559
	} while(0));
14729
	} while(0));
13560

    
   
14730

   
13561
	astman_append(s,
14731
	astman_append(s,
[+20] [20] 808 lines
[+20] [+] static char *_sip_show_peer(int type, int fd, struct mansession *s, const struct message *m, int argc, const char *argv[])
14370
		ast_cli(fd, "  Transfer mode: %s\n", transfermode2str(peer->allowtransfer));
15540
		ast_cli(fd, "  Transfer mode: %s\n", transfermode2str(peer->allowtransfer));
14371
		ast_cli(fd, "  CallingPres  : %s\n", ast_describe_caller_presentation(peer->callingpres));
15541
		ast_cli(fd, "  CallingPres  : %s\n", ast_describe_caller_presentation(peer->callingpres));
14372
		if (!ast_strlen_zero(peer->fromuser))
15542
		if (!ast_strlen_zero(peer->fromuser))
14373
			ast_cli(fd, "  FromUser     : %s\n", peer->fromuser);
15543
			ast_cli(fd, "  FromUser     : %s\n", peer->fromuser);
14374
		if (!ast_strlen_zero(peer->fromdomain))
15544
		if (!ast_strlen_zero(peer->fromdomain))
14375
			ast_cli(fd, "  FromDomain   : %s\n", peer->fromdomain);
15545
			ast_cli(fd, "  FromDomain   : %s Port %d\n", peer->fromdomain, (peer->fromdomainport) ? peer->fromdomainport : STANDARD_SIP_PORT);
14376
		ast_cli(fd, "  Callgroup    : ");
15546
		ast_cli(fd, "  Callgroup    : ");
14377
		print_group(fd, peer->callgroup, 0);
15547
		print_group(fd, peer->callgroup, 0);
14378
		ast_cli(fd, "  Pickupgroup  : ");
15548
		ast_cli(fd, "  Pickupgroup  : ");
14379
		print_group(fd, peer->pickupgroup, 0);
15549
		print_group(fd, peer->pickupgroup, 0);
14380
		peer_mailboxes_to_str(&mailbox_str, peer);
15550
		peer_mailboxes_to_str(&mailbox_str, peer);
14381
		ast_cli(fd, "  MOH Suggest  : %s\n", peer->mohsuggest);
15551
		ast_cli(fd, "  MOH Suggest  : %s\n", peer->mohsuggest);
14382
		ast_cli(fd, "  Mailbox      : %s\n", mailbox_str->str);
15552
		ast_cli(fd, "  Mailbox      : %s\n", mailbox_str->str);
14383
		ast_cli(fd, "  VM Extension : %s\n", peer->vmexten);
15553
		ast_cli(fd, "  VM Extension : %s\n", peer->vmexten);
14384
		ast_cli(fd, "  LastMsgsSent : %d/%d\n", (peer->lastmsgssent & 0x7fff0000) >> 16, peer->lastmsgssent & 0xffff);
15554
		ast_cli(fd, "  LastMsgsSent : %d/%d\n", (peer->lastmsgssent & 0x7fff0000) >> 16, peer->lastmsgssent & 0xffff);
14385
		ast_cli(fd, "  Call limit   : %d\n", peer->call_limit);
15555
		ast_cli(fd, "  Call limit   : %d\n", peer->call_limit);
14386
		if (peer->busy_level)
15556
		if (peer->busy_level)
14387
			ast_cli(fd, "  Busy level   : %d\n", peer->busy_level);
15557
			ast_cli(fd, "  Busy level   : %d\n", peer->busy_level);
14388
		ast_cli(fd, "  Dynamic      : %s\n", cli_yesno(peer->host_dynamic));
15558
		ast_cli(fd, "  Dynamic      : %s\n", AST_CLI_YESNO(peer->host_dynamic));
14389
		ast_cli(fd, "  Callerid     : %s\n", ast_callerid_merge(cbuf, sizeof(cbuf), peer->cid_name, peer->cid_num, "<unspecified>"));
15559
		ast_cli(fd, "  Callerid     : %s\n", ast_callerid_merge(cbuf, sizeof(cbuf), peer->cid_name, peer->cid_num, "<unspecified>"));
14390
		ast_cli(fd, "  MaxCallBR    : %d kbps\n", peer->maxcallbitrate);
15560
		ast_cli(fd, "  MaxCallBR    : %d kbps\n", peer->maxcallbitrate);
14391
		ast_cli(fd, "  Expire       : %ld\n", ast_sched_when(sched, peer->expire));
15561
		ast_cli(fd, "  Expire       : %ld\n", ast_sched_when(sched, peer->expire));
14392
		ast_cli(fd, "  Insecure     : %s\n", insecure2str(ast_test_flag(&peer->flags[0], SIP_INSECURE)));
15562
		ast_cli(fd, "  Insecure     : %s\n", insecure2str(ast_test_flag(&peer->flags[0], SIP_INSECURE)));
14393
		ast_cli(fd, "  Force rport  : %s\n", cli_yesno(ast_test_flag(&peer->flags[0], SIP_NAT_FORCE_RPORT)));
15563
		ast_cli(fd, "  Force rport  : %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[0], SIP_NAT_FORCE_RPORT)));
14394
		ast_cli(fd, "  ACL          : %s\n", cli_yesno(peer->ha != NULL));
15564
		ast_cli(fd, "  ACL          : %s\n", AST_CLI_YESNO(peer->ha != NULL));
14395
		ast_cli(fd, "  T.38 support : %s\n", cli_yesno(ast_test_flag(&peer->flags[1], SIP_PAGE2_T38SUPPORT)));
15565
		ast_cli(fd, "  DirectMedACL : %s\n", AST_CLI_YESNO(peer->directmediaha != NULL));

    
   
15566
		ast_cli(fd, "  T.38 support : %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[1], SIP_PAGE2_T38SUPPORT)));
14396
		ast_cli(fd, "  T.38 EC mode : %s\n", faxec2str(ast_test_flag(&peer->flags[1], SIP_PAGE2_T38SUPPORT)));
15567
		ast_cli(fd, "  T.38 EC mode : %s\n", faxec2str(ast_test_flag(&peer->flags[1], SIP_PAGE2_T38SUPPORT)));
14397
		ast_cli(fd, "  T.38 MaxDtgrm: %d\n", peer->t38_maxdatagram);
15568
		ast_cli(fd, "  T.38 MaxDtgrm: %d\n", peer->t38_maxdatagram);
14398
		ast_cli(fd, "  DirectMedia  : %s\n", cli_yesno(ast_test_flag(&peer->flags[0], SIP_DIRECT_MEDIA)));
15569
		ast_cli(fd, "  DirectMedia  : %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[0], SIP_DIRECT_MEDIA)));
14399
		ast_cli(fd, "  PromiscRedir : %s\n", cli_yesno(ast_test_flag(&peer->flags[0], SIP_PROMISCREDIR)));
15570
		ast_cli(fd, "  PromiscRedir : %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[0], SIP_PROMISCREDIR)));
14400
		ast_cli(fd, "  User=Phone   : %s\n", cli_yesno(ast_test_flag(&peer->flags[0], SIP_USEREQPHONE)));
15571
		ast_cli(fd, "  User=Phone   : %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[0], SIP_USEREQPHONE)));
14401
		ast_cli(fd, "  Video Support: %s\n", cli_yesno(ast_test_flag(&peer->flags[1], SIP_PAGE2_VIDEOSUPPORT)));
15572
		ast_cli(fd, "  Video Support: %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[1], SIP_PAGE2_VIDEOSUPPORT) || ast_test_flag(&peer->flags[1], SIP_PAGE2_VIDEOSUPPORT_ALWAYS)));
14402
		ast_cli(fd, "  Text Support : %s\n", cli_yesno(ast_test_flag(&peer->flags[1], SIP_PAGE2_TEXTSUPPORT)));
15573
		ast_cli(fd, "  Text Support : %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[1], SIP_PAGE2_TEXTSUPPORT)));
14403
		ast_cli(fd, "  Ign SDP ver  : %s\n", cli_yesno(ast_test_flag(&peer->flags[1], SIP_PAGE2_IGNORESDPVERSION)));
15574
		ast_cli(fd, "  Ign SDP ver  : %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[1], SIP_PAGE2_IGNORESDPVERSION)));
14404
		ast_cli(fd, "  Trust RPID   : %s\n", cli_yesno(ast_test_flag(&peer->flags[0], SIP_TRUSTRPID)));
15575
		ast_cli(fd, "  Trust RPID   : %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[0], SIP_TRUSTRPID)));
14405
		ast_cli(fd, "  Send RPID    : %s\n", cli_yesno(ast_test_flag(&peer->flags[0], SIP_SENDRPID)));
15576
		ast_cli(fd, "  Send RPID    : %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[0], SIP_SENDRPID)));
14406
		ast_cli(fd, "  Subscriptions: %s\n", cli_yesno(ast_test_flag(&peer->flags[1], SIP_PAGE2_ALLOWSUBSCRIBE)));
15577
		ast_cli(fd, "  Subscriptions: %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[1], SIP_PAGE2_ALLOWSUBSCRIBE)));
14407
		ast_cli(fd, "  Overlap dial : %s\n", cli_yesno(ast_test_flag(&peer->flags[1], SIP_PAGE2_ALLOWOVERLAP)));
15578
		ast_cli(fd, "  Overlap dial : %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[1], SIP_PAGE2_ALLOWOVERLAP)));
14408
		if (peer->outboundproxy)
15579
		if (peer->outboundproxy)
14409
			ast_cli(fd, "  Outb. proxy  : %s %s\n", ast_strlen_zero(peer->outboundproxy->name) ? "<not set>" : peer->outboundproxy->name,
15580
			ast_cli(fd, "  Outb. proxy  : %s %s\n", ast_strlen_zero(peer->outboundproxy->name) ? "<not set>" : peer->outboundproxy->name,
14410
							peer->outboundproxy->force ? "(forced)" : "");
15581
							peer->outboundproxy->force ? "(forced)" : "");
14411

    
   
15582

   
14412
		/* - is enumerated */
15583
		/* - is enumerated */
[+20] [20] 27 lines
[+20] static char *_sip_show_peer(int type, int fd, struct mansession *s, const struct message *m, int argc, const char *argv[])
14440
		ast_cli(fd, "%s\n", codec_buf);
15611
		ast_cli(fd, "%s\n", codec_buf);
14441
		ast_cli(fd, "  Codec Order  : (");
15612
		ast_cli(fd, "  Codec Order  : (");
14442
		print_codec_to_cli(fd, &peer->prefs);
15613
		print_codec_to_cli(fd, &peer->prefs);
14443
		ast_cli(fd, ")\n");
15614
		ast_cli(fd, ")\n");
14444

    
   
15615

   
14445
		ast_cli(fd, "  Auto-Framing :  %s \n", cli_yesno(peer->autoframing));
15616
		ast_cli(fd, "  Auto-Framing :  %s \n", AST_CLI_YESNO(peer->autoframing));
14446
		ast_cli(fd, "  100 on REG   : %s\n", ast_test_flag(&peer->flags[1], SIP_PAGE2_REGISTERTRYING) ? "Yes" : "No");
15617
		ast_cli(fd, "  100 on REG   : %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[1], SIP_PAGE2_REGISTERTRYING)));
14447
		ast_cli(fd, "  Status       : ");
15618
		ast_cli(fd, "  Status       : ");
14448
		peer_status(peer, status, sizeof(status));
15619
		peer_status(peer, status, sizeof(status));
14449
		ast_cli(fd, "%s\n", status);
15620
		ast_cli(fd, "%s\n", status);
14450
 		ast_cli(fd, "  Useragent    : %s\n", peer->useragent);
15621
 		ast_cli(fd, "  Useragent    : %s\n", peer->useragent);
14451
 		ast_cli(fd, "  Reg. Contact : %s\n", peer->fullcontact);
15622
 		ast_cli(fd, "  Reg. Contact : %s\n", peer->fullcontact);
[+20] [20] 8 lines
[+20] static char *_sip_show_peer(int type, int fd, struct mansession *s, const struct message *m, int argc, const char *argv[])
14460
		ast_cli(fd, "  Sess-Refresh : %s\n", strefresher2str(peer->stimer.st_ref));
15631
		ast_cli(fd, "  Sess-Refresh : %s\n", strefresher2str(peer->stimer.st_ref));
14461
		ast_cli(fd, "  Sess-Expires : %d secs\n", peer->stimer.st_max_se);
15632
		ast_cli(fd, "  Sess-Expires : %d secs\n", peer->stimer.st_max_se);
14462
		ast_cli(fd, "  Min-Sess     : %d secs\n", peer->stimer.st_min_se);
15633
		ast_cli(fd, "  Min-Sess     : %d secs\n", peer->stimer.st_min_se);
14463
		ast_cli(fd, "  RTP Engine   : %s\n", peer->engine);
15634
		ast_cli(fd, "  RTP Engine   : %s\n", peer->engine);
14464
		ast_cli(fd, "  Parkinglot   : %s\n", peer->parkinglot);
15635
		ast_cli(fd, "  Parkinglot   : %s\n", peer->parkinglot);
14465
		ast_cli(fd, "  Use Reason   : %s\n", ast_test_flag(&peer->flags[1], SIP_PAGE2_Q850_REASON) ? "Yes" : "No");
15636
		ast_cli(fd, "  Use Reason   : %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[1], SIP_PAGE2_Q850_REASON)));
14466
		ast_cli(fd, "\n");
15637
		ast_cli(fd, "\n");
14467
		peer = unref_peer(peer, "sip_show_peer: unref_peer: done with peer ptr");
15638
		peer = unref_peer(peer, "sip_show_peer: unref_peer: done with peer ptr");
14468
	} else  if (peer && type == 1) { /* manager listing */
15639
	} else  if (peer && type == 1) { /* manager listing */
14469
		char buffer[256];
15640
		char buffer[256];
14470
		struct ast_str *mailbox_str = ast_str_alloca(512);
15641
		struct ast_str *mailbox_str = ast_str_alloca(512);
[+20] [20] 10 lines
[+20] static char *_sip_show_peer(int type, int fd, struct mansession *s, const struct message *m, int argc, const char *argv[])
14481
		astman_append(s, "AMAflags: %s\r\n", ast_cdr_flags2str(peer->amaflags));
15652
		astman_append(s, "AMAflags: %s\r\n", ast_cdr_flags2str(peer->amaflags));
14482
		astman_append(s, "CID-CallingPres: %s\r\n", ast_describe_caller_presentation(peer->callingpres));
15653
		astman_append(s, "CID-CallingPres: %s\r\n", ast_describe_caller_presentation(peer->callingpres));
14483
		if (!ast_strlen_zero(peer->fromuser))
15654
		if (!ast_strlen_zero(peer->fromuser))
14484
			astman_append(s, "SIP-FromUser: %s\r\n", peer->fromuser);
15655
			astman_append(s, "SIP-FromUser: %s\r\n", peer->fromuser);
14485
		if (!ast_strlen_zero(peer->fromdomain))
15656
		if (!ast_strlen_zero(peer->fromdomain))
14486
			astman_append(s, "SIP-FromDomain: %s\r\n", peer->fromdomain);
15657
			astman_append(s, "SIP-FromDomain: %s\r\nSip-FromDomain-Port: %d\r\n", peer->fromdomain, (peer->fromdomainport) ? peer->fromdomainport : STANDARD_SIP_PORT);
14487
		astman_append(s, "Callgroup: ");
15658
		astman_append(s, "Callgroup: ");
14488
		astman_append(s, "%s\r\n", ast_print_group(buffer, sizeof(buffer), peer->callgroup));
15659
		astman_append(s, "%s\r\n", ast_print_group(buffer, sizeof(buffer), peer->callgroup));
14489
		astman_append(s, "Pickupgroup: ");
15660
		astman_append(s, "Pickupgroup: ");
14490
		astman_append(s, "%s\r\n", ast_print_group(buffer, sizeof(buffer), peer->pickupgroup));
15661
		astman_append(s, "%s\r\n", ast_print_group(buffer, sizeof(buffer), peer->pickupgroup));
14491
		astman_append(s, "MOHSuggest: %s\r\n", peer->mohsuggest);
15662
		astman_append(s, "MOHSuggest: %s\r\n", peer->mohsuggest);
[+20] [20] 152 lines
[+20] [+] static char *sip_show_user(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
14644
		ast_cli(a->fd, "  Callgroup    : ");
15815
		ast_cli(a->fd, "  Callgroup    : ");
14645
		print_group(a->fd, user->callgroup, 0);
15816
		print_group(a->fd, user->callgroup, 0);
14646
		ast_cli(a->fd, "  Pickupgroup  : ");
15817
		ast_cli(a->fd, "  Pickupgroup  : ");
14647
		print_group(a->fd, user->pickupgroup, 0);
15818
		print_group(a->fd, user->pickupgroup, 0);
14648
		ast_cli(a->fd, "  Callerid     : %s\n", ast_callerid_merge(cbuf, sizeof(cbuf), user->cid_name, user->cid_num, "<unspecified>"));
15819
		ast_cli(a->fd, "  Callerid     : %s\n", ast_callerid_merge(cbuf, sizeof(cbuf), user->cid_name, user->cid_num, "<unspecified>"));
14649
		ast_cli(a->fd, "  ACL          : %s\n", cli_yesno(user->ha != NULL));
15820
		ast_cli(a->fd, "  ACL          : %s\n", AST_CLI_YESNO(user->ha != NULL));
14650
 		ast_cli(a->fd, "  Sess-Timers  : %s\n", stmode2str(user->stimer.st_mode_oper));
15821
 		ast_cli(a->fd, "  Sess-Timers  : %s\n", stmode2str(user->stimer.st_mode_oper));
14651
 		ast_cli(a->fd, "  Sess-Refresh : %s\n", strefresher2str(user->stimer.st_ref));
15822
 		ast_cli(a->fd, "  Sess-Refresh : %s\n", strefresher2str(user->stimer.st_ref));
14652
 		ast_cli(a->fd, "  Sess-Expires : %d secs\n", user->stimer.st_max_se);
15823
 		ast_cli(a->fd, "  Sess-Expires : %d secs\n", user->stimer.st_max_se);
14653
 		ast_cli(a->fd, "  Sess-Min-SE  : %d secs\n", user->stimer.st_min_se);
15824
 		ast_cli(a->fd, "  Sess-Min-SE  : %d secs\n", user->stimer.st_min_se);
14654
		ast_cli(a->fd, "  RTP Engine   : %s\n", user->engine);
15825
		ast_cli(a->fd, "  RTP Engine   : %s\n", user->engine);
14655

    
   
15826

   
14656
		ast_cli(a->fd, "  Codec Order  : (");
15827
		ast_cli(a->fd, "  Codec Order  : (");
14657
		print_codec_to_cli(a->fd, &user->prefs);
15828
		print_codec_to_cli(a->fd, &user->prefs);
14658
		ast_cli(a->fd, ")\n");
15829
		ast_cli(a->fd, ")\n");
14659

    
   
15830

   
14660
		ast_cli(a->fd, "  Auto-Framing:  %s \n", cli_yesno(user->autoframing));
15831
		ast_cli(a->fd, "  Auto-Framing:  %s \n", AST_CLI_YESNO(user->autoframing));
14661
		if (user->chanvars) {
15832
		if (user->chanvars) {
14662
 			ast_cli(a->fd, "  Variables    :\n");
15833
 			ast_cli(a->fd, "  Variables    :\n");
14663
			for (v = user->chanvars ; v ; v = v->next)
15834
			for (v = user->chanvars ; v ; v = v->next)
14664
 				ast_cli(a->fd, "                 %s = %s\n", v->name, v->value);
15835
 				ast_cli(a->fd, "                 %s = %s\n", v->name, v->value);
14665
		}
15836
		}
[+20] [20] 57 lines
[+20] [+] static char *sip_show_sched(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
14723
static char *sip_show_registry(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
15894
static char *sip_show_registry(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
14724
{
15895
{
14725
#define FORMAT2 "%-30.30s %-6.6s %-12.12s  %8.8s %-20.20s %-25.25s\n"
15896
#define FORMAT2 "%-30.30s %-6.6s %-12.12s  %8.8s %-20.20s %-25.25s\n"
14726
#define FORMAT  "%-30.30s %-6.6s %-12.12s  %8d %-20.20s %-25.25s\n"
15897
#define FORMAT  "%-30.30s %-6.6s %-12.12s  %8d %-20.20s %-25.25s\n"
14727
	char host[80];
15898
	char host[80];

    
   
15899
	char user[80];
14728
	char tmpdat[256];
15900
	char tmpdat[256];
14729
	struct ast_tm tm;
15901
	struct ast_tm tm;
14730
	int counter = 0;
15902
	int counter = 0;
14731

    
   
15903

   
14732
	switch (cmd) {
15904
	switch (cmd) {
[+20] [20] 12 lines
[+20] static char *sip_show_registry(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
14745
	ast_cli(a->fd, FORMAT2, "Host", "dnsmgr", "Username", "Refresh", "State", "Reg.Time");
15917
	ast_cli(a->fd, FORMAT2, "Host", "dnsmgr", "Username", "Refresh", "State", "Reg.Time");
14746
	
15918
	
14747
	ASTOBJ_CONTAINER_TRAVERSE(&regl, 1, do {
15919
	ASTOBJ_CONTAINER_TRAVERSE(&regl, 1, do {
14748
		ASTOBJ_RDLOCK(iterator);
15920
		ASTOBJ_RDLOCK(iterator);
14749
		snprintf(host, sizeof(host), "%s:%d", iterator->hostname, iterator->portno ? iterator->portno : STANDARD_SIP_PORT);
15921
		snprintf(host, sizeof(host), "%s:%d", iterator->hostname, iterator->portno ? iterator->portno : STANDARD_SIP_PORT);

    
   
15922
		snprintf(user, sizeof(user), "%s", iterator->username);

    
   
15923
		if (!ast_strlen_zero(iterator->regdomain)) {

    
   
15924
			snprintf(tmpdat, sizeof(tmpdat), "%s", user);

    
   
15925
			snprintf(user, sizeof(user), "%s@%s", tmpdat, iterator->regdomain);}

    
   
15926
		if (iterator->regdomainport) {

    
   
15927
			snprintf(tmpdat, sizeof(tmpdat), "%s", user);

    
   
15928
			snprintf(user, sizeof(user), "%s:%d", tmpdat, iterator->regdomainport);}
14750
		if (iterator->regtime.tv_sec) {
15929
		if (iterator->regtime.tv_sec) {
14751
			ast_localtime(&iterator->regtime, &tm, NULL);
15930
			ast_localtime(&iterator->regtime, &tm, NULL);
14752
			ast_strftime(tmpdat, sizeof(tmpdat), "%a, %d %b %Y %T", &tm);
15931
			ast_strftime(tmpdat, sizeof(tmpdat), "%a, %d %b %Y %T", &tm);
14753
		} else
15932
		} else
14754
			tmpdat[0] = '\0';
15933
			tmpdat[0] = '\0';
14755
		ast_cli(a->fd, FORMAT, host, (iterator->dnsmgr) ? "Y" : "N", iterator->username, iterator->refresh, regstate2str(iterator->regstate), tmpdat);
15934
		ast_cli(a->fd, FORMAT, host, (iterator->dnsmgr) ? "Y" : "N", user, iterator->refresh, regstate2str(iterator->regstate), tmpdat);
14756
		ASTOBJ_UNLOCK(iterator);
15935
		ASTOBJ_UNLOCK(iterator);
14757
		counter++;
15936
		counter++;
14758
	} while(0));
15937
	} while(0));
14759
	ast_cli(a->fd, "%d SIP registrations.\n", counter);
15938
	ast_cli(a->fd, "%d SIP registrations.\n", counter);
14760
	return CLI_SUCCESS;
15939
	return CLI_SUCCESS;
[+20] [20] 167 lines
[+20] [+] static char *sip_show_settings(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
14928
		ast_cli(a->fd, "%d\n", ntohs(sip_tls_desc.local_address.sin_port));
16107
		ast_cli(a->fd, "%d\n", ntohs(sip_tls_desc.local_address.sin_port));
14929
		ast_cli(a->fd, "  TLS Bindaddress:        %s\n", ast_inet_ntoa(sip_tls_desc.local_address.sin_addr));
16108
		ast_cli(a->fd, "  TLS Bindaddress:        %s\n", ast_inet_ntoa(sip_tls_desc.local_address.sin_addr));
14930
	} else {
16109
	} else {
14931
		ast_cli(a->fd, "Disabled\n");
16110
		ast_cli(a->fd, "Disabled\n");
14932
	}
16111
	}
14933
	ast_cli(a->fd, "  Videosupport:           %s\n", cli_yesno(ast_test_flag(&global_flags[1], SIP_PAGE2_VIDEOSUPPORT)));
16112
	ast_cli(a->fd, "  Videosupport:           %s\n", AST_CLI_YESNO(ast_test_flag(&global_flags[1], SIP_PAGE2_VIDEOSUPPORT)));
14934
	ast_cli(a->fd, "  Textsupport:            %s\n", cli_yesno(ast_test_flag(&global_flags[1], SIP_PAGE2_TEXTSUPPORT)));
16113
	ast_cli(a->fd, "  Textsupport:            %s\n", AST_CLI_YESNO(ast_test_flag(&global_flags[1], SIP_PAGE2_TEXTSUPPORT)));
14935
	ast_cli(a->fd, "  Ignore SDP sess. ver.:  %s\n", cli_yesno(ast_test_flag(&global_flags[1], SIP_PAGE2_IGNORESDPVERSION)));
16114
	ast_cli(a->fd, "  Ignore SDP sess. ver.:  %s\n", AST_CLI_YESNO(ast_test_flag(&global_flags[1], SIP_PAGE2_IGNORESDPVERSION)));
14936
	ast_cli(a->fd, "  AutoCreate Peer:        %s\n", cli_yesno(sip_cfg.autocreatepeer));
16115
	ast_cli(a->fd, "  AutoCreate Peer:        %s\n", AST_CLI_YESNO(sip_cfg.autocreatepeer));
14937
	ast_cli(a->fd, "  Match Auth Username:    %s\n", cli_yesno(global_match_auth_username));
16116
	ast_cli(a->fd, "  Match Auth Username:    %s\n", AST_CLI_YESNO(global_match_auth_username));
14938
	ast_cli(a->fd, "  Allow unknown access:   %s\n", cli_yesno(sip_cfg.allowguest));
16117
	ast_cli(a->fd, "  Allow unknown access:   %s\n", AST_CLI_YESNO(sip_cfg.allowguest));
14939
	ast_cli(a->fd, "  Allow subscriptions:    %s\n", cli_yesno(ast_test_flag(&global_flags[1], SIP_PAGE2_ALLOWSUBSCRIBE)));
16118
	ast_cli(a->fd, "  Allow subscriptions:    %s\n", AST_CLI_YESNO(ast_test_flag(&global_flags[1], SIP_PAGE2_ALLOWSUBSCRIBE)));
14940
	ast_cli(a->fd, "  Allow overlap dialing:  %s\n", cli_yesno(ast_test_flag(&global_flags[1], SIP_PAGE2_ALLOWOVERLAP)));
16119
	ast_cli(a->fd, "  Allow overlap dialing:  %s\n", AST_CLI_YESNO(ast_test_flag(&global_flags[1], SIP_PAGE2_ALLOWOVERLAP)));
14941
	ast_cli(a->fd, "  Allow promsic. redir:   %s\n", cli_yesno(ast_test_flag(&global_flags[0], SIP_PROMISCREDIR)));
16120
	ast_cli(a->fd, "  Allow promsic. redir:   %s\n", AST_CLI_YESNO(ast_test_flag(&global_flags[0], SIP_PROMISCREDIR)));
14942
	ast_cli(a->fd, "  Enable call counters:   %s\n", cli_yesno(global_callcounter));
16121
	ast_cli(a->fd, "  Enable call counters:   %s\n", AST_CLI_YESNO(global_callcounter));
14943
	ast_cli(a->fd, "  SIP domain support:     %s\n", cli_yesno(!AST_LIST_EMPTY(&domain_list)));
16122
	ast_cli(a->fd, "  SIP domain support:     %s\n", AST_CLI_YESNO(!AST_LIST_EMPTY(&domain_list)));
14944
	ast_cli(a->fd, "  Realm. auth:            %s\n", cli_yesno(authl != NULL));
16123
	ast_cli(a->fd, "  Realm. auth:            %s\n", AST_CLI_YESNO(authl != NULL));
14945
	ast_cli(a->fd, "  Our auth realm          %s\n", sip_cfg.realm);
16124
	ast_cli(a->fd, "  Our auth realm          %s\n", sip_cfg.realm);
14946
	ast_cli(a->fd, "  Use domains as realms:  %s\n", cli_yesno(sip_cfg.domainsasrealm));
16125
	ast_cli(a->fd, "  Use domains as realms:  %s\n", AST_CLI_YESNO(sip_cfg.domainsasrealm));
14947
	ast_cli(a->fd, "  Call to non-local dom.: %s\n", cli_yesno(sip_cfg.allow_external_domains));
16126
	ast_cli(a->fd, "  Call to non-local dom.: %s\n", AST_CLI_YESNO(sip_cfg.allow_external_domains));
14948
	ast_cli(a->fd, "  URI user is phone no:   %s\n", cli_yesno(ast_test_flag(&global_flags[0], SIP_USEREQPHONE)));
16127
	ast_cli(a->fd, "  URI user is phone no:   %s\n", AST_CLI_YESNO(ast_test_flag(&global_flags[0], SIP_USEREQPHONE)));
14949
 	ast_cli(a->fd, "  Always auth rejects:    %s\n", cli_yesno(sip_cfg.alwaysauthreject));
16128
	ast_cli(a->fd, "  Always auth rejects:    %s\n", AST_CLI_YESNO(sip_cfg.alwaysauthreject));
14950
	ast_cli(a->fd, "  Direct RTP setup:       %s\n", cli_yesno(sip_cfg.directrtpsetup));
16129
	ast_cli(a->fd, "  Direct RTP setup:       %s\n", AST_CLI_YESNO(sip_cfg.directrtpsetup));
14951
	ast_cli(a->fd, "  User Agent:             %s\n", global_useragent);
16130
	ast_cli(a->fd, "  User Agent:             %s\n", global_useragent);
14952
	ast_cli(a->fd, "  SDP Session Name:       %s\n", ast_strlen_zero(global_sdpsession) ? "-" : global_sdpsession);
16131
	ast_cli(a->fd, "  SDP Session Name:       %s\n", ast_strlen_zero(global_sdpsession) ? "-" : global_sdpsession);
14953
	ast_cli(a->fd, "  SDP Owner Name:         %s\n", ast_strlen_zero(global_sdpowner) ? "-" : global_sdpowner);
16132
	ast_cli(a->fd, "  SDP Owner Name:         %s\n", ast_strlen_zero(global_sdpowner) ? "-" : global_sdpowner);
14954
	ast_cli(a->fd, "  Reg. context:           %s\n", S_OR(sip_cfg.regcontext, "(not set)"));
16133
	ast_cli(a->fd, "  Reg. context:           %s\n", S_OR(sip_cfg.regcontext, "(not set)"));
14955
	ast_cli(a->fd, "  Regexten on Qualify:    %s\n", cli_yesno(sip_cfg.regextenonqualify));
16134
	ast_cli(a->fd, "  Regexten on Qualify:    %s\n", AST_CLI_YESNO(sip_cfg.regextenonqualify));
14956
	ast_cli(a->fd, "  Caller ID:              %s\n", default_callerid);
16135
	ast_cli(a->fd, "  Caller ID:              %s\n", default_callerid);

    
   
16136
	if ((default_fromdomainport) && (default_fromdomainport != STANDARD_SIP_PORT)) {

    
   
16137
		ast_cli(a->fd, "  From: Domain:           %s:%d\n", default_fromdomain, default_fromdomainport);

    
   
16138
	} else {
14957
	ast_cli(a->fd, "  From: Domain:           %s\n", default_fromdomain);
16139
		ast_cli(a->fd, "  From: Domain:           %s\n", default_fromdomain);
14958
	ast_cli(a->fd, "  Record SIP history:     %s\n", recordhistory ? "On" : "Off");
16140
	}
14959
	ast_cli(a->fd, "  Call Events:            %s\n", sip_cfg.callevents ? "On" : "Off");
16141
	ast_cli(a->fd, "  Record SIP history:     %s\n", AST_CLI_ONOFF(recordhistory));
14960
	ast_cli(a->fd, "  Auth. Failure Events:   %s\n", global_authfailureevents ? "On" : "Off");
16142
	ast_cli(a->fd, "  Call Events:            %s\n", AST_CLI_ONOFF(sip_cfg.callevents));

    
   
16143
	ast_cli(a->fd, "  Auth. Failure Events:   %s\n", AST_CLI_ONOFF(global_authfailureevents));
14961

    
   
16144

   
14962
	ast_cli(a->fd, "  T.38 support:           %s\n", cli_yesno(ast_test_flag(&global_flags[1], SIP_PAGE2_T38SUPPORT)));
16145
	ast_cli(a->fd, "  T.38 support:           %s\n", AST_CLI_YESNO(ast_test_flag(&global_flags[1], SIP_PAGE2_T38SUPPORT)));
14963
	ast_cli(a->fd, "  T.38 EC mode:           %s\n", faxec2str(ast_test_flag(&global_flags[1], SIP_PAGE2_T38SUPPORT)));
16146
	ast_cli(a->fd, "  T.38 EC mode:           %s\n", faxec2str(ast_test_flag(&global_flags[1], SIP_PAGE2_T38SUPPORT)));
14964
	ast_cli(a->fd, "  T.38 MaxDtgrm:          %d\n", global_t38_maxdatagram);
16147
	ast_cli(a->fd, "  T.38 MaxDtgrm:          %d\n", global_t38_maxdatagram);
14965
	if (!realtimepeers && !realtimeregs)
16148
	if (!realtimepeers && !realtimeregs)
14966
		ast_cli(a->fd, "  SIP realtime:           Disabled\n" );
16149
		ast_cli(a->fd, "  SIP realtime:           Disabled\n" );
14967
	else
16150
	else
14968
		ast_cli(a->fd, "  SIP realtime:           Enabled\n" );
16151
		ast_cli(a->fd, "  SIP realtime:           Enabled\n" );
14969
	ast_cli(a->fd, "  Qualify Freq :          %d ms\n", global_qualifyfreq);
16152
	ast_cli(a->fd, "  Qualify Freq :          %d ms\n", global_qualifyfreq);
14970
	ast_cli(a->fd, "  Q.850 Reason header:    %s\n", cli_yesno(ast_test_flag(&global_flags[1], SIP_PAGE2_Q850_REASON)));
16153
	ast_cli(a->fd, "  Q.850 Reason header:    %s\n", AST_CLI_YESNO(ast_test_flag(&global_flags[1], SIP_PAGE2_Q850_REASON)));
14971
	ast_cli(a->fd, "\nNetwork QoS Settings:\n");
16154
	ast_cli(a->fd, "\nNetwork QoS Settings:\n");
14972
	ast_cli(a->fd, "---------------------------\n");
16155
	ast_cli(a->fd, "---------------------------\n");
14973
	ast_cli(a->fd, "  IP ToS SIP:             %s\n", ast_tos2str(global_tos_sip));
16156
	ast_cli(a->fd, "  IP ToS SIP:             %s\n", ast_tos2str(global_tos_sip));
14974
	ast_cli(a->fd, "  IP ToS RTP audio:       %s\n", ast_tos2str(global_tos_audio));
16157
	ast_cli(a->fd, "  IP ToS RTP audio:       %s\n", ast_tos2str(global_tos_audio));
14975
	ast_cli(a->fd, "  IP ToS RTP video:       %s\n", ast_tos2str(global_tos_video));
16158
	ast_cli(a->fd, "  IP ToS RTP video:       %s\n", ast_tos2str(global_tos_video));
14976
	ast_cli(a->fd, "  IP ToS RTP text:        %s\n", ast_tos2str(global_tos_text));
16159
	ast_cli(a->fd, "  IP ToS RTP text:        %s\n", ast_tos2str(global_tos_text));
14977
	ast_cli(a->fd, "  802.1p CoS SIP:         %d\n", global_cos_sip);
16160
	ast_cli(a->fd, "  802.1p CoS SIP:         %d\n", global_cos_sip);
14978
	ast_cli(a->fd, "  802.1p CoS RTP audio:   %d\n", global_cos_audio);
16161
	ast_cli(a->fd, "  802.1p CoS RTP audio:   %d\n", global_cos_audio);
14979
	ast_cli(a->fd, "  802.1p CoS RTP video:   %d\n", global_cos_video);
16162
	ast_cli(a->fd, "  802.1p CoS RTP video:   %d\n", global_cos_video);
14980
	ast_cli(a->fd, "  802.1p CoS RTP text:    %d\n", global_cos_text);
16163
	ast_cli(a->fd, "  802.1p CoS RTP text:    %d\n", global_cos_text);
14981
	ast_cli(a->fd, "  Jitterbuffer enabled:   %s\n", cli_yesno(ast_test_flag(&global_jbconf, AST_JB_ENABLED)));
16164
	ast_cli(a->fd, "  Jitterbuffer enabled:   %s\n", AST_CLI_YESNO(ast_test_flag(&global_jbconf, AST_JB_ENABLED)));
14982
	ast_cli(a->fd, "  Jitterbuffer forced:    %s\n", cli_yesno(ast_test_flag(&global_jbconf, AST_JB_FORCED)));
16165
	ast_cli(a->fd, "  Jitterbuffer forced:    %s\n", AST_CLI_YESNO(ast_test_flag(&global_jbconf, AST_JB_FORCED)));
14983
	ast_cli(a->fd, "  Jitterbuffer max size:  %ld\n", global_jbconf.max_size);
16166
	ast_cli(a->fd, "  Jitterbuffer max size:  %ld\n", global_jbconf.max_size);
14984
	ast_cli(a->fd, "  Jitterbuffer resync:    %ld\n", global_jbconf.resync_threshold);
16167
	ast_cli(a->fd, "  Jitterbuffer resync:    %ld\n", global_jbconf.resync_threshold);
14985
	ast_cli(a->fd, "  Jitterbuffer impl:      %s\n", global_jbconf.impl);
16168
	ast_cli(a->fd, "  Jitterbuffer impl:      %s\n", global_jbconf.impl);
14986
	ast_cli(a->fd, "  Jitterbuffer log:       %s\n", cli_yesno(ast_test_flag(&global_jbconf, AST_JB_LOG)));
16169
	ast_cli(a->fd, "  Jitterbuffer log:       %s\n", AST_CLI_YESNO(ast_test_flag(&global_jbconf, AST_JB_LOG)));
14987

    
   
16170

   
14988
	ast_cli(a->fd, "\nNetwork Settings:\n");
16171
	ast_cli(a->fd, "\nNetwork Settings:\n");
14989
	ast_cli(a->fd, "---------------------------\n");
16172
	ast_cli(a->fd, "---------------------------\n");
14990
	/* determine if/how SIP address can be remapped */
16173
	/* determine if/how SIP address can be remapped */
14991
	if (localaddr == NULL)
16174
	if (localaddr == NULL)
[+20] [20] 30 lines
[+20] static char *sip_show_settings(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
15022
	ast_getformatname_multiple(codec_buf, sizeof(codec_buf) -1, sip_cfg.capability);
16205
	ast_getformatname_multiple(codec_buf, sizeof(codec_buf) -1, sip_cfg.capability);
15023
	ast_cli(a->fd, "%s\n", codec_buf);
16206
	ast_cli(a->fd, "%s\n", codec_buf);
15024
	ast_cli(a->fd, "  Codec Order:            ");
16207
	ast_cli(a->fd, "  Codec Order:            ");
15025
	print_codec_to_cli(a->fd, &default_prefs);
16208
	print_codec_to_cli(a->fd, &default_prefs);
15026
	ast_cli(a->fd, "\n");
16209
	ast_cli(a->fd, "\n");
15027
	ast_cli(a->fd, "  Relax DTMF:             %s\n", cli_yesno(global_relaxdtmf));
16210
	ast_cli(a->fd, "  Relax DTMF:             %s\n", AST_CLI_YESNO(global_relaxdtmf));
15028
	ast_cli(a->fd, "  RFC2833 Compensation:   %s\n", cli_yesno(ast_test_flag(&global_flags[1], SIP_PAGE2_RFC2833_COMPENSATE)));
16211
	ast_cli(a->fd, "  RFC2833 Compensation:   %s\n", AST_CLI_YESNO(ast_test_flag(&global_flags[1], SIP_PAGE2_RFC2833_COMPENSATE)));
15029
	ast_cli(a->fd, "  Symmetric RTP:          %s\n", cli_yesno(ast_test_flag(&global_flags[1], SIP_PAGE2_SYMMETRICRTP)));
16212
	ast_cli(a->fd, "  Symmetric RTP:          %s\n", AST_CLI_YESNO(ast_test_flag(&global_flags[1], SIP_PAGE2_SYMMETRICRTP)));
15030
	ast_cli(a->fd, "  Compact SIP headers:    %s\n", cli_yesno(sip_cfg.compactheaders));
16213
	ast_cli(a->fd, "  Compact SIP headers:    %s\n", AST_CLI_YESNO(sip_cfg.compactheaders));
15031
	ast_cli(a->fd, "  RTP Keepalive:          %d %s\n", global_rtpkeepalive, global_rtpkeepalive ? "" : "(Disabled)" );
16214
	ast_cli(a->fd, "  RTP Keepalive:          %d %s\n", global_rtpkeepalive, global_rtpkeepalive ? "" : "(Disabled)" );
15032
	ast_cli(a->fd, "  RTP Timeout:            %d %s\n", global_rtptimeout, global_rtptimeout ? "" : "(Disabled)" );
16215
	ast_cli(a->fd, "  RTP Timeout:            %d %s\n", global_rtptimeout, global_rtptimeout ? "" : "(Disabled)" );
15033
	ast_cli(a->fd, "  RTP Hold Timeout:       %d %s\n", global_rtpholdtimeout, global_rtpholdtimeout ? "" : "(Disabled)");
16216
	ast_cli(a->fd, "  RTP Hold Timeout:       %d %s\n", global_rtpholdtimeout, global_rtpholdtimeout ? "" : "(Disabled)");
15034
	ast_cli(a->fd, "  MWI NOTIFY mime type:   %s\n", default_notifymime);
16217
	ast_cli(a->fd, "  MWI NOTIFY mime type:   %s\n", default_notifymime);
15035
	ast_cli(a->fd, "  DNS SRV lookup:         %s\n", cli_yesno(sip_cfg.srvlookup));
16218
	ast_cli(a->fd, "  DNS SRV lookup:         %s\n", AST_CLI_YESNO(sip_cfg.srvlookup));
15036
	ast_cli(a->fd, "  Pedantic SIP support:   %s\n", cli_yesno(sip_cfg.pedanticsipchecking));
16219
	ast_cli(a->fd, "  Pedantic SIP support:   %s\n", AST_CLI_YESNO(sip_cfg.pedanticsipchecking));
15037
	ast_cli(a->fd, "  Reg. min duration       %d secs\n", min_expiry);
16220
	ast_cli(a->fd, "  Reg. min duration       %d secs\n", min_expiry);
15038
	ast_cli(a->fd, "  Reg. max duration:      %d secs\n", max_expiry);
16221
	ast_cli(a->fd, "  Reg. max duration:      %d secs\n", max_expiry);
15039
	ast_cli(a->fd, "  Reg. default duration:  %d secs\n", default_expiry);
16222
	ast_cli(a->fd, "  Reg. default duration:  %d secs\n", default_expiry);
15040
	ast_cli(a->fd, "  Outbound reg. timeout:  %d secs\n", global_reg_timeout);
16223
	ast_cli(a->fd, "  Outbound reg. timeout:  %d secs\n", global_reg_timeout);
15041
	ast_cli(a->fd, "  Outbound reg. attempts: %d\n", global_regattempts_max);
16224
	ast_cli(a->fd, "  Outbound reg. attempts: %d\n", global_regattempts_max);
15042
	ast_cli(a->fd, "  Notify ringing state:   %s\n", cli_yesno(sip_cfg.notifyringing));
16225
	ast_cli(a->fd, "  Notify ringing state:   %s\n", AST_CLI_YESNO(sip_cfg.notifyringing));
15043
	if (sip_cfg.notifyringing) {
16226
	if (sip_cfg.notifyringing) {
15044
		ast_cli(a->fd, "    Include CID:          %s%s\n",
16227
		ast_cli(a->fd, "    Include CID:          %s%s\n",
15045
				cli_yesno(sip_cfg.notifycid),
16228
				AST_CLI_YESNO(sip_cfg.notifycid),
15046
				sip_cfg.notifycid == IGNORE_CONTEXT ? " (Ignoring context)" : "");
16229
				sip_cfg.notifycid == IGNORE_CONTEXT ? " (Ignoring context)" : "");
15047
	}
16230
	}
15048
	ast_cli(a->fd, "  Notify hold state:      %s\n", cli_yesno(sip_cfg.notifyhold));
16231
	ast_cli(a->fd, "  Notify hold state:      %s\n", AST_CLI_YESNO(sip_cfg.notifyhold));
15049
	ast_cli(a->fd, "  SIP Transfer mode:      %s\n", transfermode2str(sip_cfg.allowtransfer));
16232
	ast_cli(a->fd, "  SIP Transfer mode:      %s\n", transfermode2str(sip_cfg.allowtransfer));
15050
	ast_cli(a->fd, "  Max Call Bitrate:       %d kbps\n", default_maxcallbitrate);
16233
	ast_cli(a->fd, "  Max Call Bitrate:       %d kbps\n", default_maxcallbitrate);
15051
	ast_cli(a->fd, "  Auto-Framing:           %s\n", cli_yesno(global_autoframing));
16234
	ast_cli(a->fd, "  Auto-Framing:           %s\n", AST_CLI_YESNO(global_autoframing));
15052
	ast_cli(a->fd, "  Outb. proxy:            %s %s\n", ast_strlen_zero(sip_cfg.outboundproxy.name) ? "<not set>" : sip_cfg.outboundproxy.name,
16235
	ast_cli(a->fd, "  Outb. proxy:            %s %s\n", ast_strlen_zero(sip_cfg.outboundproxy.name) ? "<not set>" : sip_cfg.outboundproxy.name,
15053
							sip_cfg.outboundproxy.force ? "(forced)" : "");
16236
							sip_cfg.outboundproxy.force ? "(forced)" : "");
15054
	ast_cli(a->fd, "  Session Timers:         %s\n", stmode2str(global_st_mode));
16237
	ast_cli(a->fd, "  Session Timers:         %s\n", stmode2str(global_st_mode));
15055
	ast_cli(a->fd, "  Session Refresher:      %s\n", strefresher2str (global_st_refresher));
16238
	ast_cli(a->fd, "  Session Refresher:      %s\n", strefresher2str (global_st_refresher));
15056
	ast_cli(a->fd, "  Session Expires:        %d secs\n", global_max_se);
16239
	ast_cli(a->fd, "  Session Expires:        %d secs\n", global_max_se);
15057
	ast_cli(a->fd, "  Session Min-SE:         %d secs\n", global_min_se);
16240
	ast_cli(a->fd, "  Session Min-SE:         %d secs\n", global_min_se);
15058
 	ast_cli(a->fd, "  Timer T1:               %d\n", global_t1);
16241
 	ast_cli(a->fd, "  Timer T1:               %d\n", global_t1);
15059
	ast_cli(a->fd, "  Timer T1 minimum:       %d\n", global_t1min);
16242
	ast_cli(a->fd, "  Timer T1 minimum:       %d\n", global_t1min);
15060
 	ast_cli(a->fd, "  Timer B:                %d\n", global_timer_b);
16243
 	ast_cli(a->fd, "  Timer B:                %d\n", global_timer_b);
15061
	ast_cli(a->fd, "  No premature media:     %s\n", global_prematuremediafilter ? "Yes" : "No");
16244
	ast_cli(a->fd, "  No premature media:     %s\n", AST_CLI_YESNO(global_prematuremediafilter));
15062

    
   
16245

   
15063
	ast_cli(a->fd, "\nDefault Settings:\n");
16246
	ast_cli(a->fd, "\nDefault Settings:\n");
15064
	ast_cli(a->fd, "-----------------\n");
16247
	ast_cli(a->fd, "-----------------\n");
15065
	ast_cli(a->fd, "  Allowed transports:     %s\n", get_transport_list(default_transports));
16248
	ast_cli(a->fd, "  Allowed transports:     %s\n", get_transport_list(default_transports));
15066
	ast_cli(a->fd, "  Outbound transport:	  %s\n", get_transport(default_primary_transport));
16249
	ast_cli(a->fd, "  Outbound transport:	  %s\n", get_transport(default_primary_transport));
15067
	ast_cli(a->fd, "  Context:                %s\n", sip_cfg.default_context);
16250
	ast_cli(a->fd, "  Context:                %s\n", sip_cfg.default_context);
15068
	ast_cli(a->fd, "  Force rport:            %s\n", cli_yesno(ast_test_flag(&global_flags[0], SIP_NAT_FORCE_RPORT)));
16251
	ast_cli(a->fd, "  Force rport:            %s\n", AST_CLI_YESNO(ast_test_flag(&global_flags[0], SIP_NAT_FORCE_RPORT)));
15069
	ast_cli(a->fd, "  DTMF:                   %s\n", dtmfmode2str(ast_test_flag(&global_flags[0], SIP_DTMF)));
16252
	ast_cli(a->fd, "  DTMF:                   %s\n", dtmfmode2str(ast_test_flag(&global_flags[0], SIP_DTMF)));
15070
	ast_cli(a->fd, "  Qualify:                %d\n", default_qualify);
16253
	ast_cli(a->fd, "  Qualify:                %d\n", default_qualify);
15071
	ast_cli(a->fd, "  Use ClientCode:         %s\n", cli_yesno(ast_test_flag(&global_flags[0], SIP_USECLIENTCODE)));
16254
	ast_cli(a->fd, "  Use ClientCode:         %s\n", AST_CLI_YESNO(ast_test_flag(&global_flags[0], SIP_USECLIENTCODE)));
15072
	ast_cli(a->fd, "  Progress inband:        %s\n", (ast_test_flag(&global_flags[0], SIP_PROG_INBAND) == SIP_PROG_INBAND_NEVER) ? "Never" : (ast_test_flag(&global_flags[0], SIP_PROG_INBAND) == SIP_PROG_INBAND_NO) ? "No" : "Yes" );
16255
	ast_cli(a->fd, "  Progress inband:        %s\n", (ast_test_flag(&global_flags[0], SIP_PROG_INBAND) == SIP_PROG_INBAND_NEVER) ? "Never" : (AST_CLI_YESNO(ast_test_flag(&global_flags[0], SIP_PROG_INBAND) != SIP_PROG_INBAND_NO)));
15073
	ast_cli(a->fd, "  Language:               %s\n", default_language);
16256
	ast_cli(a->fd, "  Language:               %s\n", default_language);
15074
	ast_cli(a->fd, "  MOH Interpret:          %s\n", default_mohinterpret);
16257
	ast_cli(a->fd, "  MOH Interpret:          %s\n", default_mohinterpret);
15075
	ast_cli(a->fd, "  MOH Suggest:            %s\n", default_mohsuggest);
16258
	ast_cli(a->fd, "  MOH Suggest:            %s\n", default_mohsuggest);
15076
	ast_cli(a->fd, "  Voice Mail Extension:   %s\n", default_vmexten);
16259
	ast_cli(a->fd, "  Voice Mail Extension:   %s\n", default_vmexten);
15077

    
   
16260

   
15078
	
16261
	
15079
	if (realtimepeers || realtimeregs) {
16262
	if (realtimepeers || realtimeregs) {
15080
		ast_cli(a->fd, "\nRealtime SIP Settings:\n");
16263
		ast_cli(a->fd, "\nRealtime SIP Settings:\n");
15081
		ast_cli(a->fd, "----------------------\n");
16264
		ast_cli(a->fd, "----------------------\n");
15082
		ast_cli(a->fd, "  Realtime Peers:         %s\n", cli_yesno(realtimepeers));
16265
		ast_cli(a->fd, "  Realtime Peers:         %s\n", AST_CLI_YESNO(realtimepeers));
15083
		ast_cli(a->fd, "  Realtime Regs:          %s\n", cli_yesno(realtimeregs));
16266
		ast_cli(a->fd, "  Realtime Regs:          %s\n", AST_CLI_YESNO(realtimeregs));
15084
		ast_cli(a->fd, "  Cache Friends:          %s\n", cli_yesno(ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS)));
16267
		ast_cli(a->fd, "  Cache Friends:          %s\n", AST_CLI_YESNO(ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS)));
15085
		ast_cli(a->fd, "  Update:                 %s\n", cli_yesno(sip_cfg.peer_rtupdate));
16268
		ast_cli(a->fd, "  Update:                 %s\n", AST_CLI_YESNO(sip_cfg.peer_rtupdate));
15086
		ast_cli(a->fd, "  Ignore Reg. Expire:     %s\n", cli_yesno(sip_cfg.ignore_regexpire));
16269
		ast_cli(a->fd, "  Ignore Reg. Expire:     %s\n", AST_CLI_YESNO(sip_cfg.ignore_regexpire));
15087
		ast_cli(a->fd, "  Save sys. name:         %s\n", cli_yesno(sip_cfg.rtsave_sysname));
16270
		ast_cli(a->fd, "  Save sys. name:         %s\n", AST_CLI_YESNO(sip_cfg.rtsave_sysname));
15088
		ast_cli(a->fd, "  Auto Clear:             %d\n", sip_cfg.rtautoclear);
16271
		ast_cli(a->fd, "  Auto Clear:             %d\n", sip_cfg.rtautoclear);
15089
	}
16272
	}
15090
	ast_cli(a->fd, "\n----\n");
16273
	ast_cli(a->fd, "\n----\n");
15091
	return CLI_SUCCESS;
16274
	return CLI_SUCCESS;
15092
}
16275
}
[+20] [20] 17 lines
[+20] [+] static char *sip_show_mwi(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
15110
	ast_cli(a->fd, FORMAT, "Host", "Username", "Mailbox", "Subscribed");
16293
	ast_cli(a->fd, FORMAT, "Host", "Username", "Mailbox", "Subscribed");
15111
	
16294
	
15112
	ASTOBJ_CONTAINER_TRAVERSE(&submwil, 1, do {
16295
	ASTOBJ_CONTAINER_TRAVERSE(&submwil, 1, do {
15113
		ASTOBJ_RDLOCK(iterator);
16296
		ASTOBJ_RDLOCK(iterator);
15114
		snprintf(host, sizeof(host), "%s:%d", iterator->hostname, iterator->portno ? iterator->portno : STANDARD_SIP_PORT);
16297
		snprintf(host, sizeof(host), "%s:%d", iterator->hostname, iterator->portno ? iterator->portno : STANDARD_SIP_PORT);
15115
		ast_cli(a->fd, FORMAT, host, iterator->username, iterator->mailbox, iterator->subscribed ? "Yes" : "No");
16298
		ast_cli(a->fd, FORMAT, host, iterator->username, iterator->mailbox, AST_CLI_YESNO(iterator->subscribed));
15116
		ASTOBJ_UNLOCK(iterator);
16299
		ASTOBJ_UNLOCK(iterator);
15117
	} while(0));
16300
	} while(0));
15118

    
   
16301

   
15119
	return CLI_SUCCESS;
16302
	return CLI_SUCCESS;
15120
#undef FORMAT
16303
#undef FORMAT
[+20] [20] 53 lines
[+20] [+] static int show_channels_cb(void *__cur, void *__arg, int flags)
15174
		
16357
		
15175
		ast_cli(arg->fd, FORMAT, ast_inet_ntoa(dst->sin_addr),
16358
		ast_cli(arg->fd, FORMAT, ast_inet_ntoa(dst->sin_addr),
15176
				S_OR(cur->username, S_OR(cur->cid_num, "(None)")),
16359
				S_OR(cur->username, S_OR(cur->cid_num, "(None)")),
15177
				cur->callid,
16360
				cur->callid,
15178
				ast_getformatname_multiple(formatbuf, sizeof(formatbuf), cur->owner ? cur->owner->nativeformats : 0),
16361
				ast_getformatname_multiple(formatbuf, sizeof(formatbuf), cur->owner ? cur->owner->nativeformats : 0),
15179
				cli_yesno(ast_test_flag(&cur->flags[1], SIP_PAGE2_CALL_ONHOLD)),
16362
				AST_CLI_YESNO(ast_test_flag(&cur->flags[1], SIP_PAGE2_CALL_ONHOLD)),
15180
				cur->needdestroy ? "(d)" : "",
16363
				cur->needdestroy ? "(d)" : "",
15181
				cur->lastmsg ,
16364
				cur->lastmsg ,
15182
				referstatus
16365
				referstatus
15183
			);
16366
			);
15184
		arg->numchans++;
16367
		arg->numchans++;
[+20] [20] 240 lines
[+20] [+] static char *sip_show_channel(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
15425
			ast_cli(a->fd, "  Our Codec Capability:   %s\n", ast_getformatname_multiple(formatbuf, sizeof(formatbuf), cur->capability));
16608
			ast_cli(a->fd, "  Our Codec Capability:   %s\n", ast_getformatname_multiple(formatbuf, sizeof(formatbuf), cur->capability));
15426
			ast_cli(a->fd, "  Non-Codec Capability (DTMF):   %d\n", cur->noncodeccapability);
16609
			ast_cli(a->fd, "  Non-Codec Capability (DTMF):   %d\n", cur->noncodeccapability);
15427
			ast_cli(a->fd, "  Their Codec Capability:   %s\n", ast_getformatname_multiple(formatbuf, sizeof(formatbuf), cur->peercapability));
16610
			ast_cli(a->fd, "  Their Codec Capability:   %s\n", ast_getformatname_multiple(formatbuf, sizeof(formatbuf), cur->peercapability));
15428
			ast_cli(a->fd, "  Joint Codec Capability:   %s\n", ast_getformatname_multiple(formatbuf, sizeof(formatbuf), cur->jointcapability));
16611
			ast_cli(a->fd, "  Joint Codec Capability:   %s\n", ast_getformatname_multiple(formatbuf, sizeof(formatbuf), cur->jointcapability));
15429
			ast_cli(a->fd, "  Format:                 %s\n", ast_getformatname_multiple(formatbuf, sizeof(formatbuf), cur->owner ? cur->owner->nativeformats : 0) );
16612
			ast_cli(a->fd, "  Format:                 %s\n", ast_getformatname_multiple(formatbuf, sizeof(formatbuf), cur->owner ? cur->owner->nativeformats : 0) );
15430
			ast_cli(a->fd, "  T.38 support            %s\n", cli_yesno(cur->udptl != NULL));
16613
			ast_cli(a->fd, "  T.38 support            %s\n", AST_CLI_YESNO(cur->udptl != NULL));
15431
			ast_cli(a->fd, "  Video support           %s\n", cli_yesno(cur->vrtp != NULL));
16614
			ast_cli(a->fd, "  Video support           %s\n", AST_CLI_YESNO(cur->vrtp != NULL));
15432
			ast_cli(a->fd, "  MaxCallBR:              %d kbps\n", cur->maxcallbitrate);
16615
			ast_cli(a->fd, "  MaxCallBR:              %d kbps\n", cur->maxcallbitrate);
15433
			ast_cli(a->fd, "  Theoretical Address:    %s:%d\n", ast_inet_ntoa(cur->sa.sin_addr), ntohs(cur->sa.sin_port));
16616
			ast_cli(a->fd, "  Theoretical Address:    %s:%d\n", ast_inet_ntoa(cur->sa.sin_addr), ntohs(cur->sa.sin_port));
15434
			ast_cli(a->fd, "  Received Address:       %s:%d\n", ast_inet_ntoa(cur->recv.sin_addr), ntohs(cur->recv.sin_port));
16617
			ast_cli(a->fd, "  Received Address:       %s:%d\n", ast_inet_ntoa(cur->recv.sin_addr), ntohs(cur->recv.sin_port));
15435
			ast_cli(a->fd, "  SIP Transfer mode:      %s\n", transfermode2str(cur->allowtransfer));
16618
			ast_cli(a->fd, "  SIP Transfer mode:      %s\n", transfermode2str(cur->allowtransfer));
15436
			ast_cli(a->fd, "  Force rport:            %s\n", cli_yesno(ast_test_flag(&cur->flags[0], SIP_NAT_FORCE_RPORT)));
16619
			ast_cli(a->fd, "  Force rport:            %s\n", AST_CLI_YESNO(ast_test_flag(&cur->flags[0], SIP_NAT_FORCE_RPORT)));
15437
			ast_cli(a->fd, "  Audio IP:               %s %s\n", ast_inet_ntoa(cur->redirip.sin_addr.s_addr ? cur->redirip.sin_addr : cur->ourip.sin_addr), cur->redirip.sin_addr.s_addr ? "(Outside bridge)" : "(local)" );
16620
			ast_cli(a->fd, "  Audio IP:               %s %s\n", ast_inet_ntoa(cur->redirip.sin_addr.s_addr ? cur->redirip.sin_addr : cur->ourip.sin_addr), cur->redirip.sin_addr.s_addr ? "(Outside bridge)" : "(local)" );
15438
			ast_cli(a->fd, "  Our Tag:                %s\n", cur->tag);
16621
			ast_cli(a->fd, "  Our Tag:                %s\n", cur->tag);
15439
			ast_cli(a->fd, "  Their Tag:              %s\n", cur->theirtag);
16622
			ast_cli(a->fd, "  Their Tag:              %s\n", cur->theirtag);
15440
			ast_cli(a->fd, "  SIP User agent:         %s\n", cur->useragent);
16623
			ast_cli(a->fd, "  SIP User agent:         %s\n", cur->useragent);
15441
			if (!ast_strlen_zero(cur->username))
16624
			if (!ast_strlen_zero(cur->username))
15442
				ast_cli(a->fd, "  Username:               %s\n", cur->username);
16625
				ast_cli(a->fd, "  Username:               %s\n", cur->username);
15443
			if (!ast_strlen_zero(cur->peername))
16626
			if (!ast_strlen_zero(cur->peername))
15444
				ast_cli(a->fd, "  Peername:               %s\n", cur->peername);
16627
				ast_cli(a->fd, "  Peername:               %s\n", cur->peername);
15445
			if (!ast_strlen_zero(cur->uri))
16628
			if (!ast_strlen_zero(cur->uri))
15446
				ast_cli(a->fd, "  Original uri:           %s\n", cur->uri);
16629
				ast_cli(a->fd, "  Original uri:           %s\n", cur->uri);
15447
			if (!ast_strlen_zero(cur->cid_num))
16630
			if (!ast_strlen_zero(cur->cid_num))
15448
				ast_cli(a->fd, "  Caller-ID:              %s\n", cur->cid_num);
16631
				ast_cli(a->fd, "  Caller-ID:              %s\n", cur->cid_num);
15449
			ast_cli(a->fd, "  Need Destroy:           %s\n", cli_yesno(cur->needdestroy));
16632
			ast_cli(a->fd, "  Need Destroy:           %s\n", AST_CLI_YESNO(cur->needdestroy));
15450
			ast_cli(a->fd, "  Last Message:           %s\n", cur->lastmsg);
16633
			ast_cli(a->fd, "  Last Message:           %s\n", cur->lastmsg);
15451
			ast_cli(a->fd, "  Promiscuous Redir:      %s\n", cli_yesno(ast_test_flag(&cur->flags[0], SIP_PROMISCREDIR)));
16634
			ast_cli(a->fd, "  Promiscuous Redir:      %s\n", AST_CLI_YESNO(ast_test_flag(&cur->flags[0], SIP_PROMISCREDIR)));
15452
			ast_cli(a->fd, "  Route:                  %s\n", cur->route ? cur->route->hop : "N/A");
16635
			ast_cli(a->fd, "  Route:                  %s\n", cur->route ? cur->route->hop : "N/A");
15453
			ast_cli(a->fd, "  DTMF Mode:              %s\n", dtmfmode2str(ast_test_flag(&cur->flags[0], SIP_DTMF)));
16636
			ast_cli(a->fd, "  DTMF Mode:              %s\n", dtmfmode2str(ast_test_flag(&cur->flags[0], SIP_DTMF)));
15454
			ast_cli(a->fd, "  SIP Options:            ");
16637
			ast_cli(a->fd, "  SIP Options:            ");
15455
			if (cur->sipoptions) {
16638
			if (cur->sipoptions) {
15456
				int x;
16639
				int x;
[+20] [20] 445 lines
[+20] [+] static char *sip_cli_notify(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
15902
		if (!(p = sip_alloc(NULL, NULL, 0, SIP_NOTIFY, NULL))) {
17085
		if (!(p = sip_alloc(NULL, NULL, 0, SIP_NOTIFY, NULL))) {
15903
			ast_log(LOG_WARNING, "Unable to build sip pvt data for notify (memory/socket error)\n");
17086
			ast_log(LOG_WARNING, "Unable to build sip pvt data for notify (memory/socket error)\n");
15904
			return CLI_FAILURE;
17087
			return CLI_FAILURE;
15905
		}
17088
		}
15906

    
   
17089

   
15907
		if (create_addr(p, a->argv[i], NULL, 1)) {
17090
		if (create_addr(p, a->argv[i], NULL, 1, NULL)) {
15908
			/* Maybe they're not registered, etc. */
17091
			/* Maybe they're not registered, etc. */
15909
			dialog_unlink_all(p, TRUE, TRUE);
17092
			dialog_unlink_all(p, TRUE, TRUE);
15910
			dialog_unref(p, "unref dialog inside for loop" );
17093
			dialog_unref(p, "unref dialog inside for loop" );
15911
			/* sip_destroy(p); */
17094
			/* sip_destroy(p); */
15912
			ast_cli(a->fd, "Could not create address for '%s'\n", a->argv[i]);
17095
			ast_cli(a->fd, "Could not create address for '%s'\n", a->argv[i]);
[+20] [20] 21 lines
[+20] static char *sip_cli_notify(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
15934

    
   
17117

   
15935
		/* Recalculate our side, and recalculate Call ID */
17118
		/* Recalculate our side, and recalculate Call ID */
15936
		ast_cli(a->fd, "Sending NOTIFY of type '%s' to '%s'\n", a->argv[2], a->argv[i]);
17119
		ast_cli(a->fd, "Sending NOTIFY of type '%s' to '%s'\n", a->argv[2], a->argv[i]);
15937
		dialog_ref(p, "bump the count of p, which transmit_sip_request will decrement.");
17120
		dialog_ref(p, "bump the count of p, which transmit_sip_request will decrement.");
15938
		sip_scheddestroy(p, SIP_TRANS_TIMEOUT);
17121
		sip_scheddestroy(p, SIP_TRANS_TIMEOUT);
15939
		transmit_invite(p, SIP_NOTIFY, 0, 2);
17122
		transmit_invite(p, SIP_NOTIFY, 0, 2, NULL);
15940
	}
17123
	}
15941

    
   
17124

   
15942
	return CLI_SUCCESS;
17125
	return CLI_SUCCESS;
15943
}
17126
}
15944

    
   
17127

   
[+20] [20] 69 lines
[+20] [+] static int do_proxy_auth(struct sip_pvt *p, struct sip_request *req, enum sip_auth_type code, int sipmethod, int init)
16014
		return -1;
17197
		return -1;
16015
	}
17198
	}
16016
	/* Now we have a reply digest */
17199
	/* Now we have a reply digest */
16017
	p->options->auth = digest;
17200
	p->options->auth = digest;
16018
	p->options->authheader = respheader;
17201
	p->options->authheader = respheader;
16019
	return transmit_invite(p, sipmethod, sipmethod == SIP_INVITE, init);
17202
	return transmit_invite(p, sipmethod, sipmethod == SIP_INVITE, init, NULL);
16020
}
17203
}
16021

    
   
17204

   
16022
/*! \brief  reply to authentication for outbound registrations
17205
/*! \brief  reply to authentication for outbound registrations
16023
\return	Returns -1 if we have no auth
17206
\return	Returns -1 if we have no auth
16024
\note	This is used for register= servers in sip.conf, SIP proxies we register
17207
\note	This is used for register= servers in sip.conf, SIP proxies we register
[+20] [20] 56 lines
[+20] [+] static int reply_digest(struct sip_pvt *p, struct sip_request *req, char *header, int sipmethod, char *digest, int digest_len)
16081
		struct sip_registry *r = p->registry;
17264
		struct sip_registry *r = p->registry;
16082

    
   
17265

   
16083
		if (strcmp(r->nonce, p->nonce)) {
17266
		if (strcmp(r->nonce, p->nonce)) {
16084
			ast_string_field_set(r, realm, p->realm);
17267
			ast_string_field_set(r, realm, p->realm);
16085
			ast_string_field_set(r, nonce, p->nonce);
17268
			ast_string_field_set(r, nonce, p->nonce);
16086
			ast_string_field_set(r, domain, p->domain);
17269
			ast_string_field_set(r, authdomain, p->domain);
16087
			ast_string_field_set(r, opaque, p->opaque);
17270
			ast_string_field_set(r, opaque, p->opaque);
16088
			ast_string_field_set(r, qop, p->qop);
17271
			ast_string_field_set(r, qop, p->qop);
16089
			r->noncecount = 0;
17272
			r->noncecount = 0;
16090
		}
17273
		}
16091
	}
17274
	}
[+20] [20] 365 lines
[+20] [+] static void change_redirecting_information(struct sip_pvt *p, struct sip_request *req, struct ast_party_redirecting *redirecting, int set_call_forward)
16457
			ast_free(redirecting->from.name);
17640
			ast_free(redirecting->from.name);
16458
		}
17641
		}
16459
		ast_debug(3, "Got redirecting from name %s\n", redirecting_from_name);
17642
		ast_debug(3, "Got redirecting from name %s\n", redirecting_from_name);
16460
		redirecting->from.name = redirecting_from_name;
17643
		redirecting->from.name = redirecting_from_name;
16461
	}
17644
	}

    
   
17645
	if (!ast_strlen_zero(p->cid_tag)) {

    
   
17646
		if (redirecting->from.tag) {

    
   
17647
			ast_free(redirecting->from.tag);

    
   
17648
		}

    
   
17649
		redirecting->from.tag = ast_strdup(p->cid_tag);

    
   
17650
		if (redirecting->to.tag) {

    
   
17651
			ast_free(redirecting->to.tag);

    
   
17652
		}

    
   
17653
		redirecting->to.tag = ast_strdup(p->cid_tag);

    
   
17654
	}
16462
	if (!ast_strlen_zero(redirecting_to_number)) {
17655
	if (!ast_strlen_zero(redirecting_to_number)) {
16463
		if (redirecting->to.number) {
17656
		if (redirecting->to.number) {
16464
			ast_free(redirecting->to.number);
17657
			ast_free(redirecting->to.number);
16465
		}
17658
		}
16466
		ast_debug(3, "Got redirecting to number %s\n", redirecting_to_number);
17659
		ast_debug(3, "Got redirecting to number %s\n", redirecting_to_number);
[+20] [20] 184 lines
[+20] [+] static void handle_response_update(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno)
16651
	if ((p->authtries == MAX_AUTHTRIES) || do_proxy_auth(p, req, resp, SIP_UPDATE, 1)) {
17844
	if ((p->authtries == MAX_AUTHTRIES) || do_proxy_auth(p, req, resp, SIP_UPDATE, 1)) {
16652
		ast_log(LOG_NOTICE, "Failed to authenticate on UPDATE to '%s'\n", get_header(&p->initreq, "From"));
17845
		ast_log(LOG_NOTICE, "Failed to authenticate on UPDATE to '%s'\n", get_header(&p->initreq, "From"));
16653
	}
17846
	}
16654
}
17847
}
16655

    
   
17848

   

    
   
17849
static void cc_handle_publish_error(struct sip_pvt *pvt, const int resp, struct sip_request *req, struct sip_epa_entry *epa_entry)

    
   
17850
{

    
   
17851
	struct cc_epa_entry *cc_entry = epa_entry->instance_data;

    
   
17852
	struct sip_monitor_instance *monitor_instance = ao2_callback(sip_monitor_instances, 0,

    
   
17853
			find_sip_monitor_instance_by_suspension_entry, epa_entry);

    
   
17854
	const char *min_expires;

    
   
17855

   

    
   
17856
	if (!monitor_instance) {

    
   
17857
		ast_log(LOG_WARNING, "Can't find monitor_instance corresponding to epa_entry %p.\n", epa_entry);

    
   
17858
		return;

    
   
17859
	}

    
   
17860

   

    
   
17861
	if (resp != 423) {

    
   
17862
		ast_cc_monitor_failed(cc_entry->core_id, monitor_instance->device_name,

    
   
17863
				"Received error response to our PUBLISH");

    
   
17864
		ao2_ref(monitor_instance, -1);

    
   
17865
		return;

    
   
17866
	}

    
   
17867

   

    
   
17868
	/* Allrighty, the other end doesn't like our Expires value. They think it's

    
   
17869
	 * too small, so let's see if they've provided a more sensible value. If they

    
   
17870
	 * haven't, then we'll just double our Expires value and see if they like that

    
   
17871
	 * instead.

    
   
17872
	 *

    
   
17873
	 * XXX Ideally this logic could be placed into its own function so that SUBSCRIBE,

    
   
17874
	 * PUBLISH, and REGISTER could all benefit from the same shared code.

    
   
17875
	 */

    
   
17876
	min_expires = get_header(req, "Min-Expires");

    
   
17877
	if (ast_strlen_zero(min_expires)) {

    
   
17878
		pvt->expiry *= 2;

    
   
17879
		if (pvt->expiry < 0) {

    
   
17880
			/* You dork! You overflowed! */

    
   
17881
			ast_cc_monitor_failed(cc_entry->core_id, monitor_instance->device_name,

    
   
17882
					"PUBLISH expiry overflowed");

    
   
17883
			ao2_ref(monitor_instance, -1);

    
   
17884
			return;

    
   
17885
		}

    
   
17886
	} else if (sscanf(min_expires, "%d", &pvt->expiry) != 1) {

    
   
17887
		ast_cc_monitor_failed(cc_entry->core_id, monitor_instance->device_name,

    
   
17888
				"Min-Expires has non-numeric value");

    
   
17889
		ao2_ref(monitor_instance, -1);

    
   
17890
		return;

    
   
17891
	}

    
   
17892
	/* At this point, we have most certainly changed pvt->expiry, so try transmitting

    
   
17893
	 * again

    
   
17894
	 */

    
   
17895
	transmit_invite(pvt, SIP_PUBLISH, FALSE, 0, NULL);

    
   
17896
	ao2_ref(monitor_instance, -1);

    
   
17897
}

    
   
17898

   

    
   
17899
static void handle_response_publish(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno)

    
   
17900
{

    
   
17901
	struct sip_epa_entry *epa_entry = p->epa_entry;

    
   
17902
	const char *etag = get_header(req, "Sip-ETag");

    
   
17903

   

    
   
17904
	ast_assert(epa_entry != NULL);

    
   
17905

   

    
   
17906
	if (resp == 401 || resp == 407) {

    
   
17907
		ast_string_field_set(p, theirtag, NULL);

    
   
17908
		if (p->options) {

    
   
17909
			p->options->auth_type = (resp == 401 ? WWW_AUTH : PROXY_AUTH);

    
   
17910
		}

    
   
17911
		if ((p->authtries == MAX_AUTHTRIES) || do_proxy_auth(p, req, resp, SIP_PUBLISH, 0)) {

    
   
17912
			ast_log(LOG_NOTICE, "Failed to authenticate on PUBLISH to '%s'\n", get_header(&p->initreq, "From"));

    
   
17913
			pvt_set_needdestroy(p, "Failed to authenticate on PUBLISH");

    
   
17914
			sip_alreadygone(p);

    
   
17915
		}

    
   
17916
		return;

    
   
17917
	}

    
   
17918

   

    
   
17919
	if (resp == 501 || resp == 405) {

    
   
17920
		mark_method_unallowed(&p->allowed_methods, SIP_PUBLISH);

    
   
17921
	}

    
   
17922

   

    
   
17923
	if (resp == 200) {

    
   
17924
		p->authtries = 0;

    
   
17925
		/* If I've read section 6, item 6 of RFC 3903 correctly,

    
   
17926
		 * an ESC will only generate a new etag when it sends a 200 OK

    
   
17927
		 */

    
   
17928
		if (!ast_strlen_zero(etag)) {

    
   
17929
			ast_copy_string(epa_entry->entity_tag, etag, sizeof(epa_entry->entity_tag));

    
   
17930
		}

    
   
17931
		/* The nominal case. Everything went well. Everybody is happy.

    
   
17932
		 * Each EPA will have a specific action to take as a result of this

    
   
17933
		 * development, so ... callbacks!

    
   
17934
		 */

    
   
17935
		if (epa_entry->static_data->handle_ok) {

    
   
17936
			epa_entry->static_data->handle_ok(p, req, epa_entry);

    
   
17937
		}

    
   
17938
	} else {

    
   
17939
		/* Rather than try to make individual callbacks for each error

    
   
17940
		 * type, there is just a single error callback. The callback

    
   
17941
		 * can distinguish between error messages and do what it needs to

    
   
17942
		 */

    
   
17943
		if (epa_entry->static_data->handle_error) {

    
   
17944
			epa_entry->static_data->handle_error(p, resp, req, epa_entry);

    
   
17945
		}

    
   
17946
	}

    
   
17947
}

    
   
17948

   
16656
/*! \brief Handle SIP response to INVITE dialogue */
17949
/*! \brief Handle SIP response to INVITE dialogue */
16657
static void handle_response_invite(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno)
17950
static void handle_response_invite(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno)
16658
{
17951
{
16659
	int outgoing = ast_test_flag(&p->flags[0], SIP_OUTGOING);
17952
	int outgoing = ast_test_flag(&p->flags[0], SIP_OUTGOING);
16660
	int res = 0;
17953
	int res = 0;
[+20] [20] 57 lines
[+20] static void handle_response_invite(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno)
16718
		if (!req->ignore && p->owner) {
18011
		if (!req->ignore && p->owner) {
16719
			if (get_rpid(p, req)) {
18012
			if (get_rpid(p, req)) {
16720
				ast_party_connected_line_init(&connected);
18013
				ast_party_connected_line_init(&connected);
16721
				connected.id.number = (char *) p->cid_num;
18014
				connected.id.number = (char *) p->cid_num;
16722
				connected.id.name = (char *) p->cid_name;
18015
				connected.id.name = (char *) p->cid_name;

    
   
18016
				connected.id.tag = (char *) p->cid_tag;
16723
				connected.id.number_presentation = p->callingpres;
18017
				connected.id.number_presentation = p->callingpres;
16724
				connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
18018
				connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
16725
				ast_channel_queue_connected_line_update(p->owner, &connected);
18019
				ast_channel_queue_connected_line_update(p->owner, &connected);
16726
			}
18020
			}

    
   
18021
			sip_handle_cc(p, req, AST_CC_CCNR);
16727
			ast_queue_control(p->owner, AST_CONTROL_RINGING);
18022
			ast_queue_control(p->owner, AST_CONTROL_RINGING);
16728
			if (p->owner->_state != AST_STATE_UP) {
18023
			if (p->owner->_state != AST_STATE_UP) {
16729
				ast_setstate(p->owner, AST_STATE_RINGING);
18024
				ast_setstate(p->owner, AST_STATE_RINGING);
16730
			}
18025
			}
16731
		}
18026
		}
[+20] [20] 15 lines
[+20] static void handle_response_invite(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno)
16747
			ast_log(LOG_WARNING, "Unable to cancel SIP destruction.  Expect bad things.\n");
18042
			ast_log(LOG_WARNING, "Unable to cancel SIP destruction.  Expect bad things.\n");
16748
		if (!req->ignore && p->owner) {
18043
		if (!req->ignore && p->owner) {
16749
			struct ast_party_redirecting redirecting = {{0,},};
18044
			struct ast_party_redirecting redirecting = {{0,},};
16750
			change_redirecting_information(p, req, &redirecting, FALSE);
18045
			change_redirecting_information(p, req, &redirecting, FALSE);
16751
			ast_channel_queue_redirecting_update(p->owner, &redirecting);
18046
			ast_channel_queue_redirecting_update(p->owner, &redirecting);

    
   
18047
			ast_party_redirecting_free(&redirecting);

    
   
18048
			sip_handle_cc(p, req, AST_CC_CCNR);
16752
		}
18049
		}
16753
		check_pendings(p);
18050
		check_pendings(p);
16754
		break;
18051
		break;
16755

    
   
18052

   
16756
	case 183:	/* Session progress */
18053
	case 183:	/* Session progress */
16757
		if (!req->ignore && (p->invitestate != INV_CANCELLED) && sip_cancel_destroy(p))
18054
		if (!req->ignore && (p->invitestate != INV_CANCELLED) && sip_cancel_destroy(p))
16758
			ast_log(LOG_WARNING, "Unable to cancel SIP destruction.  Expect bad things.\n");
18055
			ast_log(LOG_WARNING, "Unable to cancel SIP destruction.  Expect bad things.\n");
16759
		if (!req->ignore && p->owner) {
18056
		if (!req->ignore && p->owner) {
16760
			if (get_rpid(p, req)) {
18057
			if (get_rpid(p, req)) {
16761
				/* Queue a connected line update */
18058
				/* Queue a connected line update */
16762
				ast_party_connected_line_init(&connected);
18059
				ast_party_connected_line_init(&connected);
16763
				connected.id.number = (char *) p->cid_num;
18060
				connected.id.number = (char *) p->cid_num;
16764
				connected.id.name = (char *) p->cid_name;
18061
				connected.id.name = (char *) p->cid_name;

    
   
18062
				connected.id.tag = (char *) p->cid_tag;
16765
				connected.id.number_presentation = p->callingpres;
18063
				connected.id.number_presentation = p->callingpres;
16766
				connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
18064
				connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
16767
				ast_channel_queue_connected_line_update(p->owner, &connected);
18065
				ast_channel_queue_connected_line_update(p->owner, &connected);
16768
			}
18066
			}

    
   
18067
			sip_handle_cc(p, req, AST_CC_CCNR);
16769
		}
18068
		}
16770
		if (find_sdp(req)) {
18069
		if (find_sdp(req)) {
16771
			if (p->invitestate != INV_CANCELLED)
18070
			if (p->invitestate != INV_CANCELLED)
16772
				p->invitestate = INV_EARLY_MEDIA;
18071
				p->invitestate = INV_EARLY_MEDIA;
16773
			res = process_sdp(p, req, SDP_T38_NONE);
18072
			res = process_sdp(p, req, SDP_T38_NONE);
[+20] [20] 30 lines
[+20] static void handle_response_invite(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno)
16804
		if (!req->ignore && p->owner && (get_rpid(p, req) || !reinvite)) {
18103
		if (!req->ignore && p->owner && (get_rpid(p, req) || !reinvite)) {
16805
			/* Queue a connected line update */
18104
			/* Queue a connected line update */
16806
			ast_party_connected_line_init(&connected);
18105
			ast_party_connected_line_init(&connected);
16807
			connected.id.number = (char *) p->cid_num;
18106
			connected.id.number = (char *) p->cid_num;
16808
			connected.id.name = (char *) p->cid_name;
18107
			connected.id.name = (char *) p->cid_name;

    
   
18108
			connected.id.tag = (char *) p->cid_tag;
16809
			connected.id.number_presentation = p->callingpres;
18109
			connected.id.number_presentation = p->callingpres;
16810
			connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
18110
			connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
16811
			ast_channel_queue_connected_line_update(p->owner, &connected);
18111
			ast_channel_queue_connected_line_update(p->owner, &connected);
16812
		}
18112
		}
16813

    
   
18113

   
[+20] [20] 636 lines
[+20] [+] static void handle_response(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno)
17450

    
   
18750

   
17451
	sipmethod = find_sip_method(msg);
18751
	sipmethod = find_sip_method(msg);
17452

    
   
18752

   
17453
	owner = p->owner;
18753
	owner = p->owner;
17454
	if (owner) {
18754
	if (owner) {
17455
		char causevar[256], causeval[256];

   
17456
		const char *rp = NULL, *rh = NULL;
18755
		const char *rp = NULL, *rh = NULL;
17457

    
   
18756

   
17458
		owner->hangupcause = 0;
18757
		owner->hangupcause = 0;
17459
		if (ast_test_flag(&p->flags[1], SIP_PAGE2_Q850_REASON) && (rh = get_header(req, "Reason"))) {
18758
		if (ast_test_flag(&p->flags[1], SIP_PAGE2_Q850_REASON) && (rh = get_header(req, "Reason"))) {
17460
			rh = ast_skip_blanks(rh);
18759
			rh = ast_skip_blanks(rh);
[+20] [20] 7 lines
[+20] static void handle_response(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno)
17468
			}
18767
			}
17469
		}
18768
		}
17470

    
   
18769

   
17471
		if (!owner->hangupcause)
18770
		if (!owner->hangupcause)
17472
			owner->hangupcause = hangup_sip2cause(resp);
18771
			owner->hangupcause = hangup_sip2cause(resp);
17473

    
   

   
17474
		snprintf(causevar, sizeof(causevar), "MASTER_CHANNEL(HASH(SIP_CAUSE,%s))", owner->name);
Moved to 22852

   
17475
		snprintf(causeval, sizeof(causeval), "SIP %s", REQ_OFFSET_TO_STR(req, rlPart2));
Moved to 22853

   
17476
		pbx_builtin_setvar_helper(owner, causevar, causeval);

   
17477
	}
18772
	}
17478

    
   
18773

   
17479
	if (p->socket.type == SIP_TRANSPORT_UDP) {
18774
	if (p->socket.type == SIP_TRANSPORT_UDP) {
17480
		int ack_res;
18775
		int ack_res;
17481

    
   
18776

   
[+20] [20] 45 lines
[+20] static void handle_response(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno)
17527
		/* We don't really care what the response is, just that it replied back.
18822
		/* We don't really care what the response is, just that it replied back.
17528
		   Well, as long as it's not a 100 response...  since we might
18823
		   Well, as long as it's not a 100 response...  since we might
17529
		   need to hang around for something more "definitive" */
18824
		   need to hang around for something more "definitive" */
17530
		if (resp != 100)
18825
		if (resp != 100)
17531
			handle_response_peerpoke(p, resp, req);
18826
			handle_response_peerpoke(p, resp, req);

    
   
18827
	} else if (sipmethod == SIP_PUBLISH) {

    
   
18828
		/* SIP PUBLISH transcends this morass of doodoo and instead

    
   
18829
		 * we just always call the response handler. Good gravy!

    
   
18830
		 */

    
   
18831
		handle_response_publish(p, resp, rest, req, seqno);
17532
	} else if (ast_test_flag(&p->flags[0], SIP_OUTGOING)) {
18832
	} else if (ast_test_flag(&p->flags[0], SIP_OUTGOING)) {
17533
		switch(resp) {
18833
		switch(resp) {
17534
		case 100:	/* 100 Trying */
18834
		case 100:	/* 100 Trying */
17535
		case 101:	/* 101 Dialog establishment */
18835
		case 101:	/* 101 Dialog establishment */
17536
		case 183:	/* 183 Session Progress */
18836
		case 183:	/* 183 Session Progress */
[+20] [20] 179 lines
[+20] static void handle_response(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno)
17716
				case 305: /* Use Proxy */
19016
				case 305: /* Use Proxy */
17717
				if (p->owner) {
19017
				if (p->owner) {
17718
					struct ast_party_redirecting redirecting = {{0,},};
19018
					struct ast_party_redirecting redirecting = {{0,},};
17719
					change_redirecting_information(p, req, &redirecting, TRUE);
19019
					change_redirecting_information(p, req, &redirecting, TRUE);
17720
					ast_channel_set_redirecting(p->owner, &redirecting);
19020
					ast_channel_set_redirecting(p->owner, &redirecting);

    
   
19021
					ast_party_redirecting_free(&redirecting);
17721
				}
19022
				}
17722
					/* Fall through */
19023
					/* Fall through */
17723
				case 486: /* Busy here */
19024
				case 486: /* Busy here */
17724
				case 600: /* Busy everywhere */
19025
				case 600: /* Busy everywhere */
17725
				case 603: /* Decline */
19026
				case 603: /* Decline */
17726
					if (p->owner)
19027
					if (p->owner) {

    
   
19028
						sip_handle_cc(p, req, AST_CC_CCBS);
17727
						ast_queue_control(p->owner, AST_CONTROL_BUSY);
19029
						ast_queue_control(p->owner, AST_CONTROL_BUSY);

    
   
19030
					}
17728
					break;
19031
					break;
17729
				case 482: /*!
19032
				case 482: /*!
17730
					\note SIP is incapable of performing a hairpin call, which
19033
					\note SIP is incapable of performing a hairpin call, which
17731
					is yet another failure of not having a layer 2 (again, YAY
19034
					is yet another failure of not having a layer 2 (again, YAY
17732
					 IETF for thinking ahead).  So we treat this as a call
19035
					 IETF for thinking ahead).  So we treat this as a call
[+20] [20] 63 lines
[+20] static void handle_response(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno)
17796

    
   
19099

   
17797
			gettag(req, "To", tag, sizeof(tag));
19100
			gettag(req, "To", tag, sizeof(tag));
17798
			ast_string_field_set(p, theirtag, tag);
19101
			ast_string_field_set(p, theirtag, tag);
17799
		}
19102
		}
17800

    
   
19103

   

    
   
19104
		if (sipmethod == SIP_SUBSCRIBE && resp >= 400) {

    
   
19105
			struct sip_monitor_instance *monitor_instance = ao2_callback(sip_monitor_instances,

    
   
19106
					0, find_sip_monitor_instance_by_subscription_pvt, p);

    
   
19107
			if (monitor_instance) {

    
   
19108
				ast_cc_monitor_failed(monitor_instance->core_id, monitor_instance->device_name,

    
   
19109
						"Received error response to our SUBSCRIBE");

    
   
19110
				return;

    
   
19111
			}

    
   
19112
		}

    
   
19113

   
17801
		switch(resp) {
19114
		switch(resp) {
17802
		case 200:
19115
		case 200:
17803
			if (sipmethod == SIP_INVITE) {
19116
			if (sipmethod == SIP_INVITE) {
17804
				handle_response_invite(p, resp, rest, req, seqno);
19117
				handle_response_invite(p, resp, rest, req, seqno);
17805
			} else if (sipmethod == SIP_CANCEL) {
19118
			} else if (sipmethod == SIP_CANCEL) {
[+20] [20] 366 lines
[+20] [+] static const char *gettag(const struct sip_request *req, const char *header, char *tagbuf, int tagbufsize)
18172
		return strsep(&tagbuf, ";");
19485
		return strsep(&tagbuf, ";");
18173
	}
19486
	}
18174
	return NULL;
19487
	return NULL;
18175
}
19488
}
18176

    
   
19489

   

    
   
19490
static int handle_cc_notify(struct sip_pvt *pvt, struct sip_request *req)

    
   
19491
{

    
   
19492
	struct sip_monitor_instance *monitor_instance = ao2_callback(sip_monitor_instances, 0,

    
   
19493
			find_sip_monitor_instance_by_subscription_pvt, pvt);

    
   
19494
	const char *status = get_body(req, "cc-state", ':');

    
   
19495
	struct cc_epa_entry *cc_entry;

    
   
19496
	char *uri;

    
   
19497

   

    
   
19498
	if (!monitor_instance) {

    
   
19499
		transmit_response(pvt, "400 Bad Request", req);

    
   
19500
		return -1;

    
   
19501
	}

    
   
19502

   

    
   
19503
	if (ast_strlen_zero(status)) {

    
   
19504
		ao2_ref(monitor_instance, -1);

    
   
19505
		transmit_response(pvt, "400 Bad Request", req);

    
   
19506
		return -1;

    
   
19507
	}

    
   
19508

   

    
   
19509
	if (!strcmp(status, "queued")) {

    
   
19510
		/* We've been told that we're queued. This is the endpoint's way of telling

    
   
19511
		 * us that it has accepted our CC request. We need to alert the core of this

    
   
19512
		 * development

    
   
19513
		 */

    
   
19514
		ast_cc_monitor_request_acked(monitor_instance->core_id, "SIP endpoint %s accepted request", monitor_instance->device_name);

    
   
19515
		transmit_response(pvt, "200 OK", req);

    
   
19516
		ao2_ref(monitor_instance, -1);

    
   
19517
		return 0;

    
   
19518
	}

    
   
19519

   

    
   
19520
	/* It's open! Yay! */

    
   
19521
	uri = get_body(req, "cc-URI", ':');

    
   
19522
	if (ast_strlen_zero(uri)) {

    
   
19523
		uri = get_in_brackets((char *)get_header(req, "From"));

    
   
19524
	}

    
   
19525

   

    
   
19526
	ast_string_field_set(monitor_instance, notify_uri, uri);

    
   
19527
	if (monitor_instance->suspension_entry) {

    
   
19528
		cc_entry = monitor_instance->suspension_entry->instance_data;

    
   
19529
		if (cc_entry->current_state == CC_CLOSED) {

    
   
19530
			/* If we've created a suspension entry and the current state is closed, then that means

    
   
19531
			 * we got a notice from the CC core earlier to suspend monitoring, but because this particular

    
   
19532
			 * call leg had not yet notified us that it was ready for recall, it meant that we

    
   
19533
			 * could not yet send a PUBLISH. Now, however, we can.

    
   
19534
			 */

    
   
19535
			construct_pidf_body(CC_CLOSED, monitor_instance->suspension_entry->body,

    
   
19536
					sizeof(monitor_instance->suspension_entry->body), monitor_instance->peername);

    
   
19537
			transmit_publish(monitor_instance->suspension_entry, SIP_PUBLISH_INITIAL, monitor_instance->notify_uri);

    
   
19538
		} else {

    
   
19539
			ast_cc_monitor_callee_available(monitor_instance->core_id, "SIP monitored callee has become available");

    
   
19540
		}

    
   
19541
	} else {

    
   
19542
		ast_cc_monitor_callee_available(monitor_instance->core_id, "SIP monitored callee has become available");

    
   
19543
	}

    
   
19544
	ao2_ref(monitor_instance, -1);

    
   
19545
	transmit_response(pvt, "200 OK", req);

    
   
19546

   

    
   
19547
	return 0;

    
   
19548
}

    
   
19549

   
18177
/*! \brief Handle incoming notifications */
19550
/*! \brief Handle incoming notifications */
18178
static int handle_request_notify(struct sip_pvt *p, struct sip_request *req, struct sockaddr_in *sin, int seqno, const char *e)
19551
static int handle_request_notify(struct sip_pvt *p, struct sip_request *req, struct sockaddr_in *sin, int seqno, const char *e)
18179
{
19552
{
18180
	/* This is mostly a skeleton for future improvements */
19553
	/* This is mostly a skeleton for future improvements */
18181
	/* Mostly created to return proper answers on notifications on outbound REFER's */
19554
	/* Mostly created to return proper answers on notifications on outbound REFER's */
[+20] [20] 152 lines