Subversion Repositories tpanel

Rev

Rev 141 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 141 Rev 144
Line 168... Line 168...
168
    pj_pool_t *tmp_pool = pjsua_pool_create("tmp-TPanel", 1000, 1000);
168
    pj_pool_t *tmp_pool = pjsua_pool_create("tmp-TPanel", 1000, 1000);
169
 
169
 
170
    // Global configuration
170
    // Global configuration
171
    string idUri = "sip:" + TConfig::getSIPuser() + "@" + sipProxy;
171
    string idUri = "sip:" + TConfig::getSIPuser() + "@" + sipProxy;
172
    string regUri = "sip:" + sipProxy + ":" + to_string(TConfig::getSIPport());
172
    string regUri = "sip:" + sipProxy + ":" + to_string(TConfig::getSIPport());
-
 
173
    pjsua_config_default(&mAppConfig.cfg);
173
    mAppConfig.cfg.outbound_proxy_cnt = 1;
174
    mAppConfig.cfg.outbound_proxy_cnt = 1;
174
    mAppConfig.cfg.outbound_proxy[0] = pj_str((char *)regUri.c_str());
175
    mAppConfig.cfg.outbound_proxy[0] = pj_str((char *)regUri.c_str());
175
    mAppConfig.cfg.max_calls = SIP_MAX_LINES;
176
    mAppConfig.cfg.max_calls = SIP_MAX_LINES;
176
 
177
 
177
    if (!TConfig::getSIPstun().empty())
178
    if (!TConfig::getSIPstun().empty())
Line 181... Line 182...
181
 
182
 
182
        if (TConfig::getSIPnetworkIPv6())
183
        if (TConfig::getSIPnetworkIPv6())
183
            mAppConfig.cfg.stun_try_ipv6 = PJ_TRUE;
184
            mAppConfig.cfg.stun_try_ipv6 = PJ_TRUE;
184
    }
185
    }
185
 
186
 
186
    string uAgent = string("TPanel v") + VERSION_STRING();
187
    string uAgent = string("TPanel v") + VERSION_STRING() + "/" + PJ_OS_NAME;
187
    mAppConfig.cfg.user_agent = pj_str((char *)uAgent.c_str());
188
    mAppConfig.cfg.user_agent = pj_str((char *)uAgent.c_str());
188
 
-
 
189
    // Define main account
189
    // Define main account
190
    mAppConfig.acc_cnt = 1;
190
    mAppConfig.acc_cnt = 1;
191
    pjsua_acc_config_default(&mAppConfig.acc_cfg[0]);
191
    pjsua_acc_config_default(&mAppConfig.acc_cfg[0]);
192
    mAppConfig.acc_cfg[0].id = pj_str((char *)idUri.c_str());
192
    mAppConfig.acc_cfg[0].id = pj_str((char *)idUri.c_str());
193
    mAppConfig.acc_cfg[0].reg_uri = pj_str((char *)regUri.c_str());
193
    mAppConfig.acc_cfg[0].reg_uri = pj_str((char *)regUri.c_str());
Line 201... Line 201...
201
    mAppConfig.acc_cfg[0].cred_info[0].data = pj_str((char *)TConfig::getSIPpassword().c_str());
201
    mAppConfig.acc_cfg[0].cred_info[0].data = pj_str((char *)TConfig::getSIPpassword().c_str());
202
 
202
 
203
    /* Init pjsua */
203
    /* Init pjsua */
204
    pjsua_logging_config log_cfg;
204
    pjsua_logging_config log_cfg;
205
 
205
 
206
    pjsua_config_default(&mAppConfig.cfg);
-
 
207
    mAppConfig.cfg.cb.on_incoming_call = &on_incoming_call;
206
    mAppConfig.cfg.cb.on_incoming_call = &on_incoming_call;
208
    mAppConfig.cfg.cb.on_call_media_state = &on_call_media_state;
207
    mAppConfig.cfg.cb.on_call_media_state = &on_call_media_state;
209
    mAppConfig.cfg.cb.on_call_state = &on_call_state;
208
    mAppConfig.cfg.cb.on_call_state = &on_call_state;
