Changeset 1438


Ignore:
Timestamp:
Sep 17, 2007 3:44:47 PM (12 years ago)
Author:
bennylp
Message:

Updated pjsua_app.py Python sample application to the new changes in Python module (thanks Gideon Klompje)

Location:
pjproject/trunk/pjsip-apps/src/py_pjsua
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip-apps/src/py_pjsua/pjsua_app.py

    r1430 r1438  
    2020# Set C_STUN_HOST to the address:port of the STUN server to enable STUN 
    2121# 
    22 #C_STUN_HOST = "" 
    23 C_STUN_HOST = "192.168.0.2" 
     22C_STUN_HOST = "" 
     23#C_STUN_HOST = "192.168.0.2" 
    2424#C_STUN_HOST = "stun.iptel.org:3478" 
    2525 
     
    268268        acc_cfg.id = "sip:" + acc_username + "@" + acc_domain 
    269269        acc_cfg.reg_uri = "sip:" + acc_domain 
    270         acc_cfg.cred_count = 1 
    271         acc_cfg.cred_info[0].realm = acc_domain 
    272         acc_cfg.cred_info[0].scheme = "digest" 
    273         acc_cfg.cred_info[0].username = acc_username 
    274         acc_cfg.cred_info[0].data_type = 0 
    275         acc_cfg.cred_info[0].data = acc_passwd 
     270 
     271        cred_info = py_pjsua.Pjsip_Cred_Info() 
     272        cred_info.realm = "*" 
     273        cred_info.scheme = "digest" 
     274        cred_info.username = acc_username 
     275        cred_info.data_type = 0 
     276        cred_info.data = acc_passwd 
     277 
     278        acc_cfg.cred_info.append(1) 
     279        acc_cfg.cred_info[0] = cred_info 
    276280 
    277281        # Add new SIP account 
     
    339343                info = py_pjsua.conf_get_port_info(port) 
    340344                txlist = "" 
    341                 for i in range(info.listener_cnt): 
    342                         txlist = txlist + "#" + `info.listeners[i]` + " " 
     345                for listener in info.listeners: 
     346                        txlist = txlist + "#" + `listener` + " " 
    343347                 
    344348                print "Port #" + `info.slot_id` + "[" + `(info.clock_rate/1000)` + "KHz/" + `(info.samples_per_frame * 1000 / info.clock_rate)` + "ms] " + info.name + " transmitting to: " + txlist 
  • pjproject/trunk/pjsip-apps/src/py_pjsua/py_pjsua.c

    r1430 r1438  
    24042404    unsigned  samples_per_frame; 
    24052405    unsigned  bits_per_sample; 
    2406     unsigned  listener_cnt; 
    24072406    PyListObject * listeners; 
    24082407 
     
    24442443        }         
    24452444         
    2446         self->listeners = (PyListObject *)PyList_New(PJSUA_MAX_CONF_PORTS); 
     2445        self->listeners = (PyListObject *)PyList_New(0); 
    24472446        if (self->listeners == NULL) 
    24482447        { 
     
    24882487        offsetof(PyObj_pjsua_conf_port_info, bits_per_sample), 0, 
    24892488        "Bits per sample" 
    2490     }, 
    2491     { 
    2492         "listener_cnt", T_INT,  
    2493         offsetof(PyObj_pjsua_conf_port_info, listener_cnt), 0, 
    2494         "Number of listeners in the array." 
    24952489    }, 
    24962490    { 
     
    31673161    pjsua_conf_port_info info; 
    31683162    int status;  
    3169     int i; 
     3163    unsigned i; 
    31703164 
    31713165    PJ_UNUSED_ARG(pSelf); 
     
    31833177    obj->channel_count = info.bits_per_sample; 
    31843178    obj->clock_rate = info.clock_rate; 
    3185     obj->listener_cnt = info.listener_cnt; 
    31863179    obj->name = PyString_FromStringAndSize(info.name.ptr, info.name.slen); 
    31873180    obj->samples_per_frame = info.samples_per_frame; 
    31883181    obj->slot_id = info.slot_id; 
    31893182     
    3190     for (i = 0; i < PJSUA_MAX_CONF_PORTS; i++) { 
     3183    obj->listeners = (PyListObject *)PyList_New(info.listener_cnt); 
     3184    for (i = 0; i < info.listener_cnt; i++) { 
    31913185        PyObject * item = Py_BuildValue("i",info.listeners[i]); 
    31923186        PyList_SetItem((PyObject *)obj->listeners, i, item); 
  • pjproject/trunk/pjsip-apps/src/py_pjsua/py_pjsua.h

    r1430 r1438  
    2929    pj_str_t str; 
    3030 
    31     str.ptr = PyString_AS_STRING(obj); 
    32     str.slen = PyString_GET_SIZE(obj); 
     31    if (obj) { 
     32        str.ptr = PyString_AS_STRING(obj); 
     33        str.slen = PyString_GET_SIZE(obj); 
     34    } else { 
     35        str.ptr = NULL; 
     36        str.slen = 0; 
     37    } 
    3338 
    3439    return str; 
     
    19061911                                                    cfg->force_contact.slen); 
    19071912    Py_XDECREF(obj->proxy); 
    1908     obj->proxy = (PyListObject *)PyList_New(8); 
     1913    obj->proxy = (PyListObject *)PyList_New(0); 
    19091914    for (i=0; i<cfg->proxy_cnt; ++i) { 
    19101915        PyObject * str; 
    19111916        str = PyString_FromStringAndSize(cfg->proxy[i].ptr,  
    19121917                                         cfg->proxy[i].slen); 
    1913         PyList_SetItem((PyObject *)obj->proxy, i, str); 
     1918        PyList_Append((PyObject *)obj->proxy, str); 
    19141919    } 
    19151920 
     
    19171922 
    19181923    Py_XDECREF(obj->cred_info); 
    1919     obj->cred_info = (PyListObject *)PyList_New(8); 
     1924    obj->cred_info = (PyListObject *)PyList_New(0); 
    19201925    for (i=0; i<cfg->cred_count; ++i) { 
    19211926        PyObj_pjsip_cred_info * ci; 
     
    19241929             PyObj_pjsip_cred_info_new(&PyTyp_pjsip_cred_info,NULL,NULL); 
    19251930        PyObj_pjsip_cred_info_import(ci, &cfg->cred_info[i]); 
    1926         PyList_SetItem((PyObject *)obj->cred_info, i, (PyObject *)ci); 
     1931        PyList_Append((PyObject *)obj->cred_info, (PyObject *)ci); 
    19271932    } 
    19281933 
     
    19921997            return NULL; 
    19931998        } 
    1994         self->proxy = (PyListObject *)PyList_New(8); 
     1999        self->proxy = (PyListObject *)PyList_New(0); 
    19952000        if (self->proxy == NULL) { 
    19962001            Py_DECREF(self); 
    19972002            return NULL; 
    19982003        } 
    1999         self->cred_info = (PyListObject *)PyList_New(8); 
     2004        self->cred_info = (PyListObject *)PyList_New(0); 
    20002005        if (self->cred_info == NULL) { 
    20012006            Py_DECREF(self); 
Note: See TracChangeset for help on using the changeset viewer.