Ignore:
Timestamp:
Nov 6, 2013 8:05:11 AM (10 years ago)
Author:
bennylp
Message:

Re #1519: Added persistent API in pjsua2, with JSON as the format. The API is extensible to support more formats. All config structures are serializable now. Tested in Python.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/pjsua2/pjsip/src/pjsua2/account.cpp

    r4639 r4644  
    11/* $Id$ */ 
    22/* 
    3  * Copyright (C) 2012 Teluu Inc. (http://www.teluu.com) 
     3 * Copyright (C) 2013 Teluu Inc. (http://www.teluu.com) 
    44 * 
    55 * This program is free software; you can redistribute it and/or modify 
     
    2727#define THIS_FILE               "account.cpp" 
    2828 
     29/////////////////////////////////////////////////////////////////////////////// 
     30 
     31void AccountRegConfig::readObject(const ContainerNode &node) throw(Error) 
     32{ 
     33    ContainerNode this_node = node.readContainer("AccountRegConfig"); 
     34 
     35    NODE_READ_STRING    (this_node, registrarUri); 
     36    NODE_READ_BOOL      (this_node, registerOnAdd); 
     37    NODE_READ_UNSIGNED  (this_node, timeoutSec); 
     38    NODE_READ_UNSIGNED  (this_node, retryIntervalSec); 
     39    NODE_READ_UNSIGNED  (this_node, firstRetryIntervalSec); 
     40    NODE_READ_UNSIGNED  (this_node, delayBeforeRefreshSec); 
     41    NODE_READ_BOOL      (this_node, dropCallsOnFail); 
     42    NODE_READ_UNSIGNED  (this_node, unregWaitSec); 
     43    NODE_READ_UNSIGNED  (this_node, proxyUse); 
     44 
     45    readSipHeaders(this_node, "headers", headers); 
     46} 
     47 
     48void AccountRegConfig::writeObject(ContainerNode &node) const throw(Error) 
     49{ 
     50    ContainerNode this_node = node.writeNewContainer("AccountRegConfig"); 
     51 
     52    NODE_WRITE_STRING   (this_node, registrarUri); 
     53    NODE_WRITE_BOOL     (this_node, registerOnAdd); 
     54    NODE_WRITE_UNSIGNED (this_node, timeoutSec); 
     55    NODE_WRITE_UNSIGNED (this_node, retryIntervalSec); 
     56    NODE_WRITE_UNSIGNED (this_node, firstRetryIntervalSec); 
     57    NODE_WRITE_UNSIGNED (this_node, delayBeforeRefreshSec); 
     58    NODE_WRITE_BOOL     (this_node, dropCallsOnFail); 
     59    NODE_WRITE_UNSIGNED (this_node, unregWaitSec); 
     60    NODE_WRITE_UNSIGNED (this_node, proxyUse); 
     61 
     62    writeSipHeaders(this_node, "headers", headers); 
     63} 
     64 
     65/////////////////////////////////////////////////////////////////////////////// 
     66 
     67void AccountSipConfig::readObject(const ContainerNode &node) throw(Error) 
     68{ 
     69    ContainerNode this_node = node.readContainer("AccountSipConfig"); 
     70 
     71    NODE_READ_STRINGV   (this_node, proxies); 
     72    NODE_READ_STRING    (this_node, contactForced); 
     73    NODE_READ_STRING    (this_node, contactParams); 
     74    NODE_READ_STRING    (this_node, contactUriParams); 
     75    NODE_READ_BOOL      (this_node, authInitialEmpty); 
     76    NODE_READ_STRING    (this_node, authInitialAlgorithm); 
     77    NODE_READ_INT       (this_node, transportId); 
     78 
     79    ContainerNode creds_node = this_node.readArray("authCreds"); 
     80    authCreds.resize(0); 
     81    while (creds_node.hasUnread()) { 
     82        AuthCredInfo cred; 
     83        cred.readObject(creds_node); 
     84        authCreds.push_back(cred); 
     85    } 
     86} 
     87 
     88void AccountSipConfig::writeObject(ContainerNode &node) const throw(Error) 
     89{ 
     90    ContainerNode this_node = node.writeNewContainer("AccountSipConfig"); 
     91 
     92    NODE_WRITE_STRINGV  (this_node, proxies); 
     93    NODE_WRITE_STRING   (this_node, contactForced); 
     94    NODE_WRITE_STRING   (this_node, contactParams); 
     95    NODE_WRITE_STRING   (this_node, contactUriParams); 
     96    NODE_WRITE_BOOL     (this_node, authInitialEmpty); 
     97    NODE_WRITE_STRING   (this_node, authInitialAlgorithm); 
     98    NODE_WRITE_INT      (this_node, transportId); 
     99 
     100    ContainerNode creds_node = this_node.writeNewArray("authCreds"); 
     101    for (unsigned i=0; i<authCreds.size(); ++i) { 
     102        authCreds[i].writeObject(creds_node); 
     103    } 
     104} 
     105 
     106/////////////////////////////////////////////////////////////////////////////// 
     107 
     108void AccountCallConfig::readObject(const ContainerNode &node) throw(Error) 
     109{ 
     110    ContainerNode this_node = node.readContainer("AccountCallConfig"); 
     111 
     112    NODE_READ_NUM_T   ( this_node, pjsua_call_hold_type, holdType); 
     113    NODE_READ_NUM_T   ( this_node, pjsua_100rel_use, prackUse); 
     114    NODE_READ_NUM_T   ( this_node, pjsua_sip_timer_use, timerUse); 
     115    NODE_READ_UNSIGNED( this_node, timerMinSESec); 
     116    NODE_READ_UNSIGNED( this_node, timerSessExpiresSec); 
     117} 
     118 
     119void AccountCallConfig::writeObject(ContainerNode &node) const throw(Error) 
     120{ 
     121    ContainerNode this_node = node.writeNewContainer("AccountCallConfig"); 
     122 
     123    NODE_WRITE_NUM_T   ( this_node, pjsua_call_hold_type, holdType); 
     124    NODE_WRITE_NUM_T   ( this_node, pjsua_100rel_use, prackUse); 
     125    NODE_WRITE_NUM_T   ( this_node, pjsua_sip_timer_use, timerUse); 
     126    NODE_WRITE_UNSIGNED( this_node, timerMinSESec); 
     127    NODE_WRITE_UNSIGNED( this_node, timerSessExpiresSec); 
     128} 
     129 
     130/////////////////////////////////////////////////////////////////////////////// 
     131 
     132void AccountPresConfig::readObject(const ContainerNode &node) throw(Error) 
     133{ 
     134    ContainerNode this_node = node.readContainer("AccountPresConfig"); 
     135 
     136    NODE_READ_BOOL    ( this_node, publishEnabled); 
     137    NODE_READ_BOOL    ( this_node, publishQueue); 
     138    NODE_READ_UNSIGNED( this_node, publishShutdownWaitMsec); 
     139    NODE_READ_STRING  ( this_node, pidfTupleId); 
     140 
     141    readSipHeaders(this_node, "headers", headers); 
     142} 
     143 
     144void AccountPresConfig::writeObject(ContainerNode &node) const throw(Error) 
     145{ 
     146    ContainerNode this_node = node.writeNewContainer("AccountPresConfig"); 
     147 
     148    NODE_WRITE_BOOL    ( this_node, publishEnabled); 
     149    NODE_WRITE_BOOL    ( this_node, publishQueue); 
     150    NODE_WRITE_UNSIGNED( this_node, publishShutdownWaitMsec); 
     151    NODE_WRITE_STRING  ( this_node, pidfTupleId); 
     152 
     153    writeSipHeaders(this_node, "headers", headers); 
     154} 
     155 
     156/////////////////////////////////////////////////////////////////////////////// 
     157 
     158void AccountMwiConfig::readObject(const ContainerNode &node) throw(Error) 
     159{ 
     160    ContainerNode this_node = node.readContainer("AccountMwiConfig"); 
     161 
     162    NODE_READ_BOOL    ( this_node, enabled); 
     163    NODE_READ_UNSIGNED( this_node, expirationSec); 
     164} 
     165 
     166void AccountMwiConfig::writeObject(ContainerNode &node) const throw(Error) 
     167{ 
     168    ContainerNode this_node = node.writeNewContainer("AccountMwiConfig"); 
     169 
     170    NODE_WRITE_BOOL    ( this_node, enabled); 
     171    NODE_WRITE_UNSIGNED( this_node, expirationSec); 
     172} 
     173 
     174/////////////////////////////////////////////////////////////////////////////// 
     175 
     176void AccountNatConfig::readObject(const ContainerNode &node) throw(Error) 
     177{ 
     178    ContainerNode this_node = node.readContainer("AccountNatConfig"); 
     179 
     180    NODE_READ_NUM_T   ( this_node, pjsua_stun_use, sipStunUse); 
     181    NODE_READ_NUM_T   ( this_node, pjsua_stun_use, mediaStunUse); 
     182    NODE_READ_BOOL    ( this_node, iceEnabled); 
     183    NODE_READ_INT     ( this_node, iceMaxHostCands); 
     184    NODE_READ_BOOL    ( this_node, iceAggressiveNomination); 
     185    NODE_READ_UNSIGNED( this_node, iceNominatedCheckDelayMsec); 
     186    NODE_READ_INT     ( this_node, iceWaitNominationTimeoutMsec); 
     187    NODE_READ_BOOL    ( this_node, iceNoRtcp); 
     188    NODE_READ_BOOL    ( this_node, iceAlwaysUpdate); 
     189    NODE_READ_BOOL    ( this_node, turnEnabled); 
     190    NODE_READ_STRING  ( this_node, turnServer); 
     191    NODE_READ_NUM_T   ( this_node, pj_turn_tp_type, turnConnType); 
     192    NODE_READ_STRING  ( this_node, turnUserName); 
     193    NODE_READ_INT     ( this_node, turnPasswordType); 
     194    NODE_READ_STRING  ( this_node, turnPassword); 
     195    NODE_READ_INT     ( this_node, contactRewriteUse); 
     196    NODE_READ_INT     ( this_node, contactRewriteMethod); 
     197    NODE_READ_INT     ( this_node, viaRewriteUse); 
     198    NODE_READ_INT     ( this_node, sdpNatRewriteUse); 
     199    NODE_READ_INT     ( this_node, sipOutboundUse); 
     200    NODE_READ_STRING  ( this_node, sipOutboundInstanceId); 
     201    NODE_READ_STRING  ( this_node, sipOutboundRegId); 
     202    NODE_READ_UNSIGNED( this_node, udpKaIntervalSec); 
     203    NODE_READ_STRING  ( this_node, udpKaData); 
     204} 
     205 
     206void AccountNatConfig::writeObject(ContainerNode &node) const throw(Error) 
     207{ 
     208    ContainerNode this_node = node.writeNewContainer("AccountNatConfig"); 
     209 
     210    NODE_WRITE_NUM_T   ( this_node, pjsua_stun_use, sipStunUse); 
     211    NODE_WRITE_NUM_T   ( this_node, pjsua_stun_use, mediaStunUse); 
     212    NODE_WRITE_BOOL    ( this_node, iceEnabled); 
     213    NODE_WRITE_INT     ( this_node, iceMaxHostCands); 
     214    NODE_WRITE_BOOL    ( this_node, iceAggressiveNomination); 
     215    NODE_WRITE_UNSIGNED( this_node, iceNominatedCheckDelayMsec); 
     216    NODE_WRITE_INT     ( this_node, iceWaitNominationTimeoutMsec); 
     217    NODE_WRITE_BOOL    ( this_node, iceNoRtcp); 
     218    NODE_WRITE_BOOL    ( this_node, iceAlwaysUpdate); 
     219    NODE_WRITE_BOOL    ( this_node, turnEnabled); 
     220    NODE_WRITE_STRING  ( this_node, turnServer); 
     221    NODE_WRITE_NUM_T   ( this_node, pj_turn_tp_type, turnConnType); 
     222    NODE_WRITE_STRING  ( this_node, turnUserName); 
     223    NODE_WRITE_INT     ( this_node, turnPasswordType); 
     224    NODE_WRITE_STRING  ( this_node, turnPassword); 
     225    NODE_WRITE_INT     ( this_node, contactRewriteUse); 
     226    NODE_WRITE_INT     ( this_node, contactRewriteMethod); 
     227    NODE_WRITE_INT     ( this_node, viaRewriteUse); 
     228    NODE_WRITE_INT     ( this_node, sdpNatRewriteUse); 
     229    NODE_WRITE_INT     ( this_node, sipOutboundUse); 
     230    NODE_WRITE_STRING  ( this_node, sipOutboundInstanceId); 
     231    NODE_WRITE_STRING  ( this_node, sipOutboundRegId); 
     232    NODE_WRITE_UNSIGNED( this_node, udpKaIntervalSec); 
     233    NODE_WRITE_STRING  ( this_node, udpKaData); 
     234} 
     235 
     236/////////////////////////////////////////////////////////////////////////////// 
     237 
     238void AccountMediaConfig::readObject(const ContainerNode &node) throw(Error) 
     239{ 
     240    ContainerNode this_node = node.readContainer("AccountMediaConfig"); 
     241 
     242    NODE_READ_BOOL    ( this_node, lockCodecEnabled); 
     243    NODE_READ_BOOL    ( this_node, streamKaEnabled); 
     244    NODE_READ_NUM_T   ( this_node, pjmedia_srtp_use, srtpUse); 
     245    NODE_READ_INT     ( this_node, srtpSecureSignaling); 
     246    NODE_READ_NUM_T   ( this_node, pjsua_ipv6_use, ipv6Use); 
     247    NODE_READ_OBJ     ( this_node, transportConfig); 
     248} 
     249 
     250void AccountMediaConfig::writeObject(ContainerNode &node) const throw(Error) 
     251{ 
     252    ContainerNode this_node = node.writeNewContainer("AccountMediaConfig"); 
     253 
     254    NODE_WRITE_BOOL    ( this_node, lockCodecEnabled); 
     255    NODE_WRITE_BOOL    ( this_node, streamKaEnabled); 
     256    NODE_WRITE_NUM_T   ( this_node, pjmedia_srtp_use, srtpUse); 
     257    NODE_WRITE_INT     ( this_node, srtpSecureSignaling); 
     258    NODE_WRITE_NUM_T   ( this_node, pjsua_ipv6_use, ipv6Use); 
     259    NODE_WRITE_OBJ     ( this_node, transportConfig); 
     260} 
     261 
     262/////////////////////////////////////////////////////////////////////////////// 
     263 
     264void AccountVideoConfig::readObject(const ContainerNode &node) throw(Error) 
     265{ 
     266    ContainerNode this_node = node.readContainer("AccountVideoConfig"); 
     267 
     268    NODE_READ_BOOL    ( this_node, autoShowIncoming); 
     269    NODE_READ_BOOL    ( this_node, autoTransmitOutgoing); 
     270    NODE_READ_UNSIGNED( this_node, windowFlags); 
     271    NODE_READ_NUM_T   ( this_node, pjmedia_vid_dev_index, defaultCaptureDevice); 
     272    NODE_READ_NUM_T   ( this_node, pjmedia_vid_dev_index, defaultRenderDevice); 
     273    NODE_READ_NUM_T   ( this_node, pjmedia_vid_stream_rc_method, rateControlMethod); 
     274    NODE_READ_UNSIGNED( this_node, rateControlBandwidth); 
     275} 
     276 
     277void AccountVideoConfig::writeObject(ContainerNode &node) const throw(Error) 
     278{ 
     279    ContainerNode this_node = node.writeNewContainer("AccountVideoConfig"); 
     280 
     281    NODE_WRITE_BOOL    ( this_node, autoShowIncoming); 
     282    NODE_WRITE_BOOL    ( this_node, autoTransmitOutgoing); 
     283    NODE_WRITE_UNSIGNED( this_node, windowFlags); 
     284    NODE_WRITE_NUM_T   ( this_node, pjmedia_vid_dev_index, defaultCaptureDevice); 
     285    NODE_WRITE_NUM_T   ( this_node, pjmedia_vid_dev_index, defaultRenderDevice); 
     286    NODE_WRITE_NUM_T   ( this_node, pjmedia_vid_stream_rc_method, rateControlMethod); 
     287    NODE_WRITE_UNSIGNED( this_node, rateControlBandwidth); 
     288} 
    29289 
    30290/////////////////////////////////////////////////////////////////////////////// 
     
    331591} 
    332592 
     593void AccountConfig::readObject(const ContainerNode &node) throw(Error) 
     594{ 
     595    ContainerNode this_node = node.readContainer("AccountConfig"); 
     596 
     597    NODE_READ_INT     ( this_node, priority); 
     598    NODE_READ_STRING  ( this_node, idUri); 
     599    NODE_READ_OBJ     ( this_node, regConfig); 
     600    NODE_READ_OBJ     ( this_node, sipConfig); 
     601    NODE_READ_OBJ     ( this_node, callConfig); 
     602    NODE_READ_OBJ     ( this_node, presConfig); 
     603    NODE_READ_OBJ     ( this_node, mwiConfig); 
     604    NODE_READ_OBJ     ( this_node, natConfig); 
     605    NODE_READ_OBJ     ( this_node, mediaConfig); 
     606    NODE_READ_OBJ     ( this_node, videoConfig); 
     607} 
     608 
     609void AccountConfig::writeObject(ContainerNode &node) const throw(Error) 
     610{ 
     611    ContainerNode this_node = node.writeNewContainer("AccountConfig"); 
     612 
     613    NODE_WRITE_INT     ( this_node, priority); 
     614    NODE_WRITE_STRING  ( this_node, idUri); 
     615    NODE_WRITE_OBJ     ( this_node, regConfig); 
     616    NODE_WRITE_OBJ     ( this_node, sipConfig); 
     617    NODE_WRITE_OBJ     ( this_node, callConfig); 
     618    NODE_WRITE_OBJ     ( this_node, presConfig); 
     619    NODE_WRITE_OBJ     ( this_node, mwiConfig); 
     620    NODE_WRITE_OBJ     ( this_node, natConfig); 
     621    NODE_WRITE_OBJ     ( this_node, mediaConfig); 
     622    NODE_WRITE_OBJ     ( this_node, videoConfig); 
     623} 
     624 
     625 
    333626/////////////////////////////////////////////////////////////////////////////// 
    334627 
Note: See TracChangeset for help on using the changeset viewer.