210
    mAppConfig.cfg.cb.on_dtmf_digit2 = &call_on_dtmf_callback2;
209
    mAppConfig.cfg.cb.on_dtmf_digit2 = &call_on_dtmf_callback2;
211
    mAppConfig.cfg.cb.on_call_redirected = &call_on_redirected;
210
    mAppConfig.cfg.cb.on_call_redirected = &call_on_redirected;
212
    mAppConfig.cfg.cb.on_call_transfer_status = &on_call_transfer_status;
211
    mAppConfig.cfg.cb.on_call_transfer_status = &on_call_transfer_status;
213
    mAppConfig.cfg.cb.on_transport_state = &on_transport_state;
212
    mAppConfig.cfg.cb.on_transport_state = &on_transport_state;
214
    mAppConfig.cfg.cb.on_ip_change_progress = &on_ip_change_progress;
213
    mAppConfig.cfg.cb.on_ip_change_progress = &on_ip_change_progress;
-
 
214
    mAppConfig.cfg.cb.on_pager2 = &on_pager2;
-
 
215
    mAppConfig.cfg.cb.on_buddy_state = &on_buddy_state;
-
 
216
    mAppConfig.cfg.cb.on_buddy_evsub_state = &on_buddy_evsub_state;
-
 
217
    mAppConfig.cfg.cb.on_mwi_info = &on_mwi_info;
215
 
218
 
216
    pjsua_logging_config_default(&log_cfg);
219
    pjsua_logging_config_default(&log_cfg);
217
    log_cfg.console_level = 4;
220
    log_cfg.console_level = 4;
218
    log_cfg.level = 5;
221
    log_cfg.level = 5;
219
    log_cfg.decor = (PJ_LOG_HAS_SENDER);
222
    log_cfg.decor = (PJ_LOG_HAS_SENDER);
Line 603... Line 606...
603
        }
606
        }
604
 
607
 
605
        pjsua_acc_set_online_status(current_acc, PJ_TRUE);
608
        pjsua_acc_set_online_status(current_acc, PJ_TRUE);
606
    }
609
    }
607
 
610
 
-
 
611
    // Boddy for IM
-
 
612
    mAppConfig.buddy_cnt = 1;
-
 
613
    pjsua_buddy_config_default(mAppConfig.buddy_cfg);
-
 
614
    mAppConfig.buddy_cfg->uri = pj_str((char *)idUri.c_str());
-
 
615
    mAppConfig.buddy_cfg->subscribe = PJ_FALSE;
-
 
616
    pjsua_buddy_id bid;
-
 
617
 
-
 
618
    if (pjsua_buddy_add(mAppConfig.buddy_cfg, &bid) != PJ_SUCCESS)
-
 
619
    {
-
 
620
        MSG_ERROR("Couldn't create a new buddy for IM (SMS)!");
-
 
621
        mAppConfig.buddy_cnt = 0;
-
 
622
    }
-
 
623
 
608
    /* Init call setting */
624
    /* Init call setting */
609
    pjsua_call_setting call_opt;
625
    pjsua_call_setting call_opt;
610
    pjsua_call_setting_default(&call_opt);
626
    pjsua_call_setting_default(&call_opt);
611
    call_opt.aud_cnt = mAppConfig.aud_cnt;
627
    call_opt.aud_cnt = mAppConfig.aud_cnt;
612
    call_opt.vid_cnt = 0;
628
    call_opt.vid_cnt = 0;
Line 934... Line 950...
934
        mDTMFduration = ms;
950
        mDTMFduration = ms;
935
 
951
 
936
    return true;
952
    return true;
937
}
953
}
938
 
954
 
-
 
955
bool TSIPClient::sendIM(const string& target, const string& msg)
-
 
956
{
-
 
957
    DECL_TRACER("TSIPClient::sendIM(const string& target, const string& msg)");
-
 
958
 
-
 
959
    pj_str_t mime = pj_str((char *)"text/plain");
-
 
960
    pj_str_t to, content;
-
 
961
    pjsua_acc_id aid = PJSUA_INVALID_ID;
-
 
962
    REGISTER_THREAD();
-
 
963
 
-
 
964
    if (!target.empty() && !msg.empty())
-
 
965
    {
-
 
966
        to = pj_str((char *)target.c_str());
-
 
967
        content = pj_str((char *)msg.c_str());
-
 
968
        MSG_DEBUG("Sending instant message to: " << to.ptr << " [" << content.ptr << "]");
-
 
969
 
-
 
970
        if ((aid = pjsua_acc_find_for_outgoing(&to)) == PJSUA_INVALID_ID)
-
 
971
        {
-
 
972
            MSG_ERROR("No account found to send a message from!");
-
 
973
            return false;
-
 
974
        }
-
 
975
    }
-
 
976
    else if (!msg.empty())
-
 
977
    {
-
 
978
        pjsua_call_id cid = getActiveCall();
-
 
979
 
-
 
980
        if (cid == PJSUA_INVALID_ID)
-
 
981
        {
-
 
982
            MSG_ERROR("No active call. Can not send a messge!");
-
 
983
            return false;
-
 
984
        }
-
 
985
 
-
 
986
        pjsua_call_info cinfo;
-
 
987
 
-
 
988
        if (pjsua_call_get_info(cid, &cinfo) != PJ_SUCCESS)
-
 
989
        {
-
 
990
            MSG_ERROR("Error getting call information!");
-
 
991
            return false;
-
 
992
        }
-
 
993
 
-
 
994
        aid = cinfo.acc_id;
-
 
995
        content = pj_str((char *)msg.c_str());
-
 
996
        to = cinfo.remote_info;
-
 
997
    }
-
 
998
    else
-
 
999
        return false;
-
 
1000
 
-
 
1001
    if (pjsua_im_send(aid, &to, &mime, &content, NULL, NULL) != PJ_SUCCESS)
-
 
1002
    {
-
 
1003
        MSG_ERROR("Couldn't send a message to " << to.ptr << " (" << msg << ")");
-
 
1004
        return false;
-
 
1005
    }
-
 
1006
 
-
 
1007
    return true;
-
 
1008
}
-
 
1009
 
939
int TSIPClient::getNumberCalls()
1010
int TSIPClient::getNumberCalls()
940
{
1011
{
941
    DECL_TRACER("TSIPClient::getNumberCalls()");
1012
    DECL_TRACER("TSIPClient::getNumberCalls()");
942
 
1013
 
943
    return pjsua_call_get_count();
1014
    return pjsua_call_get_count();
Line 965... Line 1036...
965
    mMyself->setSIPState(state, id);
1036
    mMyself->setSIPState(state, id);
966
 
1037
 
967
    if (!gPageManager)
1038
    if (!gPageManager)
968
        return;
1039
        return;
969
 
1040
 
-
 
1041
    // If there is an incoming call and the internal phone is activated, this
-
 
1042
    // opens the phone dialog and shows the state.
970
    if (state == SIP_RINGING && TConfig::getSIPiphone() && gPageManager->getShowPhoneDialog())
1043
    if (state == SIP_RINGING && TConfig::getSIPiphone() && gPageManager->getShowPhoneDialog())
971
    {
1044
    {
972
        pjsua_call_info ci;
1045
        pjsua_call_info ci;
973
 
1046
 
974
        gPageManager->getShowPhoneDialog()(true);
1047
        gPageManager->getShowPhoneDialog()(true);
Line 998... Line 1071...
998
 
1071
 
999
        gPageManager->getSetPhoneNumber()(number);
1072
        gPageManager->getSetPhoneNumber()(number);
1000
        gPageManager->getSetPhoneState()(SIP_RINGING, id);
1073
        gPageManager->getSetPhoneState()(SIP_RINGING, id);
1001
    }
1074
    }
1002
 
1075
 
-
 
1076
    // Here we set the actual state. This is send to the controller, if there
-
 
1077
    // is one configured.
1003
    vector<string> cmds;
1078
    vector<string> cmds;
1004
    cmds.push_back("CALL");
1079
    cmds.push_back("CALL");
1005
 
1080
 
1006
    switch(state)
1081
    switch(state)
1007
    {
1082
    {
Line 1033... Line 1108...
1033
    init_ringtone_player();
1108
    init_ringtone_player();
1034
 
1109
 
1035
    if (start_ring_tone() != PJ_SUCCESS)
1110
    if (start_ring_tone() != PJ_SUCCESS)
1036
    {
1111
    {
1037
        //FIXME:: Add code to free the pool
1112
        //FIXME:: Add code to free the pool
-
 
1113
        pj_pool_release(mRingtonePortInfo.pool);
-
 
1114
        mRingtonePortInfo.pool = nullptr;
-
 
1115
        mPhoneRingInit = false;
1038
        return;
1116
        return;
1039
    }
1117
    }
1040
}
1118
}
1041
 
1119
 
1042
void TSIPClient::init_ringtone_player()
1120
void TSIPClient::init_ringtone_player()
Line 1083... Line 1161...
1083
    }
1161
    }
