Revision b2bea585 plugins/janus_sipre.c

View differences:

plugins/janus_sipre.c
3170 3170
	char callid[256];
3171 3171
	g_snprintf(callid, sizeof(callid), "%.*s", (int)msg->callid.l, msg->callid.p);
3172 3172
	JANUS_LOG(LOG_HUGE, "[SIPre-%s]   -- Call-ID: %s\n", session->account.username, callid);
3173

  
3174
	const char *offer = (const char *)mbuf_buf(msg->mb);
3175
	if(offer == NULL) {
3176
		/* No SDP? */
3177
		JANUS_LOG(LOG_WARN, "[SIPre-%s] No SDP in the INVITE?\n", session->account.username);
3178
		mqueue_push(mq, janus_sipre_mqueue_event_do_rcode, janus_sipre_mqueue_payload_create(session, msg, 488, NULL));
3179
		return;
3180
	}
3181
	char sdp_offer[1024];
3182
	g_snprintf(sdp_offer, sizeof(sdp_offer), "%.*s", (int)mbuf_get_left(msg->mb), offer);
3183
	JANUS_LOG(LOG_HUGE, "[SIPre-%s]   -- Offer: %s\n", session->account.username, sdp_offer);
3184
	/* Parse the remote SDP */
3185
	char sdperror[100];
3186
	janus_sdp *sdp = janus_sdp_parse(sdp_offer, sdperror, sizeof(sdperror));
3187
	if(!sdp) {
3188
		JANUS_LOG(LOG_ERR, "\tError parsing SDP! %s\n", sdperror);
3189
		mqueue_push(mq, janus_sipre_mqueue_event_do_rcode, janus_sipre_mqueue_payload_create(session, msg, 488, NULL));
3190
		return;
3191
	}
3192

  
3173
	/* Make sure we're not in a call already */
3193 3174
	if(session->stack.sess != NULL) {
3194 3175
		/* Already in a call */
3195
		janus_sdp_free(sdp);
3196
		JANUS_LOG(LOG_VERB, "\tAlready in a call (busy, status=%s)\n", janus_sipre_call_status_string(session->status));
3197
		mqueue_push(mq, janus_sipre_mqueue_event_do_rcode, janus_sipre_mqueue_payload_create(session, msg, 486, NULL));
3176
		JANUS_LOG(LOG_VERB, "Already in a call (busy, status=%s)\n", janus_sipre_call_status_string(session->status));
3177
		mqueue_push(mq, janus_sipre_mqueue_event_do_rcode, janus_sipre_mqueue_payload_create(session, msg, 486, session));
3198 3178
		/* Notify the web app about the missed invite */
3199 3179
		json_t *missed = json_object();
3200 3180
		json_object_set_new(missed, "sip", json_string("event"));
......
3220 3200
		return;
3221 3201
	}
3222 3202
	/* New incoming call */
3203
	const char *offer = (const char *)mbuf_buf(msg->mb);
3204
	if(offer == NULL) {
3205
		/* No SDP? */
3206
		JANUS_LOG(LOG_WARN, "[SIPre-%s] No SDP in the INVITE?\n", session->account.username);
3207
		mqueue_push(mq, janus_sipre_mqueue_event_do_rcode, janus_sipre_mqueue_payload_create(session, msg, 488, NULL));
3208
		return;
3209
	}
3210
	char sdp_offer[1024];
3211
	g_snprintf(sdp_offer, sizeof(sdp_offer), "%.*s", (int)mbuf_get_left(msg->mb), offer);
3212
	JANUS_LOG(LOG_HUGE, "[SIPre-%s]   -- Offer: %s\n", session->account.username, sdp_offer);
3213
	/* Parse the remote SDP */
3214
	char sdperror[100];
3215
	janus_sdp *sdp = janus_sdp_parse(sdp_offer, sdperror, sizeof(sdperror));
3216
	if(!sdp) {
3217
		JANUS_LOG(LOG_ERR, "Error parsing SDP! %s\n", sdperror);
3218
		mqueue_push(mq, janus_sipre_mqueue_event_do_rcode, janus_sipre_mqueue_payload_create(session, msg, 488, NULL));
3219
		return;
3220
	}
3223 3221
	session->callee = g_strdup(from);
3224 3222
	session->callid = g_strdup(callid);
3225 3223
	g_hash_table_insert(callids, session->callid, session);
......
3298 3296
	char sdperror[100];
3299 3297
	janus_sdp *sdp = janus_sdp_parse(sdp_offer, sdperror, sizeof(sdperror));
3300 3298
	if(!sdp) {
3301
		JANUS_LOG(LOG_ERR, "\tError parsing SDP! %s\n", sdperror);
3299
		JANUS_LOG(LOG_ERR, "Error parsing SDP! %s\n", sdperror);
3302 3300
		return EINVAL;
3303 3301
	}
3304 3302
	gboolean changed = FALSE;
......
3340 3338
	char sdperror[100];
3341 3339
	janus_sdp *sdp = janus_sdp_parse(sdp_answer, sdperror, sizeof(sdperror));
3342 3340
	if(!sdp) {
3343
		JANUS_LOG(LOG_ERR, "\tError parsing SDP! %s\n", sdperror);
3341
		JANUS_LOG(LOG_ERR, "Error parsing SDP! %s\n", sdperror);
3344 3342
		return EINVAL;
3345 3343
	}
3346 3344
	/* Parse SDP */
......
3699 3697
					err = sipsess_answer(session->stack.sess, payload->rcode, janus_sipre_error_reason(payload->rcode), NULL, NULL);
3700 3698
				} else {
3701 3699
					/* 3xx, 4xx, 5xx, 6xx */
3702
					err = sipsess_reject(session->stack.sess, payload->rcode, janus_sipre_error_reason(payload->rcode), NULL);
3703
					session->media.ready = FALSE;
3704
					session->media.on_hold = FALSE;
3705
					session->status = janus_sipre_call_status_idle;
3700
					if(payload->data == NULL) {
3701
						/* Send an error message on the current call */
3702
						err = sipsess_reject(session->stack.sess, payload->rcode, janus_sipre_error_reason(payload->rcode), NULL);
3703
						session->media.ready = FALSE;
3704
						session->media.on_hold = FALSE;
3705
						session->status = janus_sipre_call_status_idle;
3706
					} else {
3707
						/* We're rejecting a new call because we're busy in another one: accept first and then reject */
3708
						struct sipsess *sess = NULL;
3709
						err = sipsess_accept(&sess, session->stack.sess_sock,
3710
							payload->msg, 180, janus_sipre_error_reason(180),
3711
							session->account.display_name ? session->account.display_name : session->account.username,
3712
							"application/sdp", NULL,
3713
							janus_sipre_cb_auth, session, FALSE,
3714
							janus_sipre_cb_offer, janus_sipre_cb_answer,
3715
							janus_sipre_cb_established, NULL, NULL,
3716
							janus_sipre_cb_closed, session, NULL);
3717
						err = sipsess_reject(sess, payload->rcode, janus_sipre_error_reason(payload->rcode), NULL);
3718
					}
3706 3719
				}
3707 3720
			}
3708 3721
			if(err != 0) {

Also available in: Unified diff