/[resiprocate]/branches/b-identity-0505/Embedded.cxx
ViewVC logotype

Contents of /branches/b-identity-0505/Embedded.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4598 - (show annotations) (download)
Wed May 11 22:53:07 2005 UTC (14 years, 6 months ago) by derek
File size: 4238 byte(s)
set svn:eol-style to LF
1 #if defined(HAVE_CONFIG_H)
2 #include "resiprocate/config.hxx"
3 #endif
4
5
6 #include <cassert>
7
8 #include "resiprocate/Embedded.hxx"
9 #include "resiprocate/os/Data.hxx"
10 #include "resiprocate/Symbols.hxx"
11 #include "resiprocate/os/WinLeakCheck.hxx"
12
13 using namespace resip;
14
15 char fromHex(char h1, char h2)
16 {
17 h1 = toupper(h1);
18 h2 = toupper(h2);
19
20 int i1;
21 int i2;
22
23 if (isdigit(h1))
24 {
25 i1 = h1 - '0';
26 }
27 else
28 {
29 i1 = h1 - 'A' + 10;
30 }
31
32 if (isdigit(h2))
33 {
34 i2 = h2 - '0';
35 }
36 else
37 {
38 i2 = h2 - 'A' + 10;
39 }
40
41 return i1*16+i2;
42 }
43
44 char*
45 Embedded::decode(const Data& in, unsigned int& count)
46 {
47 const char *get = in.data();
48 const char *end = get + in.size();
49 char *ret = new char[in.size()];
50 char *put = ret;
51
52 count = 0;
53 while (get < end)
54 {
55 if (*get == Symbols::PERCENT[0] && get+2 < end)
56 {
57 *put = fromHex(*(get+1), *(get+2));
58 get += 3;
59 }
60 else
61 {
62 *put = *get;
63 get++;
64 }
65 count++;
66 put++;
67 }
68
69 return ret;
70 }
71
72 static char hexMap[] = "0123456789ABCDEF";
73
74 Data
75 Embedded::encode(const Data& dat)
76 {
77 Data out((int)(dat.size()*1.1), true);
78
79 {
80 DataStream str(out);
81 for (Data::size_type i = 0; i < dat.size(); i++)
82 {
83 switch (dat[i])
84 {
85 case ';' :
86 case '@' :
87 case '&' :
88 case '=' :
89 case ' ' :
90 case ',' :
91 case '%' :
92 {
93 str << Symbols::PERCENT;
94
95 unsigned char temp = dat[i];
96 int hi = (temp & 0xf0)>>4;
97 int low = (temp & 0xf);
98
99 str << hexMap[hi];
100 str << hexMap[low];
101 break;
102 }
103 default :
104 str << dat[i];
105 }
106 }
107 }
108
109 return out;
110 }
111 /* ====================================================================
112 * The Vovida Software License, Version 1.0
113 *
114 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
115 *
116 * Redistribution and use in source and binary forms, with or without
117 * modification, are permitted provided that the following conditions
118 * are met:
119 *
120 * 1. Redistributions of source code must retain the above copyright
121 * notice, this list of conditions and the following disclaimer.
122 *
123 * 2. Redistributions in binary form must reproduce the above copyright
124 * notice, this list of conditions and the following disclaimer in
125 * the documentation and/or other materials provided with the
126 * distribution.
127 *
128 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
129 * and "Vovida Open Communication Application Library (VOCAL)" must
130 * not be used to endorse or promote products derived from this
131 * software without prior written permission. For written
132 * permission, please contact vocal@vovida.org.
133 *
134 * 4. Products derived from this software may not be called "VOCAL", nor
135 * may "VOCAL" appear in their name, without prior written
136 * permission of Vovida Networks, Inc.
137 *
138 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
139 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
140 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
141 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
142 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
143 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
144 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
145 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
146 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
147 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
148 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
149 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
150 * DAMAGE.
151 *
152 * ====================================================================
153 *
154 * This software consists of voluntary contributions made by Vovida
155 * Networks, Inc. and many individuals on behalf of Vovida Networks,
156 * Inc. For more information on Vovida Networks, Inc., please see
157 * <http://www.vovida.org/>.
158 *
159 */

Properties

Name Value
svn:eol-style LF

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27