1084
 
1162
 
1085
    mRingtonePortInfo.ring_on = PJ_FALSE;
1163
    mRingtonePortInfo.ring_on = PJ_FALSE;
1086
    mRingtonePortInfo.ring_slot = file_slot;
1164
    mRingtonePortInfo.ring_slot = file_slot;
1087
    mRingtonePortInfo.ring_port = file_port;
1165
    mRingtonePortInfo.ring_port = file_port;
-
 
1166
 
-
 
1167
    if (mRingtonePortInfo.pool)
-
 
1168
        pj_pool_release(mRingtonePortInfo.pool);
-
 
1169
 
1088
    mRingtonePortInfo.pool = pool;
1170
    mRingtonePortInfo.pool = pool;
1089
    mPhoneRingInit = true;
1171
    mPhoneRingInit = true;
1090
}
1172
}
1091
 
1173
 
1092
pj_status_t TSIPClient::start_ring_tone()
1174
pj_status_t TSIPClient::start_ring_tone()
Line 1135... Line 1217...
1135
    }
1217
    }
1136
 
1218
 
1137
    return status;
1219
    return status;
1138
}
1220
}
1139
 
1221
 
-
 
1222
pjsua_buddy_id TSIPClient::addBuddy(const string& rsipurl)
-
 
1223
{
-
 
1224
    DECL_TRACER("TSIPClient::addBuddy(const string& rsipurl)");
-
 
1225
 
-
 
1226
    // Boddy for IM
-
 
1227
    uint_t bcnt = mAppConfig.buddy_cnt + 1;
-
 
1228
 
-
 
1229
    if (bcnt >= PJSUA_MAX_BUDDIES)
-
 
1230
        return PJSUA_INVALID_ID;
-
 
1231
 
-
 
1232
    pj_str_t uri = pj_str((char *)rsipurl.c_str());
-
 
1233
 
-
 
1234
    if (pjsua_verify_sip_url(rsipurl.c_str()) != PJ_SUCCESS)
-
 
1235
    {
-
 
1236
        MSG_ERROR("Invalid SIP URI: " << rsipurl);
-
 
1237
        return PJSUA_INVALID_ID;
-
 
1238
    }
-
 
1239
 
-
 
1240
    pjsua_buddy_config *cfg = &mAppConfig.buddy_cfg[bcnt];
-
 
1241
    pjsua_buddy_config_default(cfg);
-
 
1242
    cfg->uri = uri;
-
 
1243
    cfg->subscribe = PJ_FALSE;
-
 
1244
    pjsua_buddy_id bid;
-
 
1245
 
-
 
1246
    if (pjsua_buddy_add(mAppConfig.buddy_cfg, &bid) != PJ_SUCCESS)
-
 
1247
    {
-
 
1248
        MSG_ERROR("Couldn't create a new buddy for URL " << rsipurl << "!");
-
 
1249
        return PJSUA_INVALID_ID;
-
 
1250
    }
-
 
1251
 
-
 
1252
    mAppConfig.buddy_cnt = bcnt;
-
 
1253
    return bid;
-
 
1254
}
-
 
1255
 
-
 
1256
TSIPClient::_uri_t TSIPClient::parseUri(const string& uri)
-
 
