|
reSIProcate/stack
9694
|
00001 #include "resip/stack/Pidf.hxx" 00002 #include <iostream> 00003 #include "rutil/Logger.hxx" 00004 00005 using namespace resip; 00006 using namespace std; 00007 00008 #define CRLF "\r\n" 00009 00010 int 00011 main(int argc, char** argv) 00012 { 00013 //Log::initialize(Log::Cout, Log::Debug, argv[0]); 00014 00015 { 00016 cerr << "test truncated contents" << endl; 00017 const Data txt("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" CRLF 00018 "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\"" CRLF 00019 " entity=\"sip:qqqqll99200_AT_163.com@teltel.com\">" CRLF 00020 " <tuple id=\"qqqqll99200@163.com\" callstatus=\"0\" displayName=\"éæ\" status=\"1\">" CRLF 00021 " <status><basic>open</basic></status>" CRLF 00022 " <contact priority=\"0\">sip:qqqqll99200_AT_163.com@teltel.com</contact>" CRLF 00023 " <"); 00024 00025 try 00026 { 00027 HeaderFieldValue hfv(txt.data(), txt.size()); 00028 Mime type("application", "pidf+xml"); 00029 Pidf pc(hfv, type); 00030 assert(pc.getNumTuples() == 1); 00031 assert(false); 00032 } 00033 catch (BaseException& e) 00034 { 00035 resipCerr << "Caught: " << e << endl; 00036 } 00037 } 00038 00039 { 00040 //resip::Pidf::Tuple tuple; 00041 //tuple.status = true; 00042 //tuple.id = account; 00043 //tuple.contact = Data::from(from); 00044 //tuple.contactPriority = 0.0; 00045 //tuple.note = "test"; 00046 //pidf.getTuples().push_back(tuple); 00047 00048 Data txt ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" CRLF 00049 "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\"" CRLF 00050 " entity=\"sip:jason_AT_example.com@london.gloo.net\">" CRLF 00051 " <tuple id=\"jason@example.com\" >" CRLF // SPACE before > causes error 00052 " <status><basic>open</basic></status>" CRLF 00053 " <contact priority=\"0\">sip:jason_AT_example.com@london.gloo.net</contact>" CRLF 00054 " <note>test</note>" CRLF 00055 " </tuple>" CRLF 00056 "</presence>"); 00057 00058 HeaderFieldValue hfv(txt.data(), txt.size()); 00059 Mime type("application", "pidf+xml"); 00060 Pidf pc(hfv, type); 00061 assert(pc.getNumTuples() == 1); 00062 } 00063 00064 //Test namespace support 00065 { 00066 00067 Data txt ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" CRLF 00068 "<pr:presence xmlns:pr=\"urn:ietf:params:xml:ns:pidf\">" CRLF 00069 " <pr:tuple>" CRLF 00070 " <pr:status>" CRLF 00071 " <pr:basic>open</pr:basic>" CRLF 00072 " <pr:contact priority=\"0\">sip:jason_AT_example.com@london.gloo.net</pr:contact>" CRLF 00073 " <pr:note>test</pr:note>" CRLF 00074 " </pr:status>" CRLF 00075 " </pr:tuple>" CRLF 00076 "</pr:presence>"); 00077 00078 HeaderFieldValue hfv(txt.data(), txt.size()); 00079 Mime type("application", "pidf+xml"); 00080 Pidf pc(hfv, type); 00081 pc.checkParsed(); 00082 assert(pc.getNumTuples() == 1); 00083 } 00084 { 00085 // http://www.imppwg.org/ml-archive/IMPP-WG/200204/msg00094.html 00086 00087 const Data txt("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" CRLF 00088 "<presence xmlns=\"urn:ietf:params:xml:ns:cpim-pidf:\"" CRLF 00089 "xmlns:im=\"urn:ietf:params:xml:ns:cpim-pidf:im\"" CRLF 00090 "xmlns:myex=\"http://id.mycompany.com/cpim-presence/\" " CRLF 00091 "entity=\"pres:someone@example.com\">" CRLF 00092 " <tuple id=\"mobile-im\" display=\"displayed\">" CRLF 00093 " <status>" CRLF 00094 " <basic>open</basic>" CRLF 00095 " <im:im>busy</im:im>" CRLF 00096 " <myex:location>home</myex:location>" CRLF 00097 " </status>" CRLF 00098 " <contact priority=\"0.2\">im:someone@mobilecarrier.net</contact>" CRLF 00099 " <note xml:lang=\"en\">Don't Disturb Please!</note>" CRLF 00100 " <note xml:lang=\"fr\">Ne dérangez pas, s'il vous plait</note>" CRLF 00101 " <timestamp>2001-10-27T16:49:29Z</timestamp>" CRLF 00102 " </tuple>" CRLF 00103 " <tuple id=\"email\">" CRLF 00104 " <status>" CRLF 00105 " <basic>open</basic>" CRLF 00106 " </status>" CRLF 00107 " <contact priority=\"0.1\">mailto:someone@example.com</contact>" CRLF 00108 " </tuple>" CRLF 00109 " <note xml:lang=\"en\">I'll be in Tokyo next week</note>" CRLF 00110 "</presence>"); 00111 00112 HeaderFieldValue hfv(txt.data(), txt.size()); 00113 Mime type("application", "pidf+xml"); 00114 Pidf pc(hfv, type); 00115 00116 cerr << "!! " << pc.getEntity() << endl; 00117 assert(pc.getEntity() == Uri("pres:someone@example.com")); 00118 00119 assert(pc.getNumTuples() == 2); 00120 assert(pc.getTuples()[0].id == "mobile-im"); 00121 assert(pc.getTuples()[0].attributes["display"] == "displayed"); 00122 assert(pc.getTuples()[0].status); 00123 assert(pc.getTuples()[0].contact == "im:someone@mobilecarrier.net"); 00124 #ifndef RESIP_FIXED_POINT 00125 assert(pc.getTuples()[0].contactPriority == 0.2); 00126 #else 00127 assert(pc.getTuples()[0].contactPriority == 200); 00128 #endif 00129 assert(pc.getTuples()[0].note == "Ne dérangez pas, s'il vous plait"); 00130 assert(pc.getTuples()[0].timeStamp == "2001-10-27T16:49:29Z"); 00131 00132 pc.encodeParsed(resipCerr); 00133 } 00134 00135 { 00136 cerr << "Test merge" << endl; 00137 00138 const Data txt1("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" CRLF 00139 "<presence xmlns=\"urn:ietf:params:xml:ns:cpim-pidf:\"" CRLF 00140 "xmlns:im=\"urn:ietf:params:xml:ns:cpim-pidf:im\"" CRLF 00141 "xmlns:myex=\"http://id.mycompany.com/cpim-presence/\" " CRLF 00142 "entity=\"pres:someone@example.com\">" CRLF 00143 " <tuple id=\"mobile-im1\" display=\"displayed\">" CRLF 00144 " <status>" CRLF 00145 " <basic>open</basic>" CRLF 00146 " <im:im>busy</im:im>" CRLF 00147 " <myex:location>home</myex:location>" CRLF 00148 " </status>" CRLF 00149 " <contact priority=\"0.2\">im:someone@mobilecarrier.net</contact>" CRLF 00150 " <note xml:lang=\"en\">Don't Disturb Please!</note>" CRLF 00151 " <note xml:lang=\"fr\">Ne dérangez pas, s'il vous plait</note>" CRLF 00152 " <timestamp>2001-10-27T16:49:29Z</timestamp>" CRLF 00153 " </tuple>" CRLF 00154 " <tuple id=\"email1\">" CRLF 00155 " <status>" CRLF 00156 " <basic>open</basic>" CRLF 00157 " </status>" CRLF 00158 " <contact priority=\"0.1\">mailto:someone@exapmle.com</contact>" CRLF 00159 " </tuple>" CRLF 00160 " <note xml:lang=\"en\">I'll be in Tokyo next week</note>" CRLF 00161 "</presence>"); 00162 00163 Mime type("application", "pidf+xml"); 00164 00165 HeaderFieldValue hfv1(txt1.data(), txt1.size()); 00166 Pidf pc1(hfv1, type); 00167 00168 const Data txt2("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" CRLF 00169 "<presence xmlns=\"urn:ietf:params:xml:ns:cpim-pidf:\"" CRLF 00170 "xmlns:im=\"urn:ietf:params:xml:ns:cpim-pidf:im\"" CRLF 00171 "xmlns:myex=\"http://id.mycompany.com/cpim-presence/\" " CRLF 00172 "entity=\"pres:someone@example.com\">" CRLF 00173 " <tuple id=\"mobile-im2\" display=\"displayed\">" CRLF 00174 " <status>" CRLF 00175 " <basic>open</basic>" CRLF 00176 " <im:im>busy</im:im>" CRLF 00177 " <myex:location>home</myex:location>" CRLF 00178 " </status>" CRLF 00179 " <contact priority=\"0.4\">im:someone@mobilecarrier.net</contact>" CRLF 00180 " <note xml:lang=\"en\">Don't Disturb Please!</note>" CRLF 00181 " <note xml:lang=\"fr\">Ne dérangez pas, s'il vous plait</note>" CRLF 00182 " <timestamp>2002-10-27T16:49:29Z</timestamp>" CRLF 00183 " </tuple>" CRLF 00184 " <tuple id=\"email2\">" CRLF 00185 " <status>" CRLF 00186 " <basic>open</basic>" CRLF 00187 " </status>" CRLF 00188 " <contact priority=\"0.1\">mailto:someone@exapmle.com</contact>" CRLF 00189 " </tuple>" CRLF 00190 " <note xml:lang=\"en\">I'll be in Tokyo next week</note>" CRLF 00191 "</presence>"); 00192 00193 HeaderFieldValue hfv2(txt2.data(), txt2.size()); 00194 Pidf pc2(hfv2, type); 00195 00196 Pidf* n = new Pidf; 00197 00198 n->merge(pc1); 00199 00200 cerr << "!! " << n->getEntity() << endl; 00201 assert(n->getEntity() == Uri("pres:someone@example.com")); 00202 00203 assert(n->getNumTuples() == 2); 00204 assert(n->getTuples()[0].id == "mobile-im1"); 00205 assert(n->getTuples()[0].attributes["display"] == "displayed"); 00206 assert(n->getTuples()[0].status); 00207 assert(n->getTuples()[0].contact == "im:someone@mobilecarrier.net"); 00208 #ifndef RESIP_FIXED_POINT 00209 assert(n->getTuples()[0].contactPriority == 0.2); 00210 #else 00211 assert(n->getTuples()[0].contactPriority == 200); 00212 #endif 00213 assert(n->getTuples()[0].note == "Ne dérangez pas, s'il vous plait"); 00214 assert(n->getTuples()[0].timeStamp == "2001-10-27T16:49:29Z"); 00215 00216 n->encodeParsed(resipCerr); 00217 00218 n->merge(pc2); 00219 00220 assert(n->getNumTuples() == 4); 00221 assert(n->getTuples()[2].id == "mobile-im2"); 00222 assert(n->getTuples()[2].attributes["display"] == "displayed"); 00223 assert(n->getTuples()[2].status); 00224 assert(n->getTuples()[2].contact == "im:someone@mobilecarrier.net"); 00225 #ifndef RESIP_FIXED_POINT 00226 assert(n->getTuples()[2].contactPriority == 0.4); 00227 #else 00228 assert(n->getTuples()[2].contactPriority == 400); 00229 #endif 00230 assert(n->getTuples()[2].note == "Ne dérangez pas, s'il vous plait"); 00231 assert(n->getTuples()[2].timeStamp == "2002-10-27T16:49:29Z"); 00232 00233 n->encodeParsed(resipCerr); 00234 } 00235 { 00236 resip::Pidf pidf; 00237 resip::Uri aor("sip:jason@example.com"); 00238 pidf.setEntity(aor); 00239 00240 resip::Pidf::Tuple tuple; 00241 tuple.status = true; 00242 tuple.id = "test id"; 00243 tuple.contact = Data::from(aor); 00244 tuple.contactPriority = (int)0; 00245 tuple.note = "Away"; 00246 tuple.attributes["displayname"] = "displayName"; 00247 tuple.attributes["status"] = "1"; 00248 00249 pidf.getTuples().push_back(tuple); 00250 std::cerr << Data::from(pidf) << std::endl; 00251 } 00252 00253 00254 cerr << "All OK" << endl; 00255 return 0; 00256 } 00257 00258 /* ==================================================================== 00259 * The Vovida Software License, Version 1.0 00260 * 00261 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00262 * 00263 * Redistribution and use in source and binary forms, with or without 00264 * modification, are permitted provided that the following conditions 00265 * are met: 00266 * 00267 * 1. Redistributions of source code must retain the above copyright 00268 * notice, this list of conditions and the following disclaimer. 00269 * 00270 * 2. Redistributions in binary form must reproduce the above copyright 00271 * notice, this list of conditions and the following disclaimer in 00272 * the documentation and/or other materials provided with the 00273 * distribution. 00274 * 00275 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00276 * and "Vovida Open Communication Application Library (VOCAL)" must 00277 * not be used to endorse or promote products derived from this 00278 * software without prior written permission. For written 00279 * permission, please contact vocal@vovida.org. 00280 * 00281 * 4. Products derived from this software may not be called "VOCAL", nor 00282 * may "VOCAL" appear in their name, without prior written 00283 * permission of Vovida Networks, Inc. 00284 * 00285 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00286 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00287 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00288 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00289 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00290 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00291 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00292 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00293 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00294 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00295 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00296 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00297 * DAMAGE. 00298 * 00299 * ==================================================================== 00300 * 00301 * This software consists of voluntary contributions made by Vovida 00302 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00303 * Inc. For more information on Vovida Networks, Inc., please see 00304 * <http://www.vovida.org/>. 00305 * 00306 */
1.7.5.1