- Timestamp:
- Nov 6, 2013 8:09:05 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/pjsua2/pjsip-apps/src/samples/pjsua2_demo.cpp
r4638 r4647 20 20 #include <iostream> 21 21 #include <memory> 22 #include <pj/file_access.h> 22 23 23 24 using namespace pj; … … 37 38 }; 38 39 39 static void mainProg () throw(Error)40 static void mainProg1() throw(Error) 40 41 { 41 42 Endpoint ep; … … 73 74 } 74 75 76 void mainProg2() throw(Error) 77 { 78 Endpoint ep; 79 80 // Create library 81 ep.libCreate(); 82 83 string json_str; 84 85 { 86 EpConfig epCfg; 87 JsonDocument jDoc; 88 89 epCfg.uaConfig.maxCalls = 61; 90 epCfg.uaConfig.userAgent = "Just JSON Test"; 91 epCfg.uaConfig.stunServer.push_back("stun1.pjsip.org"); 92 epCfg.uaConfig.stunServer.push_back("stun2.pjsip.org"); 93 epCfg.logConfig.filename = "THE.LOG"; 94 95 jDoc.writeObject(epCfg); 96 json_str = jDoc.saveString(); 97 std::cout << json_str << std::endl << std::endl; 98 } 99 100 { 101 EpConfig epCfg; 102 JsonDocument rDoc; 103 string output; 104 105 rDoc.loadString(json_str); 106 rDoc.readObject(epCfg); 107 108 JsonDocument wDoc; 109 110 wDoc.writeObject(epCfg); 111 json_str = wDoc.saveString(); 112 std::cout << json_str << std::endl << std::endl; 113 114 wDoc.saveFile("jsontest.js"); 115 } 116 117 { 118 EpConfig epCfg; 119 JsonDocument rDoc; 120 121 rDoc.loadFile("jsontest.js"); 122 rDoc.readObject(epCfg); 123 pj_file_delete("jsontest.js"); 124 } 125 126 ep.libDestroy(); 127 } 128 129 void mainProg() throw(Error) 130 { 131 Endpoint ep; 132 133 // Create library 134 ep.libCreate(); 135 136 string json_str; 137 138 { 139 JsonDocument jdoc; 140 AccountConfig accCfg; 141 142 accCfg.idUri = "\"Just Test\" <sip:test@pjsip.org>"; 143 accCfg.regConfig.registrarUri = "sip:pjsip.org"; 144 SipHeader h; 145 h.hName = "X-Header"; 146 h.hValue = "User header"; 147 accCfg.regConfig.headers.push_back(h); 148 149 accCfg.sipConfig.proxies.push_back("<sip:sip.pjsip.org;transport=tcp>"); 150 accCfg.sipConfig.proxies.push_back("<sip:sip.pjsip.org;transport=tls>"); 151 152 accCfg.mediaConfig.transportConfig.tlsConfig.ciphers.push_back(1); 153 accCfg.mediaConfig.transportConfig.tlsConfig.ciphers.push_back(2); 154 accCfg.mediaConfig.transportConfig.tlsConfig.ciphers.push_back(3); 155 156 AuthCredInfo aci; 157 aci.scheme = "digest"; 158 aci.username = "test"; 159 aci.data = "passwd"; 160 aci.realm = "*"; 161 accCfg.sipConfig.authCreds.push_back(aci); 162 163 jdoc.writeObject(accCfg); 164 json_str = jdoc.saveString(); 165 std::cout << "Original:" << std::endl; 166 std::cout << json_str << std::endl << std::endl; 167 } 168 169 { 170 JsonDocument rdoc; 171 172 rdoc.loadString(json_str); 173 AccountConfig accCfg; 174 rdoc.readObject(accCfg); 175 176 JsonDocument wdoc; 177 wdoc.writeObject(accCfg); 178 json_str = wdoc.saveString(); 179 180 std::cout << "Parsed:" << std::endl; 181 std::cout << json_str << std::endl << std::endl; 182 } 183 184 ep.libDestroy(); 185 } 186 75 187 int main() 76 188 { … … 79 191 try { 80 192 mainProg(); 193 std::cout << "Success" << std::endl; 81 194 } catch (Error & err) { 82 195 std::cout << "Exception: " << err.info() << std::endl;
Note: See TracChangeset
for help on using the changeset viewer.