1257
{
-
 
1258
    DECL_TRACER("TSIPClient::parseUri(const string& uri)");
-
 
1259
 
-
 
1260
    size_t pos1, pos2;
-
 
1261
    _uri_t u;
-
 
1262
 
-
 
1263
    pos1 = uri.find("\"");
-
 
1264
 
-
 
1265
    if (pos1 != string::npos)
-
 
1266
    {
-
 
1267
        pos2 = uri.find("\"", pos1 + 1);
-
 
1268
 
-
 
1269
        if (pos2 != string::npos)
-
 
1270
            u.name = uri.substr(pos1 + 1, pos2 - pos1 - 1);
-
 
1271
    }
-
 
1272
 
-
 
1273
    pos1 = uri.find("<");
-
 
1274
 
-
 
1275
    if (pos1 != string::npos)
-
 
1276
    {
-
 
1277
        pos2 = uri.find(":");
-
 
1278
 
-
 
1279
        if (pos2 != string::npos)
-
 
1280
            u.scheme = uri.substr(pos1 + 1, pos2 - pos1 - 1);
-
 
1281
        else
-
 
1282
        {
-
 
1283
            pos2 = uri.find("@");
-
 
1284
 
-
 
1285
            if (pos2 != string::npos)
-
 
1286
                u.user = uri.substr(pos1 + 1, pos2 - pos1 - 1);
-
 
1287
            else
-
 
1288
            {
-
 
1289
                pos2 = uri.find(">");
-
 
1290
 
-
 
1291
                if (pos2 != string::npos)
-
 
1292
                    u.server = uri.substr(pos1, pos2 - pos1 - 1);
-
 
1293
 
-
 
1294
                return u;
-
 
1295
            }
-
 
1296
 
-
 
1297
            return u;
-
 
1298
        }
-
 
1299
 
-
 
1300
        pos1 = pos2;
-
 
1301
        pos2 = uri.find("@");
-
 
1302
 
-
 
1303
        if (pos2 != string::npos)
-
 
1304
            u.user = uri.substr(pos1 + 1, pos2 - pos1 - 1);
-
 
1305
        else
-
 
1306
        {
-
 
1307
            pos2 = uri.find(">");
-
 
1308
 
-
 
1309
            if (pos2 != string::npos)
-
 
1310
                u.server = uri.substr(pos1, pos2 - pos1 - 1);
-
 
1311
            else
-
 
1312
                return u;
-
 
1313
        }
-
 
1314
 
-
 
1315
        pos1 = pos2;
-
 
1316
        pos2 = uri.find(">");
-
 
1317
 
-
 
1318
        if (pos2 != string::npos)
-
 
1319
            u.server = uri.substr(pos1 + 1, pos2 - pos1 - 1);
-
 
1320
        else
-
 
1321
            u.server = uri.substr(pos1 + 1);
-
 
1322
    }
-
 
1323
 
-
 
1324
    return u;
-
 
1325
}
-
 
1326
 
1140
/*******************************************************************************
1327
/*******************************************************************************
1141
 * All the following functions are static callback functions.
1328
 * All the following functions are static callback functions.
1142
 * The following functions are called by the PJSUA-library for different
1329
 * The following functions are called by the PJSUA-library for different
1143
 * events.
1330
 * events.
1144
 ******************************************************************************/
1331
 ******************************************************************************/
Line 1333... Line 1520...
1333
    pjsua_call_get_info(call_id, &ci);
1520
    pjsua_call_get_info(call_id, &ci);
1334
 
1521
 
1335
    MSG_DEBUG("Incoming call from " << ci.remote_info.ptr);
1522
    MSG_DEBUG("Incoming call from " << ci.remote_info.ptr);
1336
    sendConnectionStatus(SIP_RINGING, call_id);
1523
    sendConnectionStatus(SIP_RINGING, call_id);
1337
 
1524
 
1338
    /* Automatically answer incoming calls with 200/OK */
-
 
1339
    if (gPageManager && gPageManager->getPHNautoanswer() && mMyself)
1525
    if (gPageManager && gPageManager->getPHNautoanswer() && mMyself)
1340
        mMyself->pickup(call_id);
1526
        mMyself->pickup(call_id);   // Automatically answer incoming calls with 200/OK
1341
    else if (mMyself)
1527
    else if (mMyself)
1342
        mMyself->runRinger();
1528
        mMyself->runRinger();       // Start the ring tone
1343
}
1529
}
1344
 
1530
 
1345
/* Callback called by the library when call's state has changed */
1531
/* Callback called by the library when call's state has changed */
1346
void TSIPClient::on_call_state(pjsua_call_id call_id, pjsip_event *e)
1532
void TSIPClient::on_call_state(pjsua_call_id call_id, pjsip_event *e)
1347
{
1533
{
Line 1683... Line 1869...
1683
    {
1869
    {
1684
        MSG_ERROR("IP change progress failed (" << status << ")");
1870
        MSG_ERROR("IP change progress failed (" << status << ")");
1685
    }
1871
    }
1686
}
1872
}
1687
 
1873
 
-
 
1874
void TSIPClient::on_pager2(pjsua_call_id call_id, const pj_str_t* from, const pj_str_t* to, const pj_str_t* contact, const pj_str_t* mime_type, const pj_str_t* body, pjsip_rx_data* rdata, pjsua_acc_id acc_id)
-
 
1875
{
-
 
1876
    DECL_TRACER("TSIPClient::on_pager2(pjsua_call_id call_id, const pj_str_t* from, const pj_str_t* to, const pj_str_t* contact, const pj_str_t* mime_type, const pj_str_t* body, pjsip_rx_data* rdata, pjsua_acc_id acc_id)");
-
 
1877
 
-
 
1878
    PJ_UNUSED_ARG(contact);
-
 
1879
    PJ_UNUSED_ARG(rdata);
-
 
1880
 
-
 
1881
    string sFrom(from->ptr, from->slen);
-
 
1882
    string sTo(to->ptr, to->slen);
-
 
1883
    string mime(mime_type->ptr, mime_type->slen);
-
 
1884
    string bdy(body->ptr, body->slen);
-
 
1885
 
-
 
1886
    MSG_DEBUG("Received message for ID " << call_id << " from " << sFrom << ", to " << sTo << " (" << acc_id << ") with mime type " << mime << ": " << bdy);
-
 
1887
 
-
 
1888
    if (acc_id == PJSUA_INVALID_ID)
-
 
1889
    {
-
 
1890
        MSG_ERROR("Invalid account ID: " << acc_id);
-
 
1891
        return;
-
 
1892
    }
-
 
1893
 
-
 
1894
    if (mime != "text/plain")
-
 
1895
    {
-
 
1896
        MSG_ERROR("Unknown mime type " << mime);
-
 
1897
        return;
-
 
1898
    }
-
 
1899
 
-
 
1900
    _uri_t u = parseUri(from->ptr);
-
 
1901
 
-
 
1902
    vector<string> cmds;
-
 
1903
    cmds.push_back("IM");
-
 
1904
    cmds.push_back(u.user + "@" + u.server);
-
 
1905
 
-
 
1906
    if (bdy.length() > 256)
-
 
1907
        bdy = bdy.substr(0, 256);
-
 
1908
 
-
 
1909
    cmds.push_back(bdy);
-
 
1910
 
-
 
1911
    if (gPageManager)
-
 
1912
        gPageManager->sendPHN(cmds);
-
 
1913
}
-
 
1914
 
-
 
1915
void TSIPClient::on_buddy_state(pjsua_buddy_id buddy_id)
-
 
1916
{
-
 
1917
    DECL_TRACER("TSIPClient::on_buddy_state(pjsua_buddy_id buddy_id)");
-
 
1918
 
-
 
1919
    pjsua_buddy_info binfo;
-
 
1920
 
-
 
1921
    if (pjsua_buddy_get_info(buddy_id, &binfo) != PJ_SUCCESS)
-
 
1922
    {
-
 
1923
        MSG_ERROR("Error retrieving buddy information for buddy ID " << buddy_id);
-
 
1924
        return;
-
 
1925
    }
-
 
1926
 
-
 
1927
    switch(binfo.status)
-
 
1928
    {
-
 
1929
        case PJSUA_BUDDY_STATUS_ONLINE:
-
 
1930
            MSG_DEBUG("Buddy " << buddy_id << ": " << binfo.contact.ptr << " is online.");
-
 
1931
        break;
-
 
1932
 
-
 
1933
        case PJSUA_BUDDY_STATUS_OFFLINE:
-
 
1934
            MSG_DEBUG("Buddy " << buddy_id << ": " << binfo.contact.ptr << " is offline.");
-
 
1935
        break;
-
 
1936
 
-
 
1937
        default:
-
 
1938
            MSG_DEBUG("Buddy " << buddy_id << ": " << binfo.contact.ptr << " is unknown.");
-
 
1939
    }
-
 
1940
}
-
 
1941
void TSIPClient::on_buddy_evsub_state(pjsua_buddy_id buddy_id, pjsip_evsub* sub, pjsip_event* event)
-
 
1942
{
-
 
1943
    DECL_TRACER("TSIPClient::on_buddy_evsub_state(pjsua_buddy_id buddy_id, pjsip_evsub* sub, pjsip_event* event)");
-
 
1944
 
-
 
1945
    char event_info[80];
-
 
1946
 
-
 
1947
    if (event->type == PJSIP_EVENT_RX_MSG)
-
 
1948
    {
-
 
1949
        pjsip_rx_data *rdata = event->body.tsx_state.src.rdata;
-
 
1950
        snprintf(event_info, sizeof(event_info), " (RX %s)", pjsip_rx_data_get_info(rdata));
-
 
1951
        MSG_DEBUG("Budyy event for ID " << buddy_id << ":" << event_info);
-
 
1952
    }
-
 
1953
    else
-
 
1954
        event_info[0] = 0;
-
 
1955
 
-
 
1956
    MSG_DEBUG("Buddy " << buddy_id << ": subscription state: " << pjsip_evsub_get_state_name(sub) << " (event: " << pjsip_event_str(event->type) << event_info << ")");
-
 
1957
}
-
 
1958
 
-
 
1959
void TSIPClient::on_mwi_info(pjsua_acc_id acc_id, pjsua_mwi_info* mwi_info)
-
 
1960
{
-
 
1961
    DECL_TRACER("TSIPClient::on_mwi_info(pjsua_acc_id acc_id, pjsua_mwi_info* mwi_info)");
-
 
1962
 
-
 
1963
    MSG_INFO("Received MWI for acc " << acc_id);
-
 
1964
    vector<string>cmds;
-
 
1965
    cmds.push_back("IM");
-
 
1966
 
-
 
1967
    if (mwi_info->rdata->msg_info.ctype)
-
 
1968
    {
-
 
1969
        const pjsip_ctype_hdr *ctype = mwi_info->rdata->msg_info.ctype;
-
 
1970
        string msg(ctype->media.subtype.ptr, ctype->media.subtype.slen);
-
 
1971
        MSG_INFO("Content-Type: " << ctype->media.type.ptr << "/" << msg);
-
 
1972
        const pjsip_from_hdr *from = mwi_info->rdata->msg_info.from;
-
 
1973
 
-
 
1974
        cmds.push_back((char *)pjsip_uri_get_uri(from->uri));
-
 
1975
    }
-
 
1976
    else
-
 
1977
        cmds.push_back("sip:?@" + TConfig::getSIPproxy());
-
 
1978
 
-
 
1979
    if (!mwi_info->rdata->msg_info.msg->body)
-
 
1980
    {
-
 
1981
        MSG_INFO("No message body!");
-
 
1982
        return;
-
 
1983
    }
-
 
1984
 
-
 
1985
    string body((char *)mwi_info->rdata->msg_info.msg->body->data, mwi_info->rdata->msg_info.msg->body->len);
-
 
1986
 
-
 
1987
    if (body.length() > 256)
-
 
1988
        cmds.push_back(body.substr(0, 256));
-
 
1989
    else
-
 
1990
        cmds.push_back(body);
-
 
1991
 
-
 
1992
    MSG_INFO("Body:" << std::endl << body);
-
 
1993
 
-
 
1994
    if (gPageManager)
-
 
1995
        gPageManager->sendPHN(cmds);
-
 
1996
}
-
 
1997
 
1688
/*
1998
/*
1689
 * A simple registrar, invoked by default_mod_on_rx_request()
1999
 * A simple registrar, invoked by default_mod_on_rx_request()
1690
 */
2000
 */
1691
void TSIPClient::simple_registrar(pjsip_rx_data *rdata)
2001
void TSIPClient::simple_registrar(pjsip_rx_data *rdata)
1692
{
2002
{
-
 
2003
    DECL_TRACER("TSIPClient::simple_registrar(pjsip_rx_data *rdata)");
-
 
2004
 
1693
    pjsip_tx_data *tdata;
2005
    pjsip_tx_data *tdata;
1694
    const pjsip_expires_hdr *exp;
2006
    const pjsip_expires_hdr *exp;
1695
    const pjsip_hdr *h;
2007
    const pjsip_hdr *h;
1696
    unsigned cnt = 0;
2008
    unsigned cnt = 0;
1697
    pjsip_generic_string_hdr *srv;
2009
    pjsip_generic_string_hdr *srv;
Line 1750... Line 2062...
1750
 */
2062
 */
1751
 
2063
 
1752
/* Notification on incoming request */
2064
/* Notification on incoming request */
1753
pj_bool_t TSIPClient::default_mod_on_rx_request(pjsip_rx_data *rdata)
2065
pj_bool_t TSIPClient::default_mod_on_rx_request(pjsip_rx_data *rdata)
1754
{
2066
{
-
 
2067
    DECL_TRACER("TSIPClient::default_mod_on_rx_request(pjsip_rx_data *rdata)");
-
 
2068
 
1755
    pjsip_tx_data *tdata;
2069
    pjsip_tx_data *tdata;
1756
    pjsip_status_code status_code;
2070
    pjsip_status_code status_code;
1757
    pj_status_t status;
2071
    pj_status_t status;
1758
 
2072
 
1759
    /* Don't respond to ACK! */
2073
    /* Don't respond to ACK! */
Line 1804... Line 2118...
1804
        pj_str_t user_agent;
2118
        pj_str_t user_agent;
1805
        char tmp[80];
2119
        char tmp[80];
1806
        const pj_str_t USER_AGENT = { (char *)"User-Agent", 10};
2120
        const pj_str_t USER_AGENT = { (char *)"User-Agent", 10};
1807
        pjsip_hdr *h;
2121
        pjsip_hdr *h;
1808
 
2122
 
1809
        pj_ansi_snprintf(tmp, sizeof(tmp), "PJSUA v%s/%s", pj_get_version(), PJ_OS_NAME);
2123
//        pj_ansi_snprintf(tmp, sizeof(tmp), "PJSUA v%s/%s", pj_get_version(), PJ_OS_NAME);
-
 
2124
        pj_ansi_snprintf(tmp, sizeof(tmp), "TPanel v%s/%s", VERSION_STRING(), PJ_OS_NAME);
1810
        pj_strdup2_with_null(tdata->pool, &user_agent, tmp);
2125
        pj_strdup2_with_null(tdata->pool, &user_agent, tmp);
1811
 
2126
 
1812
        h = (pjsip_hdr*) pjsip_generic_string_hdr_create(tdata->pool, &USER_AGENT, &user_agent);
2127
        h = (pjsip_hdr*) pjsip_generic_string_hdr_create(tdata->pool, &USER_AGENT, &user_agent);
1813
        pjsip_msg_add_hdr(tdata->msg, h);
2128
        pjsip_msg_add_hdr(tdata->msg, h);
1814
    }
2129
    }
1815
 
2130
 
1816
    status = pjsip_endpt_send_response2(pjsua_get_pjsip_endpt(), rdata, tdata, NULL, NULL);
2131
    status = pjsip_endpt_send_response2(pjsua_get_pjsip_endpt(), rdata, tdata, NULL, NULL);
1817
 
2132
 
-
 
2133
    if (status != PJ_SUCCESS)
1818
    if (status != PJ_SUCCESS) pjsip_tx_data_dec_ref(tdata);
2134
        pjsip_tx_data_dec_ref(tdata);
-
 
2135
 
1819
    return PJ_TRUE;
2136
    return PJ_TRUE;
1820
}
2137
}
1821
 
2138
 
1822
#endif  // _NOSIP_
2139
#endif  // _NOSIP_