Changeset 2156 for pjproject/trunk/pjsip-apps/src/python/_pjsua.c
- Timestamp:
- Jul 18, 2008 11:00:56 PM (16 years ago)
- File:
-
- 1 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
Note: See TracChangeset
for help on using the changeset viewer.