Revision 71a04f89 plugins/janus_sip.c

View differences:

plugins/janus_sip.c
174 174

  
175 175
/* Useful stuff */
176 176
static volatile gint initialized = 0, stopping = 0;
177
static gboolean notify_events = TRUE;
177 178
static janus_callbacks *gateway = NULL;
178 179

  
179 180
static char local_ip[INET6_ADDRSTRLEN];
......
812 813
	g_snprintf(filename, 255, "%s/%s.cfg", config_path, JANUS_SIP_PACKAGE);
813 814
	JANUS_LOG(LOG_VERB, "Configuration file: %s\n", filename);
814 815
	janus_config *config = janus_config_parse(filename);
815
	if(config != NULL)
816
	if(config != NULL) {
816 817
		janus_config_print(config);
817 818

  
818
	gboolean local_ip_set = FALSE;
819
	janus_config_item *item = janus_config_get_item_drilldown(config, "general", "local_ip");
820
	if(item && item->value) {
821
		int family;
822
		if (!janus_is_ip_valid(item->value, &family)) {
823
			JANUS_LOG(LOG_WARN, "Invalid local IP specified: %s, guessing the default...\n", item->value);
824
		} else {
825
			/* Verify that we can actually bind to that address */
826
			int fd = socket(family, SOCK_DGRAM, 0);
827
			if (fd == -1) {
828
				JANUS_LOG(LOG_WARN, "Error creating test socket, falling back to detecting IP address...\n");
819
		gboolean local_ip_set = FALSE;
820
		janus_config_item *item = janus_config_get_item_drilldown(config, "general", "local_ip");
821
		if(item && item->value) {
822
			int family;
823
			if (!janus_is_ip_valid(item->value, &family)) {
824
				JANUS_LOG(LOG_WARN, "Invalid local IP specified: %s, guessing the default...\n", item->value);
829 825
			} else {
830
				int r;
831
				struct sockaddr_storage ss;
832
				socklen_t addrlen;
833
				memset(&ss, 0, sizeof(ss));
834
				if (family == AF_INET) {
835
					struct sockaddr_in *addr4 = (struct sockaddr_in*)&ss;
836
					addr4->sin_family = AF_INET;
837
					addr4->sin_port = 0;
838
					inet_pton(AF_INET, item->value, &(addr4->sin_addr.s_addr));
839
					addrlen = sizeof(struct sockaddr_in);
840
				} else {
841
					struct sockaddr_in6 *addr6 = (struct sockaddr_in6*)&ss;
842
					addr6->sin6_family = AF_INET6;
843
					addr6->sin6_port = 0;
844
					inet_pton(AF_INET6, item->value, &(addr6->sin6_addr.s6_addr));
845
					addrlen = sizeof(struct sockaddr_in6);
846
				}
847
				r = bind(fd, (const struct sockaddr*)&ss, addrlen);
848
				close(fd);
849
				if (r < 0) {
850
					JANUS_LOG(LOG_WARN, "Error setting local IP address to %s, falling back to detecting IP address...\n", item->value);
826
				/* Verify that we can actually bind to that address */
827
				int fd = socket(family, SOCK_DGRAM, 0);
828
				if (fd == -1) {
829
					JANUS_LOG(LOG_WARN, "Error creating test socket, falling back to detecting IP address...\n");
851 830
				} else {
852
					g_strlcpy(local_ip, item->value, sizeof(local_ip));
853
					local_ip_set = TRUE;
831
					int r;
832
					struct sockaddr_storage ss;
833
					socklen_t addrlen;
834
					memset(&ss, 0, sizeof(ss));
835
					if (family == AF_INET) {
836
						struct sockaddr_in *addr4 = (struct sockaddr_in*)&ss;
837
						addr4->sin_family = AF_INET;
838
						addr4->sin_port = 0;
839
						inet_pton(AF_INET, item->value, &(addr4->sin_addr.s_addr));
840
						addrlen = sizeof(struct sockaddr_in);
841
					} else {
842
						struct sockaddr_in6 *addr6 = (struct sockaddr_in6*)&ss;
843
						addr6->sin6_family = AF_INET6;
844
						addr6->sin6_port = 0;
845
						inet_pton(AF_INET6, item->value, &(addr6->sin6_addr.s6_addr));
846
						addrlen = sizeof(struct sockaddr_in6);
847
					}
848
					r = bind(fd, (const struct sockaddr*)&ss, addrlen);
849
					close(fd);
850
					if (r < 0) {
851
						JANUS_LOG(LOG_WARN, "Error setting local IP address to %s, falling back to detecting IP address...\n", item->value);
852
					} else {
853
						g_strlcpy(local_ip, item->value, sizeof(local_ip));
854
						local_ip_set = TRUE;
855
					}
854 856
				}
855 857
			}
856 858
		}
859
		if (!local_ip_set)
860
			janus_sip_detect_local_ip(local_ip, sizeof(local_ip));
861
		JANUS_LOG(LOG_VERB, "Local IP set to %s\n", local_ip);
862

  
863
		item = janus_config_get_item_drilldown(config, "general", "keepalive_interval");
864
		if(item && item->value)
865
			keepalive_interval = atoi(item->value);
866
		JANUS_LOG(LOG_VERB, "SIP keep-alive interval set to %d seconds\n", keepalive_interval);
867

  
868
		item = janus_config_get_item_drilldown(config, "general", "register_ttl");
869
		if(item && item->value)
870
			register_ttl = atoi(item->value);
871
		JANUS_LOG(LOG_VERB, "SIP registration TTL set to %d seconds\n", register_ttl);
872

  
873
		item = janus_config_get_item_drilldown(config, "general", "behind_nat");
874
		if(item && item->value)
875
			behind_nat = janus_is_true(item->value);
876

  
877
		item = janus_config_get_item_drilldown(config, "general", "user_agent");
878
		if(item && item->value)
879
			user_agent = g_strdup(item->value);
880
		else
881
			user_agent = g_strdup("Janus WebRTC Gateway SIP Plugin "JANUS_SIP_VERSION_STRING);
882
		JANUS_LOG(LOG_VERB, "SIP User-Agent set to %s\n", user_agent);
883

  
884
		item = janus_config_get_item_drilldown(config, "general", "events");
885
		if(item != NULL && item->value != NULL)
886
			notify_events = janus_is_true(item->value);
887
		if(!notify_events && callback->events_is_enabled()) {
888
			JANUS_LOG(LOG_WARN, "Notification of events to handlers disabled for %s\n", JANUS_SIP_NAME);
889
		}
890

  
891
		janus_config_destroy(config);
857 892
	}
858
	if (!local_ip_set)
859
		janus_sip_detect_local_ip(local_ip, sizeof(local_ip));
860
	JANUS_LOG(LOG_VERB, "Local IP set to %s\n", local_ip);
861

  
862
	item = janus_config_get_item_drilldown(config, "general", "keepalive_interval");
863
	if(item && item->value)
864
		keepalive_interval = atoi(item->value);
865
	JANUS_LOG(LOG_VERB, "SIP keep-alive interval set to %d seconds\n", keepalive_interval);
866

  
867
	item = janus_config_get_item_drilldown(config, "general", "register_ttl");
868
	if(item && item->value)
869
		register_ttl = atoi(item->value);
870
	JANUS_LOG(LOG_VERB, "SIP registration TTL set to %d seconds\n", register_ttl);
871

  
872
	item = janus_config_get_item_drilldown(config, "general", "behind_nat");
873
	if(item && item->value)
874
		behind_nat = janus_is_true(item->value);
875

  
876
	item = janus_config_get_item_drilldown(config, "general", "user_agent");
877
	if(item && item->value)
878
		user_agent = g_strdup(item->value);
879
	else
880
		user_agent = g_strdup("Janus WebRTC Gateway SIP Plugin "JANUS_SIP_VERSION_STRING);
881
	JANUS_LOG(LOG_VERB, "SIP User-Agent set to %s\n", user_agent);
882

  
883
	/* This plugin actually has nothing to configure... */
884
	janus_config_destroy(config);
885 893
	config = NULL;
886 894

  
887 895
	/* Setup sofia */
......
1671 1679
				json_object_set_new(result, "username", json_string(session->account.username));
1672 1680
				json_object_set_new(result, "register_sent", json_string("false"));
1673 1681
				/* Also notify event handlers */
1674
				if(gateway->events_is_enabled()) {
1682
				if(notify_events && gateway->events_is_enabled()) {
1675 1683
					json_t *info = json_object();
1676 1684
					json_object_set_new(info, "event", json_string("registered"));
1677 1685
					json_object_set_new(info, "identity", json_string(session->account.identity));
......
1832 1840
			char callid[24];
1833 1841
			janus_sip_random_string(24, (char *)&callid);
1834 1842
			/* Also notify event handlers */
1835
			if(gateway->events_is_enabled()) {
1843
			if(notify_events && gateway->events_is_enabled()) {
1836 1844
				json_t *info = json_object();
1837 1845
				json_object_set_new(info, "event", json_string("calling"));
1838 1846
				json_object_set_new(info, "callee", json_string(uri_text));
......
1964 1972
			}
1965 1973
			JANUS_LOG(LOG_VERB, "Prepared SDP for 200 OK:\n%s", sdp);
1966 1974
			/* Also notify event handlers */
1967
			if(gateway->events_is_enabled()) {
1975
			if(notify_events && gateway->events_is_enabled()) {
1968 1976
				json_t *info = json_object();
1969 1977
				json_object_set_new(info, "event", json_string("accepted"));
1970 1978
				if(session->callid)
......
2025 2033
			}
2026 2034
			nua_respond(session->stack->s_nh_i, response_code, sip_status_phrase(response_code), TAG_END());
2027 2035
			/* Also notify event handlers */
2028
			if(gateway->events_is_enabled()) {
2036
			if(notify_events && gateway->events_is_enabled()) {
2029 2037
				json_t *info = json_object();
2030 2038
				json_object_set_new(info, "event", json_string("declined"));
2031 2039
				json_object_set_new(info, "callee", json_string(session->callee));
......
2420 2428
				JANUS_LOG(LOG_VERB, "  >> %d (%s)\n", ret, janus_get_api_error(ret));
2421 2429
				g_free(call_text);
2422 2430
				/* Also notify event handlers */
2423
				if(gateway->events_is_enabled()) {
2431
				if(notify_events && gateway->events_is_enabled()) {
2424 2432
					json_t *info = json_object();
2425 2433
					json_object_set_new(info, "event", json_string("proceeding"));
2426 2434
					if(session->callid)
......
2446 2454
				JANUS_LOG(LOG_VERB, "  >> %d (%s)\n", ret, janus_get_api_error(ret));
2447 2455
				g_free(call_text);
2448 2456
				/* Also notify event handlers */
2449
				if(gateway->events_is_enabled()) {
2457
				if(notify_events && gateway->events_is_enabled()) {
2450 2458
					json_t *info = json_object();
2451 2459
					json_object_set_new(info, "event", json_string("hangup"));
2452 2460
					if(session->callid)
......
2525 2533
					JANUS_LOG(LOG_VERB, "  >> %d (%s)\n", ret, janus_get_api_error(ret));
2526 2534
					g_free(missed_text);
2527 2535
					/* Also notify event handlers */
2528
					if(gateway->events_is_enabled()) {
2536
					if(notify_events && gateway->events_is_enabled()) {
2529 2537
						json_t *info = json_object();
2530 2538
						json_object_set_new(info, "event", json_string("missed_call"));
2531 2539
						json_object_set_new(info, "caller", json_string(caller_text));
......
2569 2577
			JANUS_LOG(LOG_VERB, "  >> %d (%s)\n", ret, janus_get_api_error(ret));
2570 2578
			g_free(call_text);
2571 2579
			/* Also notify event handlers */
2572
			if(gateway->events_is_enabled()) {
2580
			if(notify_events && gateway->events_is_enabled()) {
2573 2581
				json_t *info = json_object();
2574 2582
				json_object_set_new(info, "event", json_string("incomingcall"));
2575 2583
				if(session->callid)
......
2729 2737
			JANUS_LOG(LOG_VERB, "  >> %d (%s)\n", ret, janus_get_api_error(ret));
2730 2738
			g_free(call_text);
2731 2739
			/* Also notify event handlers */
2732
			if(gateway->events_is_enabled()) {
2740
			if(notify_events && gateway->events_is_enabled()) {
2733 2741
				json_t *info = json_object();
2734 2742
				json_object_set_new(info, "event", json_string("accepted"));
2735 2743
				if(session->callid)
......
2762 2770
				JANUS_LOG(LOG_VERB, "  >> %d (%s)\n", ret, janus_get_api_error(ret));
2763 2771
				g_free(call_text);
2764 2772
				/* Also notify event handlers */
2765
				if(gateway->events_is_enabled()) {
2773
				if(notify_events && gateway->events_is_enabled()) {
2766 2774
					json_t *info = json_object();
2767 2775
					json_object_set_new(info, "event", json_string("registered"));
2768 2776
					json_object_set_new(info, "identity", json_string(session->account.identity));
......
2807 2815
				JANUS_LOG(LOG_VERB, "  >> %d (%s)\n", ret, janus_get_api_error(ret));
2808 2816
				g_free(event_text);
2809 2817
				/* Also notify event handlers */
2810
				if(gateway->events_is_enabled()) {
2818
				if(notify_events && gateway->events_is_enabled()) {
2811 2819
					json_t *info = json_object();
2812 2820
					json_object_set_new(info, "event", json_string("registration_failed"));
2813 2821
					json_object_set_new(info, "code", json_integer(status));

Also available in: Unified diff