📄 nua_glib.c
字号:
* invite response handler */static void sof_r_invite(int status, char const *phrase, nua_t *nua, NuaGlib *self, nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip, tagi_t tags[]){ if (status >= 300) { op->op_callstate &= ~opc_sent; priv_oper_check_response_for_auth(self, op, status, sip, tags); } g_signal_emit(self, signals[NGSIG_INVITE_ANSWERED],0, op, status, phrase);}/* * incoming call-forked handler * * Releases forked calls */static void sof_i_fork(int status, char const *phrase, nua_t *nua, NuaGlib *self, nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip, tagi_t tags[]){ nua_handle_t *nh2 = NULL; g_signal_emit(self, signals[NGSIG_CALL_FORKED], 0, status, phrase, op); g_warning("%s: call fork: %03d %s\n", self->priv->name, status, phrase); /* We just release forked calls. */ tl_gets(tags, NUTAG_HANDLE_REF(nh2), TAG_END()); g_return_if_fail(nh2); nua_bye(nh2, TAG_END()); nua_handle_destroy(nh2);}/* * incoming invite handler */static void sof_i_invite(nua_t *nua, NuaGlib *self, nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip, tagi_t tags[]){ /* Incoming call */ sip_from_t const *from; sip_to_t const *to; sip_subject_t const *subject; g_return_if_fail(sip); from = sip->sip_from; to = sip->sip_to; subject = sip->sip_subject; char *url; g_return_if_fail(from && to); if (op) { op->op_callstate |= opc_recv; } else if ((op = nua_glib_op_create2(self, SIP_METHOD_INVITE, nh, from))) { op->op_callstate = opc_recv; } else { nua_respond(nh, SIP_500_INTERNAL_SERVER_ERROR, TAG_END()); nua_handle_destroy(nh); } if (op) { if (op->op_callstate == opc_recv) { url = url_as_string(self->priv->home, to->a_url); g_signal_emit(self, signals[NGSIG_INCOMING_INVITE], 0, op, to->a_display, url, subject?subject->g_value:NULL); su_free(self->priv->home, url); } else { g_signal_emit(self, signals[NGSIG_INCOMING_REINVITE], 0, op); } }}/** * nua_glib_redirect: * @op: call to redirect * @contact: contact to redirect to * Redirect a call */voidnua_glib_redirect(NuaGlib *self, NuaGlibOp *op, const char *contact){ nua_respond(op->op_handle, SIP_302_MOVED_TEMPORARILY, SIPTAG_CONTACT_STR(contact), TAG_END());}/** * nua_glib_answer: * @op: operation returned from the incoming-invite signal * @status: SIP response status (see RFCs of SIP) * @phrase: Reponse text (default response phrase used if NULL) * @sdp: SDP description of local media capabilites * * Answer a call. */void nua_glib_answer(NuaGlib *self, NuaGlibOp *op, int status, const char *phrase, const char *sdp){ /* SDP O/A note: * - pass SDP information to nua_respond() in * the SOATAG_USER_SDP_STR() tag * - see also: sof_i_state() and nua_glib_invite() */ if (status >= 200 && status < 300) op->op_callstate |= opc_sent; else op->op_callstate = opc_none; nua_respond(op->op_handle, status, phrase, SOATAG_USER_SDP_STR(sdp), TAG_END());}static void sof_i_prack(nua_t *nua, NuaGlib *self, nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip, tagi_t tags[]){ /* Incoming PRACK */ sip_rack_t const *rack; g_return_if_fail(sip); rack = sip->sip_rack; g_signal_emit(self, signals[NGSIG_INCOMING_PRACK], 0, op, rack ? rack->ra_response : 0); if (op == NULL) nua_handle_destroy(nh);}static void sof_i_state(int status, char const *phrase, nua_t *nua, NuaGlib *self, nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip, tagi_t tags[]){ char const *l_sdp = NULL, *r_sdp = NULL; int audio = NUA_GLIB_MEDIA_INACTIVE; int video = NUA_GLIB_MEDIA_INACTIVE; int image = NUA_GLIB_MEDIA_INACTIVE; int chat = NUA_GLIB_MEDIA_INACTIVE; int offer_recv = 0, answer_recv = 0, offer_sent = 0, answer_sent = 0; int ss_state = nua_callstate_init; g_return_if_fail(op); tl_gets(tags, NUTAG_CALLSTATE_REF(ss_state), NUTAG_ACTIVE_AUDIO_REF(audio), NUTAG_ACTIVE_VIDEO_REF(video), NUTAG_ACTIVE_IMAGE_REF(image), NUTAG_ACTIVE_CHAT_REF(chat), NUTAG_OFFER_RECV_REF(offer_recv), NUTAG_ANSWER_RECV_REF(answer_recv), NUTAG_OFFER_SENT_REF(offer_sent), NUTAG_ANSWER_SENT_REF(answer_sent), SOATAG_LOCAL_SDP_STR_REF(l_sdp), SOATAG_REMOTE_SDP_STR_REF(r_sdp), TAG_END()); /* SDP O/A note: * - check the O/A state and whether local and/or remote SDP * is available (and whether it is updated) * - inform media subsystem of the changes in configuration * - see also: sof_i_state() and nua_glib_invite() */ if (l_sdp) { g_return_if_fail(answer_sent || offer_sent); } if (r_sdp) { g_return_if_fail(answer_recv || offer_recv); } if (op->op_prev_state != ss_state) { /* note: only emit if state has changed */ g_signal_emit(self, signals[NGSIG_CALL_STATE_CHANGED], 0, op, audio, video, image, chat, l_sdp, r_sdp); op->op_prev_state = ss_state; }}static void sof_i_active(nua_t *nua, NuaGlib *self, nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip, tagi_t tags[]){ assert(op); op->op_callstate = opc_active; g_signal_emit(self, signals[NGSIG_INCOMING_ACTIVE], 0, op);}static gboolean idle_kill_op (gpointer data){ NuaGlibOp* op = (NuaGlibOp *)data; nua_glib_op_destroy(op->op_parent, op); return FALSE;}static void sof_i_terminated(int status, char const *phrase, nua_t *nua, NuaGlib *self, nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip, tagi_t tags[]){ if (op) { g_signal_emit(self, signals[NGSIG_CALL_TERMINATED], 0, op, status); op->op_callstate = 0; g_idle_add(idle_kill_op, op); }}/** * nua_glib_bye: * @op the call to bye * * Initiate a BYE * a bye-received signal will be emitted with the response to the bye */void nua_glib_bye(NuaGlib *self, NuaGlibOp *op){ nua_bye(op->op_handle, TAG_END()); op->op_callstate = 0;}void sof_r_bye(int status, char const *phrase, nua_t *nua, NuaGlib *self, nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip, tagi_t tags[]){ assert(op); assert(op->op_handle == nh); g_signal_emit(self, signals[NGSIG_BYE_ANSWERED], 0, op, status, phrase);}static void sof_i_bye(nua_t *nua, NuaGlib *self, nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip, tagi_t tags[]){ assert(op); assert(op->op_handle == nh); g_signal_emit(self, signals[NGSIG_INCOMING_BYE], 0, op);}/** * nua_glib_cancel: * @op the call to cancel * * Cancel a call * A cancel-received signal will be emitted with the response to the cancel */void nua_glib_cancel(NuaGlib *self, NuaGlibOp *op){ nua_cancel(op->op_handle, TAG_END());}void sof_i_cancel(nua_t *nua, NuaGlib *self, nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip, tagi_t tags[]){ assert(op); assert(op->op_handle == nh); g_signal_emit(self, signals[NGSIG_INCOMING_CANCEL], 0, op);}/** * nua_glib_options: * @destination: URI to set options for * make an options request to the destination * * Return value: operation created for request */NuaGlibOp *nua_glib_options(NuaGlib *self, const char *destination){ NuaGlibOp *op = nua_glib_op_create(self, SIP_METHOD_OPTIONS, destination, TAG_END()); if (op) { nua_options(op->op_handle, TAG_END()); return op; } else return NULL; }static void sof_r_options(int status, char const *phrase, nua_t *nua, NuaGlib *self, nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip, tagi_t tags[]){ g_signal_emit(self, signals[NGSIG_OPTIONS_ANSWERED], 0, op, status, phrase); priv_oper_check_response_for_auth(self, op, status, sip, tags);}/** * nua_glib_message: * @destination destination address * @message: message to send * * Send a message to a given destination address * Return value: operation created for the message, NULL cif failure */NuaGlibOp * nua_glib_message(NuaGlib *self, const char *destination, const char *message){ NuaGlibOp *op = nua_glib_op_create(self, SIP_METHOD_MESSAGE, destination, TAG_END()); if (op) { nua_message(op->op_handle, SIPTAG_CONTENT_TYPE_STR("text/plain"), SIPTAG_PAYLOAD_STR(message), TAG_END()); return op; } else return NULL;}static void sof_r_message(int status, char const *phrase, nua_t *nua, NuaGlib *self, nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip, tagi_t tags[]){ g_signal_emit(self, signals[NGSIG_MESSAGE_ANSWERED], 0, op, status, phrase); if (status < 200) return; priv_oper_check_response_for_auth(self, op, status, sip, tags);}static void sof_i_message(nua_t *nua, NuaGlib *self, nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip, tagi_t tags[]){ /* Incoming message */ sip_from_t const *from; sip_to_t const *to; sip_subject_t const *subject; GString *message; char *url; assert(sip); from = sip->sip_from; to = sip->sip_to; subject = sip->sip_subject; assert(from && to); if (sip->sip_payload) message=g_string_new_len(sip->sip_payload->pl_data, sip->sip_payload->pl_len); else message=NULL; url = url_as_string(self->priv->home, to->a_url); g_signal_emit(self, signals[NGSIG_INCOMING_MESSAGE], 0, op, to->a_display, url, subject ? subject->g_value : NULL, message ? message->str : NULL); su_free(self->priv->home, url); if (message) g_string_free(message, TRUE); if (op == NULL) op = nua_glib_op_create2(self, SIP_METHOD_MESSAGE, nh, from); if (op == NULL) nua_handle_destroy(nh);}/** * nua_glib_info: * @op operation representing existing call to send INFO in * @message INFO message to send * * Send an INFO request to a destination on an existing call */voidnua_glib_info (NuaGlib *self, NuaGlibOp *op, const char *content_type, const char *message){ nua_info(op->op_handle, SIPTAG_CONTENT_TYPE_STR(content_type), SIPTAG_PAYLOAD_STR(message), TAG_END());}static void sof_r_info(int status, char const *phrase, nua_t *nua, NuaGlib *self, nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip, tagi_t tags[]){ g_signal_emit(self, signals[NGSIG_INFO_ANSWERED], 0, op, status, phrase); if (status < 200) return; priv_oper_check_response_for_auth(self, op, status, sip, tags);}static void sof_i_info(nua_t *nua, NuaGlib *self, nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip, tagi_t tags[]){ /* Incoming info */ sip_from_t const *from; sip_to_t const *to; sip_subject_t const *subject; GString *message; char *url; assert(sip); from = sip->sip_from; to = sip->sip_to; subject = sip->sip_subject; assert(from && to); if (sip->sip_payload) message=g_string_new_len(sip->sip_payload->pl_data, sip->sip_payload->pl_len); else message=NULL; url = url_as_string(self->priv->home, to->a_url);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -