Changeset 916 for pjproject/trunk
- Timestamp:
- Jan 29, 2007 6:36:38 PM (18 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/py_pjsua/pjsua_app.py
r851 r916 6 6 # Configurations 7 7 # 8 APP= "pjsua_app.py"8 THIS_FILE = "pjsua_app.py" 9 9 C_QUIT = 0 10 C_LOG_LEVEL = 3 11 10 C_LOG_LEVEL = 4 11 12 # STUN config. 13 # Set C_STUN_SRV to the address of the STUN server to enable STUN 14 # 15 C_STUN_SRV = "" 12 16 C_SIP_PORT = 5060 13 C_STUN_SRV = ""14 17 C_STUN_PORT = 3478 15 18 16 C_ACC_REGISTRAR = "" 17 #C_ACC_REGISTRAR = "sip:iptel.org" 18 C_ACC_ID = "sip:bulukucing1@iptel.org" 19 C_ACC_REALM = "iptel.org" 20 C_ACC_USERNAME = "bulukucing1" 21 C_ACC_PASSWORD = "netura" 22 23 # Display PJ error and exit 19 20 # Globals 21 # 22 g_acc_id = py_pjsua.PJSUA_INVALID_ID 23 g_current_call = py_pjsua.PJSUA_INVALID_ID 24 25 26 # Utility to get call info 27 # 28 def call_name(call_id): 29 ci = py_pjsua.call_get_info(call_id) 30 return "[Call " + `call_id` + " " + ci.remote_info + "]" 31 32 # Handler when invite state has changed. 33 # 34 def on_call_state(call_id, e): 35 global g_current_call 36 ci = py_pjsua.call_get_info(call_id) 37 write_log(3, call_name(call_id) + " state = " + `ci.state_text`) 38 if ci.state == 6: 39 g_current_call = py_pjsua.PJSUA_INVALID_ID 40 41 # Handler for incoming call 42 # 43 def on_incoming_call(acc_id, call_id, rdata): 44 global g_current_call 45 if g_current_call != py_pjsua.PJSUA_INVALID_ID: 46 py_pjsua.call_answer(call_id, 486, "", None) 47 return 48 g_current_call = call_id 49 ci = py_pjsua.call_get_info(call_id) 50 write_log(3, "Incoming call: " + call_name(call_id)) 51 py_pjsua.call_answer(call_id, 200, "", None) 52 53 54 # Handler when media state has changed (e.g. established or terminated) 55 # 56 def on_call_media_state(call_id): 57 ci = py_pjsua.call_get_info(call_id) 58 if ci.media_status == 1: 59 py_pjsua.conf_connect(ci.conf_slot, 0) 60 py_pjsua.conf_connect(0, ci.conf_slot) 61 write_log(3, call_name(call_id) + ": media is active") 62 else: 63 write_log(3, call_name(call_id) + ": media is inactive") 64 65 66 # Handler when account registration state has changed 67 # 68 def on_reg_state(acc_id): 69 acc_info = py_pjsua.acc_get_info(acc_id) 70 if acc_info.status != 0 and acc_info.status != 200: 71 write_log(3, "Account (un)registration failed: rc=" + `acc_info.status` + " " + acc_info.status_text) 72 else: 73 write_log(3, "Account successfully (un)registered") 74 75 76 # Utility: display PJ error and exit 77 # 24 78 def err_exit(title, rc): 25 py_pjsua.perror( APP, title, rc)79 py_pjsua.perror(THIS_FILE, title, rc) 26 80 exit(1) 27 81 28 # Logging callback 82 83 # Logging function (also callback, called by pjsua-lib) 84 # 29 85 def log_cb(level, str, len): 30 if level >= C_LOG_LEVEL:86 if level <= C_LOG_LEVEL: 31 87 print str, 32 88 33 # Initialize pjsua 89 def write_log(level, str): 90 log_cb(level, str + "\n", 0) 91 92 93 # 94 # Initialize pjsua. 95 # 34 96 def app_init(): 35 # Create pjsua before anything else 36 status = py_pjsua.create() 37 if status != 0: 38 err_exit("pjsua create() error", status) 39 40 # Create and initialize logging config 41 log_cfg = py_pjsua.logging_config_default() 42 log_cfg.level = C_LOG_LEVEL 43 log_cfg.cb = log_cb 44 45 # Create and initialize pjsua config 46 ua_cfg = py_pjsua.config_default() 47 ua_cfg.thread_cnt = 0 48 ua_cfg.user_agent = "PJSUA/Python 0.1" 49 50 # Create and initialize media config 51 med_cfg = py_pjsua.media_config_default() 52 med_cfg.ec_tail_len = 0 53 54 # 55 # Initialize pjsua!! 56 # 57 status = py_pjsua.init(ua_cfg, log_cfg, med_cfg) 58 if status != 0: 59 err_exit("pjsua init() error", status) 60 61 # Configure STUN config 62 stun_cfg = py_pjsua.stun_config_default() 63 stun_cfg.stun_srv1 = C_STUN_SRV 64 stun_cfg.stun_srv2 = C_STUN_SRV 65 stun_cfg.stun_port1 = C_STUN_PORT 66 stun_cfg.stun_port2 = C_STUN_PORT 67 68 # Configure UDP transport config 69 transport_cfg = py_pjsua.transport_config_default() 70 transport_cfg.port = C_SIP_PORT 71 transport_cfg.stun_config = stun_cfg 72 if C_STUN_SRV != "": 73 transport_cfg.use_stun = 1 74 75 # Create UDP transport 76 # Note: transport_id is supposed to be integer 77 status, transport_id = py_pjsua.transport_create(1, transport_cfg) 78 if status != 0: 79 py_pjsua.destroy() 80 err_exit("Error creating UDP transport", status) 81 82 83 # Configure account configuration 84 acc_cfg = py_pjsua.acc_config_default() 85 acc_cfg.id = C_ACC_ID 86 acc_cfg.reg_uri = C_ACC_REGISTRAR 87 acc_cfg.cred_count = 1 88 acc_cfg.cred_info[0].realm = C_ACC_REALM 89 acc_cfg.cred_info[0].scheme = "digest" 90 acc_cfg.cred_info[0].username = C_ACC_USERNAME 91 acc_cfg.cred_info[0].data_type = 0 92 acc_cfg.cred_info[0].data = C_ACC_PASSWORD 93 94 # Add new SIP account 95 # Note: acc_id is supposed to be integer 96 status, acc_id = py_pjsua.acc_add(acc_cfg, 1) 97 if status != 0: 98 py_pjsua.destroy() 99 err_exit("Error adding SIP account", status) 100 101 102 # Worker thread function 97 global g_acc_id 98 99 # Create pjsua before anything else 100 status = py_pjsua.create() 101 if status != 0: 102 err_exit("pjsua create() error", status) 103 104 # Create and initialize logging config 105 log_cfg = py_pjsua.logging_config_default() 106 log_cfg.level = C_LOG_LEVEL 107 log_cfg.cb = log_cb 108 109 # Create and initialize pjsua config 110 # Note: for this Python module, thread_cnt must be 0 since Python 111 # doesn't like to be called from alien thread (pjsua's thread 112 # in this case) 113 ua_cfg = py_pjsua.config_default() 114 ua_cfg.thread_cnt = 0 115 ua_cfg.user_agent = "PJSUA/Python 0.1" 116 ua_cfg.cb.on_incoming_call = on_incoming_call 117 ua_cfg.cb.on_call_media_state = on_call_media_state 118 ua_cfg.cb.on_reg_state = on_reg_state 119 ua_cfg.cb.on_call_state = on_call_state 120 121 # Create and initialize media config 122 med_cfg = py_pjsua.media_config_default() 123 med_cfg.ec_tail_len = 0 124 125 # 126 # Initialize pjsua!! 127 # 128 status = py_pjsua.init(ua_cfg, log_cfg, med_cfg) 129 if status != 0: 130 err_exit("pjsua init() error", status) 131 132 # Configure STUN config 133 stun_cfg = py_pjsua.stun_config_default() 134 stun_cfg.stun_srv1 = C_STUN_SRV 135 stun_cfg.stun_srv2 = C_STUN_SRV 136 stun_cfg.stun_port1 = C_STUN_PORT 137 stun_cfg.stun_port2 = C_STUN_PORT 138 139 # Configure UDP transport config 140 transport_cfg = py_pjsua.transport_config_default() 141 transport_cfg.port = C_SIP_PORT 142 transport_cfg.stun_config = stun_cfg 143 if C_STUN_SRV != "": 144 transport_cfg.use_stun = 1 145 146 # Create UDP transport 147 status, transport_id = py_pjsua.transport_create(1, transport_cfg) 148 if status != 0: 149 py_pjsua.destroy() 150 err_exit("Error creating UDP transport", status) 151 152 # Create initial default account 153 status, acc_id = py_pjsua.acc_add_local(transport_id, 1) 154 if status != 0: 155 py_pjsua.destroy() 156 err_exit("Error creating account", status) 157 158 g_acc_id = acc_id 159 160 # Add SIP account interractively 161 # 162 def add_account(): 163 global g_acc_id 164 165 acc_domain = "" 166 acc_username = "" 167 acc_passwd ="" 168 confirm = "" 169 170 # Input account configs 171 print "Your SIP domain (e.g. myprovider.com): ", 172 acc_domain = sys.stdin.readline() 173 if acc_domain == "\n": 174 return 175 acc_domain = acc_domain.replace("\n", "") 176 177 print "Your username (e.g. alice): ", 178 acc_username = sys.stdin.readline() 179 if acc_username == "\n": 180 return 181 acc_username = acc_username.replace("\n", "") 182 183 print "Your password (e.g. secret): ", 184 acc_passwd = sys.stdin.readline() 185 if acc_passwd == "\n": 186 return 187 acc_passwd = acc_passwd.replace("\n", "") 188 189 # Configure account configuration 190 acc_cfg = py_pjsua.acc_config_default() 191 acc_cfg.id = "sip:" + acc_username + "@" + acc_domain 192 acc_cfg.reg_uri = "sip:" + acc_domain 193 acc_cfg.cred_count = 1 194 acc_cfg.cred_info[0].realm = acc_domain 195 acc_cfg.cred_info[0].scheme = "digest" 196 acc_cfg.cred_info[0].username = acc_username 197 acc_cfg.cred_info[0].data_type = 0 198 acc_cfg.cred_info[0].data = acc_passwd 199 200 # Add new SIP account 201 status, acc_id = py_pjsua.acc_add(acc_cfg, 1) 202 if status != 0: 203 py_pjsua.perror(THIS_FILE, "Error adding SIP account", status) 204 else: 205 g_acc_id = acc_id 206 write_log(3, "Account " + acc_cfg.id + " added") 207 208 209 # 210 # Worker thread function. 211 # Python doesn't like it when it's called from an alien thread 212 # (pjsua's worker thread, in this case), so for Python we must 213 # disable worker thread in pjsua and poll pjsua from Python instead. 214 # 103 215 def worker_thread_main(arg): 104 thread_desc = 0; 105 status = py_pjsua.thread_register("worker thread", thread_desc) 106 if status != 0: 107 py_pjsua.perror(APP, "Error registering thread", status) 108 else: 109 while C_QUIT == 0: 110 py_pjsua.handle_events(50) 216 global C_QUIT 217 thread_desc = 0; 218 status = py_pjsua.thread_register("python worker", thread_desc) 219 if status != 0: 220 py_pjsua.perror(THIS_FILE, "Error registering thread", status) 221 else: 222 while C_QUIT == 0: 223 py_pjsua.handle_events(50) 224 print "Worker thread quitting.." 225 C_QUIT = 2 226 111 227 112 228 # Start pjsua 229 # 113 230 def app_start(): 114 115 116 117 118 119 120 121 122 231 # Done with initialization, start pjsua!! 232 # 233 status = py_pjsua.start() 234 if status != 0: 235 py_pjsua.destroy() 236 err_exit("Error starting pjsua!", status) 237 238 # Start worker thread 239 thr = thread.start_new(worker_thread_main, (0,)) 123 240 124 241 print "PJSUA Started!!" 125 242 126 243 127 244 # Print application menu 245 # 128 246 def print_menu(): 129 print "Menu:" 130 print " q Quit application" 131 print " s Add buddy" 132 print "Choice: ", 133 134 247 print """ 248 Menu: 249 q Quit application 250 +a Add account 251 +b Add buddy 252 m Make call 253 h Hangup current call (if any) 254 i Send instant message 255 """ 256 print "Choice: ", 257 135 258 # Menu 259 # 136 260 def app_menu(): 137 quit = 0 138 while quit == 0: 139 print_menu() 140 choice = sys.stdin.readline() 141 if choice[0] == "q": 142 quit = 1 143 elif choice[0] == "s": 144 bc = py_pjsua.Buddy_Config() 145 print "Buddy URI: ", 146 bc.uri = sys.stdin.readline() 147 if bc.uri == "": 148 continue 261 global g_acc_id 262 global g_current_call 263 264 quit = 0 265 while quit == 0: 266 print_menu() 267 choice = sys.stdin.readline() 268 269 if choice[0] == "q": 270 quit = 1 271 272 elif choice[0] == "i": 273 # Sending IM 274 print "Send IM to SIP URL: ", 275 url = sys.stdin.readline() 276 if url == "\n": 277 continue 278 279 # Send typing indication 280 py_pjsua.im_typing(g_acc_id, url, 1, None) 281 282 print "The content: ", 283 message = sys.stdin.readline() 284 if message == "\n": 285 py_pjsua.im_typing(g_acc_id, url, 0, None) 286 continue 287 288 # Send the IM! 289 py_pjsua.im_send(g_acc_id, url, "", message, None, 0) 290 291 elif choice[0] == "m": 292 # Make call 293 print "Using account ", g_acc_id 294 print "Make call to SIP URL: ", 295 url = sys.stdin.readline() 296 url = url.replace("\n", "") 297 if url == "": 298 continue 299 300 # Initiate the call! 301 status, call_id = py_pjsua.call_make_call(g_acc_id, url, 0, 0, None) 149 302 150 bc.subscribe = 1 151 status = py_pjsua.buddy_add(bc) 152 if status != 0: 153 py_pjsua.perror(APP, "Error adding buddy", status) 303 if status != 0: 304 py_pjsua.perror(THIS_FILE, "Error making call", status) 305 else: 306 g_current_call = call_id 307 308 elif choice[0] == "+" and choice[1] == "b": 309 # Add new buddy 310 bc = py_pjsua.Buddy_Config() 311 print "Buddy URL: ", 312 bc.uri = sys.stdin.readline() 313 if bc.uri == "\n": 314 continue 315 316 bc.subscribe = 1 317 status, buddy_id = py_pjsua.buddy_add(bc) 318 if status != 0: 319 py_pjsua.perror(THIS_FILE, "Error adding buddy", status) 320 321 elif choice[0] == "+" and choice[1] == "a": 322 # Add account 323 add_account() 324 325 elif choice[0] == "h": 326 if g_current_call != py_pjsua.PJSUA_INVALID_ID: 327 py_pjsua.call_hangup(g_current_call, 603, "", None) 328 else: 329 print "No current call" 154 330 155 331 … … 166 342 print "PJSUA shutting down.." 167 343 C_QUIT = 1 344 # Give the worker thread chance to quit itself 345 while C_QUIT != 2: 346 py_pjsua.handle_events(50) 347 348 print "PJSUA destroying.." 168 349 py_pjsua.destroy() 169 350 -
pjproject/trunk/pjsip-apps/src/py_pjsua/py_pjsua.c
r915 r916 27 27 static PyObject* obj_reconfigure_logging; 28 28 static PyObject* obj_logging_init; 29 static long thread_id; 29 30 30 31 /* … … 51 52 static void cb_logging_init(int level, const char *data, pj_size_t len) 52 53 { 53 54 /* Ignore if this callback is called from alien thread context, 55 * or otherwise it will crash Python. 56 */ 57 if (pj_thread_local_get(thread_id) == 0) 58 return; 59 54 60 if (PyCallable_Check(obj_logging_init)) 55 61 { … … 176 182 * The global callback object. 177 183 */ 178 static callback_Object * obj_callback;184 static callback_Object * g_obj_callback; 179 185 180 186 … … 185 191 static void cb_on_call_state(pjsua_call_id call_id, pjsip_event *e) 186 192 { 187 188 printf("on_call_state called\n"); 189 if (PyCallable_Check(obj_callback->on_call_state)) 193 if (PyCallable_Check(g_obj_callback->on_call_state)) 190 194 { 191 195 pjsip_event_Object * obj; … … 198 202 199 203 PyObject_CallFunctionObjArgs( 200 obj_callback->on_call_state,Py_BuildValue("i",call_id),obj,NULL204 g_obj_callback->on_call_state,Py_BuildValue("i",call_id),obj,NULL 201 205 ); 202 206 … … 212 216 pjsip_rx_data *rdata) 213 217 { 214 printf("on_incoming_call called\n"); 215 if (PyCallable_Check(obj_callback->on_incoming_call)) 218 if (PyCallable_Check(g_obj_callback->on_incoming_call)) 216 219 { 217 220 pjsip_rx_data_Object * obj = (pjsip_rx_data_Object *) … … 221 224 222 225 PyObject_CallFunctionObjArgs( 223 obj_callback->on_incoming_call,226 g_obj_callback->on_incoming_call, 224 227 Py_BuildValue("i",acc_id), 225 228 Py_BuildValue("i",call_id), … … 237 240 static void cb_on_call_media_state(pjsua_call_id call_id) 238 241 { 239 printf("on_call_media_state called\n"); 240 if (PyCallable_Check(obj_callback->on_call_media_state)) 241 { 242 PyObject_CallFunction(obj_callback->on_call_media_state,"i",call_id); 242 if (PyCallable_Check(g_obj_callback->on_call_media_state)) 243 { 244 PyObject_CallFunction(g_obj_callback->on_call_media_state,"i",call_id); 243 245 } 244 246 } … … 255 257 PyObject * ret; 256 258 int cd; 257 printf("on_call_transfer_request called\n"); 258 if (PyCallable_Check(obj_callback->on_call_transfer_request)) 259 if (PyCallable_Check(g_obj_callback->on_call_transfer_request)) 259 260 { 260 261 ret = PyObject_CallFunctionObjArgs( 261 obj_callback->on_call_transfer_request,262 g_obj_callback->on_call_transfer_request, 262 263 Py_BuildValue("i",call_id), 263 264 PyString_FromStringAndSize(dst->ptr, dst->slen), … … 291 292 PyObject * ret; 292 293 int cnt; 293 printf("on_call_transfer_status called\n"); 294 if (PyCallable_Check(obj_callback->on_call_transfer_status)) 294 if (PyCallable_Check(g_obj_callback->on_call_transfer_status)) 295 295 { 296 296 ret = PyObject_CallFunctionObjArgs( 297 obj_callback->on_call_transfer_status,297 g_obj_callback->on_call_transfer_status, 298 298 Py_BuildValue("i",call_id), 299 299 Py_BuildValue("i",status_code), … … 327 327 PyObject * txt; 328 328 int cd; 329 printf("on_call_replace_request called\n"); 330 if (PyCallable_Check(obj_callback->on_call_replace_request)) 329 if (PyCallable_Check(g_obj_callback->on_call_replace_request)) 331 330 { 332 331 pjsip_rx_data_Object * obj = (pjsip_rx_data_Object *) … … 336 335 337 336 ret = PyObject_CallFunctionObjArgs( 338 obj_callback->on_call_replace_request,337 g_obj_callback->on_call_replace_request, 339 338 Py_BuildValue("i",call_id), 340 339 obj, … … 364 363 pjsua_call_id new_call_id) 365 364 { 366 printf("on_call_replaced\n"); 367 if (PyCallable_Check(obj_callback->on_call_replaced)) 365 if (PyCallable_Check(g_obj_callback->on_call_replaced)) 368 366 { 369 367 PyObject_CallFunctionObjArgs( 370 obj_callback->on_call_replaced,368 g_obj_callback->on_call_replaced, 371 369 Py_BuildValue("i",old_call_id), 372 370 Py_BuildValue("i",old_call_id), … … 383 381 static void cb_on_reg_state(pjsua_acc_id acc_id) 384 382 { 385 printf("on_reg_state\n"); 386 if (PyCallable_Check(obj_callback->on_reg_state)) 387 { 388 PyObject_CallFunction(obj_callback->on_reg_state,"i",acc_id); 383 if (PyCallable_Check(g_obj_callback->on_reg_state)) 384 { 385 PyObject_CallFunction(g_obj_callback->on_reg_state,"i",acc_id); 389 386 } 390 387 } … … 397 394 static void cb_on_buddy_state(pjsua_buddy_id buddy_id) 398 395 { 399 printf("on_buddy_state called\n"); 400 if (PyCallable_Check(obj_callback->on_buddy_state)) 401 { 402 PyObject_CallFunction(obj_callback->on_buddy_state,"i",buddy_id); 396 if (PyCallable_Check(g_obj_callback->on_buddy_state)) 397 { 398 PyObject_CallFunction(g_obj_callback->on_buddy_state,"i",buddy_id); 403 399 } 404 400 } … … 412 408 const pj_str_t *mime_type, const pj_str_t *body) 413 409 { 414 printf("on_pager called\n"); 415 if (PyCallable_Check(obj_callback->on_pager)) 410 if (PyCallable_Check(g_obj_callback->on_pager)) 416 411 { 417 412 PyObject_CallFunctionObjArgs( 418 obj_callback->on_pager,Py_BuildValue("i",call_id),413 g_obj_callback->on_pager,Py_BuildValue("i",call_id), 419 414 PyString_FromStringAndSize(from->ptr, from->slen), 420 415 PyString_FromStringAndSize(to->ptr, to->slen), … … 438 433 439 434 PyObject * obj = PyType_GenericNew(user_data, NULL, NULL); 440 printf("on_pager_status called\n"); 441 if (PyCallable_Check(obj_callback->on_pager)) 435 if (PyCallable_Check(g_obj_callback->on_pager)) 442 436 { 443 437 PyObject_CallFunctionObjArgs( 444 obj_callback->on_pager,Py_BuildValue("i",call_id),438 g_obj_callback->on_pager,Py_BuildValue("i",call_id), 445 439 PyString_FromStringAndSize(to->ptr, to->slen), 446 440 PyString_FromStringAndSize(body->ptr, body->slen),obj, … … 460 454 pj_bool_t is_typing) 461 455 { 462 printf("on_typing called\n"); 463 if (PyCallable_Check(obj_callback->on_typing)) 456 if (PyCallable_Check(g_obj_callback->on_typing)) 464 457 { 465 458 PyObject_CallFunctionObjArgs( 466 obj_callback->on_typing,Py_BuildValue("i",call_id),459 g_obj_callback->on_typing,Py_BuildValue("i",call_id), 467 460 PyString_FromStringAndSize(from->ptr, from->slen), 468 461 PyString_FromStringAndSize(to->ptr, to->slen), … … 1726 1719 #endif 1727 1720 status = pj_thread_register(name, thread_desc, &thread); 1721 1722 if (status == PJ_SUCCESS) 1723 status = pj_thread_local_set(thread_id, (void*)1); 1728 1724 return Py_BuildValue("i",status); 1729 1725 } … … 1992 1988 } 1993 1989 status = pjsua_create(); 1994 //printf("status %d\n",status); 1990 1991 if (status == PJ_SUCCESS) { 1992 status = pj_thread_local_alloc(&thread_id); 1993 if (status == PJ_SUCCESS) 1994 status = pj_thread_local_set(thread_id, (void*)1); 1995 } 1996 1995 1997 return Py_BuildValue("i",status); 1996 1998 } … … 2028 2030 2029 2031 if (ua_cfgObj != Py_None) { 2030 2032 ua_cfg = (config_Object *)ua_cfgObj; 2031 2033 cfg_ua.cred_count = ua_cfg->cred_count; 2032 2034 for (i = 0; i < 4; i++) 2033 2035 { 2034 2036 cfg_ua.cred_info[i] = ua_cfg->cred_info[i]; 2035 2037 } 2036 2038 cfg_ua.max_calls = ua_cfg->max_calls; 2037 2039 for (i = 0; i < PJSUA_ACC_MAX_PROXIES; i++) 2038 2040 { 2039 2041 cfg_ua.outbound_proxy[i] = ua_cfg->outbound_proxy[i]; 2040 } 2042 } 2043 2044 g_obj_callback = ua_cfg->cb; 2045 Py_INCREF(g_obj_callback); 2046 2047 cfg_ua.cb.on_call_state = &cb_on_call_state; 2048 cfg_ua.cb.on_incoming_call = &cb_on_incoming_call; 2049 cfg_ua.cb.on_call_media_state = &cb_on_call_media_state; 2050 cfg_ua.cb.on_call_transfer_request = &cb_on_call_transfer_request; 2051 cfg_ua.cb.on_call_transfer_status = &cb_on_call_transfer_status; 2052 cfg_ua.cb.on_call_replace_request = &cb_on_call_replace_request; 2053 cfg_ua.cb.on_call_replaced = &cb_on_call_replaced; 2054 cfg_ua.cb.on_reg_state = &cb_on_reg_state; 2055 cfg_ua.cb.on_buddy_state = &cb_on_buddy_state; 2056 cfg_ua.cb.on_pager = &cb_on_pager; 2057 cfg_ua.cb.on_pager_status = &cb_on_pager_status; 2058 cfg_ua.cb.on_typing = &cb_on_typing; 2041 2059 2042 2060 cfg_ua.outbound_proxy_cnt = ua_cfg->outbound_proxy_cnt; … … 2045 2063 cfg_ua.user_agent.slen = strlen(cfg_ua.user_agent.ptr); 2046 2064 2047 obj_callback = ua_cfg->cb;2048 cfg_ua.cb.on_call_state = &cb_on_call_state;2049 cfg_ua.cb.on_incoming_call = &cb_on_incoming_call;2050 cfg_ua.cb.on_call_media_state = &cb_on_call_media_state;2051 cfg_ua.cb.on_call_transfer_request = &cb_on_call_transfer_request;2052 cfg_ua.cb.on_call_transfer_status = &cb_on_call_transfer_status;2053 cfg_ua.cb.on_call_replace_request = &cb_on_call_replace_request;2054 cfg_ua.cb.on_call_replaced = &cb_on_call_replaced;2055 cfg_ua.cb.on_reg_state = &cb_on_reg_state;2056 cfg_ua.cb.on_buddy_state = &cb_on_buddy_state;2057 cfg_ua.cb.on_pager = &cb_on_pager;2058 cfg_ua.cb.on_pager_status = &cb_on_pager_status;2059 cfg_ua.cb.on_typing = &cb_on_typing;2060 2065 p_cfg_ua = &cfg_ua; 2061 2066 } else { 2062 2067 p_cfg_ua = NULL; 2063 } 2068 } 2069 2064 2070 if (log_cfgObj != Py_None) { 2065 2071 log_cfg = (logging_config_Object *)log_cfgObj; … … 2077 2083 } else { 2078 2084 p_cfg_log = NULL; 2079 } 2085 } 2086 2080 2087 if (media_cfgObj != Py_None) { 2081 2088 media_cfg = (media_config_Object *)media_cfgObj; … … 2093 2100 cfg_media.tx_drop_pct = media_cfg->tx_drop_pct; 2094 2101 p_cfg_media = &cfg_media; 2095 2102 } else { 2096 2103 p_cfg_media = NULL; 2097 } 2104 } 2105 2098 2106 status = pjsua_init(p_cfg_ua, p_cfg_log, p_cfg_media); 2099 2107 return Py_BuildValue("i",status); … … 3960 3968 return NULL; 3961 3969 } 3970 3971 pjsua_acc_config_default(&cfg); 3962 3972 if (acObj != Py_None) 3963 3973 { … … 3965 3975 cfg.cred_count = ac->cred_count; 3966 3976 for (i = 0; i < 8; i++) 3967 3977 { 3968 3978 /*cfg.cred_info[i] = ac->cred_info[i];*/ 3969 3979 pjsip_cred_info_Object * ci = (pjsip_cred_info_Object *) … … 3980 3990 (PyString_AsString(ci->username)); 3981 3991 cfg.cred_info[i].data_type = ci->data_type; 3982 3992 } 3983 3993 cfg.force_contact.ptr = PyString_AsString(ac->force_contact); 3984 3994 cfg.force_contact.slen = strlen(PyString_AsString(ac->force_contact)); … … 3990 4000 cfg.proxy[i].ptr = PyString_AsString 3991 4001 (PyList_GetItem((PyObject *)ac->proxy,i)); 3992 4002 } 3993 4003 cfg.proxy_cnt = ac->proxy_cnt; 3994 4004 cfg.publish_enabled = ac->publish_enabled; … … 7163 7173 dst_uri.slen = strlen(PyString_AsString(sd)); 7164 7174 if (omdObj != Py_None) { 7165 7175 omd = (msg_data_Object *)omdObj; 7166 7176 msg_data.content_type.ptr = PyString_AsString(omd->content_type); 7167 7177 msg_data.content_type.slen = strlen … … 7174 7184 options, &user_data, &msg_data, &call_id); 7175 7185 pj_pool_release(pool); 7176 7186 } else { 7177 7187 status = pjsua_call_make_call(acc_id, &dst_uri, 7178 7188 options, &user_data, NULL, &call_id); 7179 } 7189 } 7190 7180 7191 return Py_BuildValue("ii",status, call_id); 7181 7192 } … … 7254 7265 call_info_Object * oi; 7255 7266 pjsua_call_info info; 7256 int i;7257 7267 7258 7268 … … 7268 7278 oi = (call_info_Object *)call_info_new(&call_info_Type, NULL, NULL); 7269 7279 oi->acc_id = info.acc_id; 7270 for (i = 0; i < 128; i++) 7271 { 7272 oi->buf_.call_id[i] = info.buf_.call_id[i]; 7273 oi->buf_.last_status_text[i] = info.buf_.last_status_text[i]; 7274 oi->buf_.local_contact[i] = info.buf_.local_contact[i]; 7275 oi->buf_.local_info[i] = info.buf_.local_info[i]; 7276 oi->buf_.remote_contact[i] = info.buf_.remote_contact[i]; 7277 oi->buf_.remote_info[i] = info.buf_.remote_info[i]; 7278 } 7280 pj_ansi_snprintf(oi->buf_.call_id, sizeof(oi->buf_.call_id), 7281 "%.*s", (int)info.call_id.slen, info.call_id.ptr); 7282 pj_ansi_snprintf(oi->buf_.last_status_text, sizeof(oi->buf_.last_status_text), 7283 "%.*s", (int)info.last_status_text.slen, info.last_status_text.ptr); 7284 pj_ansi_snprintf(oi->buf_.local_contact, sizeof(oi->buf_.local_contact), 7285 "%.*s", (int)info.local_contact.slen, info.local_contact.ptr); 7286 pj_ansi_snprintf(oi->buf_.local_info, sizeof(oi->buf_.local_info), 7287 "%.*s", (int)info.local_info.slen, info.local_info.ptr); 7288 pj_ansi_snprintf(oi->buf_.remote_contact, sizeof(oi->buf_.remote_contact), 7289 "%.*s", (int)info.remote_contact.slen, info.remote_contact.ptr); 7290 pj_ansi_snprintf(oi->buf_.remote_info, sizeof(oi->buf_.remote_info), 7291 "%.*s", (int)info.remote_info.slen, info.remote_info.ptr); 7292 7279 7293 oi->call_id = PyString_FromStringAndSize(info.call_id.ptr, 7280 7294 info.call_id.slen); … … 7372 7386 return NULL; 7373 7387 } 7374 7388 7375 7389 reason.ptr = PyString_AsString(sr); 7376 7390 reason.slen = strlen(PyString_AsString(sr)); … … 7409 7423 PyObject * omdObj; 7410 7424 msg_data_Object * omd; 7411 pj_pool_t * pool ;7425 pj_pool_t * pool = NULL; 7412 7426 7413 7427 if (!PyArg_ParseTuple(pArgs, "iIOO", &call_id, &code, &sr, &omdObj)) … … 7429 7443 status = pjsua_call_hangup(call_id, code, &reason, &msg_data); 7430 7444 pj_pool_release(pool); 7431 7445 } else { 7432 7446 status = pjsua_call_hangup(call_id, code, &reason, NULL); 7433 7447 } 7434 7448 return Py_BuildValue("i",status); 7435 7449 } -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c
r881 r916 1004 1004 if (call->res_time.sec == 0) 1005 1005 pj_gettimeofday(&call->res_time); 1006 1007 if (reason && reason->slen == 0) 1008 reason = NULL; 1006 1009 1007 1010 /* Create response message */
Note: See TracChangeset
for help on using the changeset viewer.