Changeset 2156 for pjproject/trunk
- Timestamp:
- Jul 18, 2008 11:00:56 PM (16 years ago)
- Location:
- pjproject/trunk/pjsip-apps/src/python
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/python/_pjsua.c
r2119 r2156 341 341 } 342 342 343 /* 344 * cb_on_incoming_subscribe 345 */ 346 static void cb_on_incoming_subscribe( pjsua_acc_id acc_id, 347 pjsua_srv_pres *srv_pres, 348 pjsua_buddy_id buddy_id, 349 const pj_str_t *from, 350 pjsip_rx_data *rdata, 351 pjsip_status_code *code, 352 pj_str_t *reason, 353 pjsua_msg_data *msg_data) 354 { 355 static char reason_buf[64]; 356 357 PJ_UNUSED_ARG(rdata); 358 PJ_UNUSED_ARG(msg_data); 359 360 if (PyCallable_Check(g_obj_callback->on_incoming_subscribe)) 361 { 362 PyObject *ret; 363 364 ENTER_PYTHON(); 365 366 ret = PyObject_CallFunctionObjArgs( 367 g_obj_callback->on_incoming_subscribe, 368 Py_BuildValue("i", acc_id), 369 Py_BuildValue("i", buddy_id), 370 PyString_FromStringAndSize(from->ptr, from->slen), 371 PyLong_FromLong((long)srv_pres), 372 NULL 373 ); 374 375 if (ret && PyTuple_Check(ret)) { 376 if (PyTuple_Size(ret) >= 1) 377 *code = (int)PyInt_AsLong(PyTuple_GetItem(ret, 0)); 378 if (PyTuple_Size(ret) >= 2) { 379 if (PyTuple_GetItem(ret, 1) != Py_None) { 380 pj_str_t tmp; 381 tmp = PyString_to_pj_str(PyTuple_GetItem(ret, 1)); 382 reason->ptr = reason_buf; 383 pj_strncpy(reason, &tmp, sizeof(reason_buf)); 384 } else { 385 } 386 } 387 388 } else if (ret) { 389 Py_XDECREF(ret); 390 } 391 392 LEAVE_PYTHON(); 393 } 394 } 343 395 344 396 /* … … 372 424 pjsip_rx_data *rdata, pjsua_acc_id acc_id) 373 425 { 426 PJ_UNUSED_ARG(rdata); 427 374 428 if (PyCallable_Check(g_obj_callback->on_pager)) 375 429 { … … 912 966 cfg_ua.cb.on_call_replaced = &cb_on_call_replaced; 913 967 cfg_ua.cb.on_reg_state = &cb_on_reg_state; 968 cfg_ua.cb.on_incoming_subscribe = &cb_on_incoming_subscribe; 914 969 cfg_ua.cb.on_buddy_state = &cb_on_buddy_state; 915 970 cfg_ua.cb.on_pager2 = &cb_on_pager; … … 1879 1934 } 1880 1935 1936 1937 /* 1938 * py_pjsua_acc_pres_notify 1939 */ 1940 static PyObject *py_pjsua_acc_pres_notify 1941 (PyObject *pSelf, PyObject *pArgs) 1942 { 1943 static char reason_buf[64]; 1944 int acc_id, state; 1945 PyObject *arg_pres, *arg_msg_data; 1946 void *srv_pres; 1947 pjsua_msg_data msg_data; 1948 const char *arg_reason; 1949 pj_str_t reason; 1950 pj_bool_t with_body; 1951 pj_pool_t *pool = NULL; 1952 int status; 1953 1954 PJ_UNUSED_ARG(pSelf); 1955 1956 if (!PyArg_ParseTuple(pArgs, "iOisO", &acc_id, &arg_pres, 1957 &state, &arg_reason, &arg_msg_data)) 1958 { 1959 return NULL; 1960 } 1961 1962 srv_pres = (void*) PyLong_AsLong(arg_pres); 1963 pjsua_msg_data_init(&msg_data); 1964 with_body = (state != PJSIP_EVSUB_STATE_TERMINATED); 1965 1966 if (arg_reason) { 1967 strncpy(reason_buf, arg_reason, sizeof(reason_buf)); 1968 reason.ptr = reason_buf; 1969 reason.slen = strlen(arg_reason); 1970 } else { 1971 reason = pj_str(""); 1972 } 1973 1974 if (arg_msg_data && arg_msg_data != Py_None) { 1975 PyObj_pjsua_msg_data *omd = (PyObj_pjsua_msg_data *)arg_msg_data; 1976 msg_data.content_type.ptr = PyString_AsString(omd->content_type); 1977 msg_data.content_type.slen = PyString_Size(omd->content_type); 1978 msg_data.msg_body.ptr = PyString_AsString(omd->msg_body); 1979 msg_data.msg_body.slen = PyString_Size(omd->msg_body); 1980 pool = pjsua_pool_create("pytmp", POOL_SIZE, POOL_SIZE); 1981 translate_hdr(pool, &msg_data.hdr_list, omd->hdr_list); 1982 } else if (arg_msg_data) { 1983 Py_XDECREF(arg_msg_data); 1984 } 1985 1986 status = pjsua_pres_notify(acc_id, (pjsua_srv_pres*)srv_pres, 1987 (pjsip_evsub_state)state, NULL, 1988 &reason, with_body, &msg_data); 1989 1990 if (pool) { 1991 pj_pool_release(pool); 1992 } 1993 1994 return Py_BuildValue("i", status); 1995 } 1881 1996 1882 1997 static char pjsua_acc_config_default_doc[] = … … 5543 5658 }, 5544 5659 { 5660 "acc_pres_notify", py_pjsua_acc_pres_notify, METH_VARARGS, 5661 "Accept or reject subscription request" 5662 }, 5663 { 5545 5664 "enum_accs", py_pjsua_enum_accs, METH_VARARGS, 5546 5665 pjsua_enum_accs_doc -
pjproject/trunk/pjsip-apps/src/python/_pjsua.h
r2119 r2156 508 508 PyObject * on_call_replaced; 509 509 PyObject * on_reg_state; 510 PyObject * on_incoming_subscribe; 510 511 PyObject * on_buddy_state; 511 512 PyObject * on_pager; … … 530 531 Py_XDECREF(self->on_call_replaced); 531 532 Py_XDECREF(self->on_reg_state); 533 Py_XDECREF(self->on_incoming_subscribe); 532 534 Py_XDECREF(self->on_buddy_state); 533 535 Py_XDECREF(self->on_pager); … … 617 619 return NULL; 618 620 } 621 Py_INCREF(Py_None); 622 self->on_incoming_subscribe = Py_None; 619 623 Py_INCREF(Py_None); 620 624 self->on_buddy_state = Py_None; … … 718 722 "Notify application when registration status has changed. Application " 719 723 "may then query the account info to get the registration details." 724 }, 725 { 726 "on_incoming_subscribe", T_OBJECT_EX, 727 offsetof(PyObj_pjsua_callback, on_incoming_subscribe), 0, 728 "Notification when incoming SUBSCRIBE request is received." 720 729 }, 721 730 { … … 2769 2778 int monitor_pres; 2770 2779 int activity; 2780 int sub_state; 2781 PyObject *sub_term_reason; 2771 2782 } PyObj_pjsua_buddy_info; 2772 2783 … … 2782 2793 Py_XDECREF(self->contact); 2783 2794 Py_XDECREF(self->status_text); 2795 Py_XDECREF(self->sub_term_reason); 2784 2796 2785 2797 self->ob_type->tp_free((PyObject*)self); … … 2801 2813 obj->monitor_pres = info->monitor_pres; 2802 2814 obj->activity = info->rpid.activity; 2815 obj->sub_state = info->sub_state; 2816 Py_XDECREF(obj->sub_term_reason); 2817 obj->sub_term_reason = PyString_FromStringAndSize(info->sub_term_reason.ptr, 2818 info->sub_term_reason.slen); 2803 2819 } 2804 2820 … … 2824 2840 Py_DECREF(self); 2825 2841 return NULL; 2826 } 2842 } 2827 2843 self->contact = PyString_FromString(""); 2828 2844 if (self->contact == NULL) { … … 2835 2851 return NULL; 2836 2852 } 2837 2853 self->sub_term_reason = PyString_FromString(""); 2838 2854 } 2839 2855 return (PyObject *)self; … … 2882 2898 offsetof(PyObj_pjsua_buddy_info, activity), 0, 2883 2899 "Activity type. " 2900 }, 2901 { 2902 "sub_state", T_INT, 2903 offsetof(PyObj_pjsua_buddy_info, sub_state), 0, 2904 "Subscription state." 2905 }, 2906 { 2907 "sub_term_reason", T_INT, 2908 offsetof(PyObj_pjsua_buddy_info, sub_term_reason), 0, 2909 "Subscription termination reason." 2884 2910 }, 2885 2911 -
pjproject/trunk/pjsip-apps/src/python/pjsua.py
r2122 r2156 148 148 Member documentation: 149 149 150 N ONE-- media is not available.150 NULL -- media is not available. 151 151 ACTIVE -- media is active. 152 152 LOCAL_HOLD -- media is put on-hold by local party. … … 154 154 ERROR -- media error (e.g. ICE negotiation failure). 155 155 """ 156 N ONE= 0156 NULL = 0 157 157 ACTIVE = 1 158 158 LOCAL_HOLD = 2 … … 166 166 Member documentation: 167 167 168 N ONE-- media is not active168 NULL -- media is not active 169 169 ENCODING -- media is active in transmit/encoding direction only. 170 170 DECODING -- media is active in receive/decoding direction only 171 171 ENCODING_DECODING -- media is active in both directions. 172 172 """ 173 N ONE= 0173 NULL = 0 174 174 ENCODING = 1 175 175 DECODING = 2 … … 189 189 AWAY = 1 190 190 BUSY = 2 191 192 193 class SubscriptionState: 194 """Presence subscription state constants. 195 196 """ 197 NULL = 0 198 SENT = 1 199 ACCEPTED = 2 200 PENDING = 3 201 ACTIVE = 4 202 TERMINATED = 5 203 UNKNOWN = 6 204 191 205 192 206 class TURNConnType: … … 862 876 reject the call with default status code. 863 877 864 Keyword arguments:865 call -- the new incoming call878 Keyword arguments: 879 call -- the new incoming call 866 880 """ 867 881 call.hangup() 882 883 def on_incoming_subscribe(self, buddy, from_uri, pres_obj): 884 """Notification when incoming SUBSCRIBE request is received. 885 886 Application may use this callback to authorize the incoming 887 subscribe request (e.g. ask user permission if the request 888 should be granted) 889 890 Keyword arguments: 891 buddy -- The buddy object, if buddy is found. Otherwise 892 the value is None. 893 from_uri -- The URI string of the sender. 894 pres_obj -- Opaque presence subscription object, which is 895 needed by Account.pres_notify() 896 897 Return: 898 Tuple (code, reason), where: 899 code: The status code. If code is >= 300, the 900 request is rejected. If code is 200, the 901 request is accepted and NOTIFY will be sent 902 automatically. If code is 202, application 903 must accept or reject the request later with 904 Account.press_notify(). 905 reason: Optional reason phrase, or None to use the 906 default reasoh phrase for the status code. 907 """ 908 return (200, None) 868 909 869 910 def on_pager(self, from_uri, contact, mime_type, body): … … 952 993 id -- the pjsua account ID. 953 994 """ 954 _cb = AccountCallback(self)995 self._cb = AccountCallback(self) 955 996 self._id = id 956 997 self._lib = lib … … 1102 1143 return Buddy(self._lib, buddy_id, self) 1103 1144 1145 def pres_notify(self, pres_obj, state, reason="", hdr_list=None): 1146 """Send NOTIFY to inform account presence status or to terminate 1147 server side presence subscription. 1148 1149 Keyword arguments: 1150 pres_obj -- The subscription object from on_incoming_subscribe() 1151 callback 1152 state -- Subscription state, from SubscriptionState 1153 reason -- Optional reason phrase. 1154 hdr_list -- Optional header list. 1155 """ 1156 _pjsua.acc_pres_notify(self._id, pres_obj, state, reason, 1157 Lib._create_msg_data(hdr_list)) 1104 1158 1105 1159 class CallCallback: … … 1276 1330 last_code = 0 1277 1331 last_reason = "" 1278 media_state = MediaState.N ONE1279 media_dir = MediaDir.N ONE1332 media_state = MediaState.NULL 1333 media_dir = MediaDir.NULL 1280 1334 conf_slot = -1 1281 1335 call_time = 0 … … 1530 1584 subscribed -- specify whether buddy's presence status is currently 1531 1585 being subscribed. 1586 sub_state -- SubscriptionState 1587 sub_term_reason -- The termination reason string of the last presence 1588 subscription to this buddy, if any. 1532 1589 """ 1533 1590 uri = "" … … 1537 1594 activity = PresenceActivity.UNKNOWN 1538 1595 subscribed = False 1596 sub_state = SubscriptionState.NULL 1597 sub_term_reason = "" 1539 1598 1540 1599 def __init__(self, pjsua_bi=None): … … 1549 1608 self.activity = inf.activity 1550 1609 self.subscribed = inf.monitor_pres 1610 self.sub_state = inf.sub_state 1611 self.sub_term_reason = inf.sub_term_reason 1551 1612 1552 1613 … … 1867 1928 py_ua_cfg.cb.on_call_replaced = _cb_on_call_replaced 1868 1929 py_ua_cfg.cb.on_reg_state = _cb_on_reg_state 1930 py_ua_cfg.cb.on_incoming_subscribe = _cb_on_incoming_subscribe 1869 1931 py_ua_cfg.cb.on_buddy_state = _cb_on_buddy_state 1870 1932 py_ua_cfg.cb.on_pager = _cb_on_pager … … 2267 2329 2268 2330 def _lookup_buddy(self, buddy_id, uri=None): 2269 print "lookup_buddy, id=", buddy_id2270 2331 buddy = self.buddy.has_key(buddy_id) and self.buddy[buddy_id] or None 2271 2332 if uri and not buddy: 2272 2333 sip_uri = SIPUri(uri) 2273 print "lookup_buddy, uri=", sip_uri.user, sip_uri.host2274 2334 buddy = self.buddy_by_uri.has_key( (sip_uri.user, sip_uri.host) ) \ 2275 2335 and self.buddy_by_uri[(sip_uri.user, sip_uri.host)] or \ … … 2289 2349 if acc: 2290 2350 acc._cb.on_reg_state() 2351 2352 def _cb_on_incoming_subscribe(self, acc_id, buddy_id, from_uri, pres_obj): 2353 acc = self._lookup_account(acc_id) 2354 if acc: 2355 buddy = self._lookup_buddy(buddy_id) 2356 return acc._cb.on_incoming_subscribe(buddy, from_uri, pres_obj) 2357 else: 2358 return (404, None) 2291 2359 2292 2360 def _cb_on_incoming_call(self, acc_id, call_id, rdata): … … 2425 2493 _lib._cb_on_reg_state(acc_id) 2426 2494 2495 def _cb_on_incoming_subscribe(acc_id, buddy_id, from_uri, pres): 2496 return _lib._cb_on_incoming_subscribe(acc_id, buddy_id, from_uri, pres) 2497 2427 2498 def _cb_on_buddy_state(buddy_id): 2428 2499 _lib._cb_on_buddy_state(buddy_id)
Note: See TracChangeset
for help on using the changeset viewer.