📄 nua_glib.c
字号:
return; case nua_i_state: sof_i_state(status, phrase, nua, self, nh, op, sip, tags); return; case nua_i_terminated: sof_i_terminated(status, phrase, nua, self, nh, op, sip, tags); return; case nua_r_bye: sof_r_bye(status, phrase, nua, self, nh, op, sip, tags); return; case nua_i_bye: sof_i_bye(nua, self, nh, op, sip, tags); return; case nua_r_message: sof_r_message(status, phrase, nua, self, nh, op, sip, tags); return; case nua_i_message: sof_i_message(nua, self, nh, op, sip, tags); return; case nua_r_info: sof_r_info(status, phrase, nua, self, nh, op, sip, tags); return; case nua_i_info: sof_i_info(nua, self, nh, op, sip, tags); return; case nua_r_refer: sof_r_refer(status, phrase, nua, self, nh, op, sip, tags); return; case nua_i_refer: sof_i_refer(nua, self, nh, op, sip, tags); return; case nua_r_subscribe: sof_r_subscribe(status, phrase, nua, self, nh, op, sip, tags); return; case nua_r_unsubscribe: sof_r_unsubscribe(status, phrase, nua, self, nh, op, sip, tags); return; case nua_r_publish: sof_r_publish(status, phrase, nua, self, nh, op, sip, tags); return; case nua_r_notify: sof_r_notify(status, phrase, nua, self, nh, op, sip, tags); return; case nua_i_notify: sof_i_notify(nua, self, nh, op, sip, tags); return; case nua_i_cancel: sof_i_cancel(nua, self, nh, op, sip, tags); return; case nua_i_error: sof_i_error(nua, self, nh, op, status, phrase, tags); return; default: break; } if (status > 100) g_warning("%s: unknown event %d: %03d %s\n", self->priv->name, event, status, phrase); else g_warning("%s: unknown event %d\n", self->priv->name, event); tl_print(stderr, "", tags);}/* ====================================================================== */static inlinevoid oper_assign(NuaGlibOp *op, sip_method_t method, char const *name);static void nua_glib_op_destroy(NuaGlib *self, NuaGlibOp *op);static NuaGlibOp *nua_glib_op_create(NuaGlib *self, sip_method_t method, char const *name, const char *address, tag_type_t tag, tag_value_t value, ...){ NuaGlibOp *op, *old; ta_list ta; enter; for (old = self->priv->operations; old; old = old->op_next) if (!old->op_persistent) break; if (address) { int have_url = 1; sip_to_t *to; to = sip_to_make(self->priv->home, address); if (to == NULL) { /*TODO, error returns*/ g_warning("%s: %s: invalid address: %s\n", self->priv->name, name, address); return NULL; } /* Try to make sense out of the URL */ if (url_sanitize(to->a_url) < 0) { /*TODO, error returns*/ g_warning("%s: %s: invalid address\n", self->priv->name, name); return NULL; } if (!(op = su_zalloc(self->priv->home, sizeof(*op)))) { /*TODO, error returns*/ g_warning("%s: %s: cannot create handle\n", self->priv->name, name); return NULL; } op->op_parent = self; op->op_next = self->priv->operations; op->op_prev_state = -1; self->priv->operations = op; if (method == sip_method_register) have_url = 0; ta_start(ta, tag, value); op->op_handle = nua_handle(self->priv->nua, op, TAG_IF(have_url, NUTAG_URL(to->a_url)), SIPTAG_TO(to), ta_tags(ta)); ta_end(ta); op->op_ident = sip_header_as_string(self->priv->home, (sip_header_t *)to); oper_assign(op, method, name); if (!op->op_persistent) { NuaGlibOp *old_next; for (; old; old = old_next) { /* Clean old handles */ old_next = old->op_next; if (!old->op_persistent && !old->op_callstate) nua_glib_op_destroy(self, old); } } su_free(self->priv->home, to); } else if (method || name) oper_assign(op = old, method, name); else return old; if (!op) { if (address) /*TODO, error returns*/ g_warning("%s: %s: invalid destination\n", self->priv->name, name); else /*TODO, error returns*/ g_warning("%s: %s: no destination\n", self->priv->name, name); return NULL; } return op;}static NuaGlibOp *nua_glib_op_create2(NuaGlib *self, sip_method_t method, char const *name, nua_handle_t *nh, sip_from_t const *from){ NuaGlibOp *op; enter; if ((op = su_zalloc(self->priv->home, sizeof(*op)))) { op->op_parent = self; op->op_next = self->priv->operations; self->priv->operations = op; oper_assign(op, method, name); nua_handle_bind(op->op_handle = nh, op); op->op_ident = sip_header_as_string(self->priv->home, (sip_header_t*)from); } else { printf("%s: cannot create operation object for %s\n", self->priv->name, name); } return op;}/** Delete operation and attached handles and identities */static void nua_glib_op_destroy(NuaGlib *self, NuaGlibOp *op){ NuaGlibOp **prev; if (!op) return; g_assert(op->data == NULL); /* Remove from queue */ for (prev = &self->priv->operations; *prev && *prev != op; prev = &(*prev)->op_next) ; if (*prev) *prev = op->op_next, op->op_next = NULL; if (op->op_handle) nua_handle_destroy(op->op_handle), op->op_handle = NULL; su_free(self->priv->home, op);}/* ====================================================================== */static void oper_assign(NuaGlibOp *op, sip_method_t method, char const *name){ if (!op) return; op->op_method = method, op->op_method_name = name; op->op_persistent = method == sip_method_subscribe || method == sip_method_register || method == sip_method_publish;}#if 0/** Find call operation */static NuaGlibOp *oper_find_call(NuaGlib *self){ NuaGlibOp *op; for (op = self->priv->operations; op; op = op->op_next) if (op->op_callstate) break; return op;}/** Find call operation */static NuaGlibOp *oper_find_call_in_progress(NuaGlib *self){ NuaGlibOp *op; for (op = self->priv->operations; op; op = op->op_next) if (op->op_callstate & opc_sent) /* opc_sent bit is on? */ break; return op;}static NuaGlibOp *oper_find_call_embryonic(NuaGlib *self){ NuaGlibOp *op; for (op = self->priv->operations; op; op = op->op_next) if (op->op_callstate == 0 && op->op_method == sip_method_invite) break; return op;} /** Find unanswered call */static NuaGlibOp *oper_find_unanswered(NuaGlib *self){ NuaGlibOp *op; for (op = self->priv->operations; op; op = op->op_next) if (op->op_callstate == opc_recv) break; return op;}/** Find operation by method */NuaGlibOp *oper_find_by_method(NuaGlib *self, sip_method_t method){ NuaGlibOp *op; for (op = self->priv->operations; op; op = op->op_next) if (op->op_method == method && op->op_persistent) break; return op;}/** Find register operation */NuaGlibOp *oper_find_register(NuaGlib *self){ NuaGlibOp *op; for (op = self->priv->operations; op; op = op->op_next) if (op->op_method == sip_method_register && op->op_persistent) break; return op;}#endif /** Set operation to be authenticated */static void oper_set_auth (NuaGlib *self, NuaGlibOp *op, sip_t const *sip, tagi_t *tags){ sip_www_authenticate_t const *wa = sip->sip_www_authenticate; sip_proxy_authenticate_t const *pa = sip->sip_proxy_authenticate; enter; tl_gets(tags, SIPTAG_WWW_AUTHENTICATE_REF(wa), SIPTAG_PROXY_AUTHENTICATE_REF(pa), TAG_NULL()); printf("%s: %s was unauthorized\n", self->priv->name, op->op_method_name); if (wa) sl_header_print(stdout, "Server auth: %s\n", (sip_header_t *)wa); if (pa) sl_header_print(stdout, "Proxy auth: %s\n", (sip_header_t *)pa); if (op->op_tried_auth) { g_message("Failed auth for %s by %s", op->op_method_name, self->priv->name); op->op_tried_auth =0; op->op_auth_failed =1; return; } nua_authenticate(op->op_handle, NUTAG_AUTH(self->priv->authinfo), TAG_END()); op->op_tried_auth =1;}/** * nua_glib_op_owner: * * get the owning NuaGlib for a given NuaGlibOp */NuaGlib* nua_glib_op_owner(NuaGlibOp *op){ return op->op_parent;}sip_method_tnua_glib_op_method_type(NuaGlibOp *op){ return op->op_method;}/** * nua_glib_op_set_data: * @op: op to attach data to * @data: data to attach * * Attach an applciation specific blob of data to a NuaGlibOp * The application is in charge of deleting the data when it * removes any internal references to the @op. When it has done * so, it should call this function with @data set to NULL * Failing to do so will cause an assertion. */voidnua_glib_op_set_data(NuaGlibOp *op, gpointer data){ op->data = data;}/** * nua_glib_op_get_data: * @op: op to get data from * * Get an application specific blob of data from a NuaGlibOp * Returns: attached data */gpointernua_glib_op_get_data(NuaGlibOp *op){ return op->data ;}/** * nua_glib_op_get_identity: * @op: op to get data from * * Get the identity of an operation * This is the contents of To: when initiating, From: when receiving. * Returns: the identity */const gchar *nua_glib_op_get_identity(NuaGlibOp *op){ return op->op_ident;}static void sof_i_error(nua_t *nua, NuaGlib *self, nua_handle_t *nh, NuaGlibOp *op, int status, char const *phrase, tagi_t tags[]){ g_signal_emit(self, signals[ERROR], status, phrase);}#if 0shouldnt be necessary in glib bindings/** * List active calls * */GList*nua_glib_list(NuaGlib *self){ NuaGlibOp *op; for (op = self->priv->operations; op; op = op->op_next) { if (op->op_ident) { op->op_method, op->op_method_name, op->op_ident); } }}#endif/** * nua_glib_invite: * @destination sip address to invite * @local_sdp an SDP blob describing local capabilites * * Issue an INVITE * Return value: operation descriptor for this operation, NULL if failure * */NuaGlibOp *nua_glib_invite(NuaGlib *self, const char *destination, const char *local_sdp){ NuaGlibOp *op; op = nua_glib_op_create(self, SIP_METHOD_INVITE, destination, TAG_END()); /* SDP O/A note: * - pass media information to nua_invite() in the * SOATAG_USER_SDP_STR() tag * - see also: sof_i_state() and nua_glib_answer() */ if (op) { nua_invite(op->op_handle, SOATAG_USER_SDP_STR(local_sdp),#if 0 SIPTAG_SUBJECT_STR("Call!"), SIPTAG_CALL_INFO_STR("<http://127.1/my_face.jpg>" ";purpose=icon"), NUTAG_MEDIA_ENABLE(0),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -