1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13 * express or implied.
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
17 */
18 // -*- c++ -*-
19 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
20
21 // P V S T R I N G URI C L A S S
22
23 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
24
25 // - - Inclusion - - - - - - - - - - - - - - - - - - - - - - - - - - - -
26
27 #include "pv_string_uri.h"
28 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
29
30
31 //////////////////////////////////////////////////////////////////////////////////////////////////////
PersentageToEscapedEncoding(char * aUrl,uint32 & aUrlMaxOutLength)32 OSCL_EXPORT_REF bool PVStringUri::PersentageToEscapedEncoding(char* aUrl, uint32 & aUrlMaxOutLength)
33 {
34 int32 err;
35 uint32 Url_Counter = 0;
36 uint32 Url_Tmp_Counter = 0;
37 aUrlMaxOutLength = 0;
38 mbchar* TempUrlBuffer = NULL;
39 uint32 iPersentage_Flag = false;
40 bool iRet = false;
41
42 OSCL_TRY(err, TempUrlBuffer = OSCL_ARRAY_NEW(mbchar, MAX_FULL_REQUEST_SIZE));
43 if ((err != OsclErrNone) || (TempUrlBuffer == NULL))
44 {
45 return false;
46 }
47
48 oscl_memset(TempUrlBuffer, 0, sizeof(TempUrlBuffer));
49 while (aUrl[Url_Counter] != '\0')
50 {
51
52 switch (aUrl[Url_Counter])
53 {
54 case PERSENTAGE:
55 {
56 if (!(aUrl[Url_Counter+1] == '2' && aUrl[Url_Counter+2] == '0') &&
57 !(aUrl[Url_Counter+1] == '2' && aUrl[Url_Counter+2] == '1') &&
58 !(aUrl[Url_Counter+1] == '2' && aUrl[Url_Counter+2] == 'A') &&
59 !(aUrl[Url_Counter+1] == '2' && aUrl[Url_Counter+2] == '7') &&
60 !(aUrl[Url_Counter+1] == '2' && aUrl[Url_Counter+2] == '8') &&
61 !(aUrl[Url_Counter+1] == '2' && aUrl[Url_Counter+2] == '9') &&
62 !(aUrl[Url_Counter+1] == '2' && aUrl[Url_Counter+2] == 'B') &&
63 !(aUrl[Url_Counter+1] == '2' && aUrl[Url_Counter+2] == '4') &&
64 !(aUrl[Url_Counter+1] == '2' && aUrl[Url_Counter+2] == '6') &&
65 !(aUrl[Url_Counter+1] == '2' && aUrl[Url_Counter+2] == 'C') &&
66 !(aUrl[Url_Counter+1] == '2' && aUrl[Url_Counter+2] == 'F') &&
67 !(aUrl[Url_Counter+1] == '2' && aUrl[Url_Counter+2] == '5') &&
68 !(aUrl[Url_Counter+1] == '2' && aUrl[Url_Counter+2] == '3') &&
69 !(aUrl[Url_Counter+1] == '3' && aUrl[Url_Counter+2] == 'A') &&
70 !(aUrl[Url_Counter+1] == '3' && aUrl[Url_Counter+2] == 'B') &&
71 !(aUrl[Url_Counter+1] == '3' && aUrl[Url_Counter+2] == 'D') &&
72 !(aUrl[Url_Counter+1] == '3' && aUrl[Url_Counter+2] == 'F') &&
73 !(aUrl[Url_Counter+1] == '5' && aUrl[Url_Counter+2] == 'B') &&
74 !(aUrl[Url_Counter+1] == '5' && aUrl[Url_Counter+2] == 'D') &&
75 !(aUrl[Url_Counter+1] == '4' && aUrl[Url_Counter+2] == '0'))
76 {
77 TempUrlBuffer[Url_Tmp_Counter] = '%';
78 TempUrlBuffer[++Url_Tmp_Counter] = '2';
79 TempUrlBuffer[++Url_Tmp_Counter] = '5';
80 break;
81 }
82 iPersentage_Flag = true;
83 break;
84 }
85 default :
86 TempUrlBuffer[Url_Tmp_Counter] = aUrl[Url_Counter];
87 break;
88 }
89
90 if (iPersentage_Flag)
91 {
92 TempUrlBuffer[Url_Tmp_Counter] = aUrl[Url_Counter];
93 iPersentage_Flag = false;
94 }
95 Url_Counter++;
96 Url_Tmp_Counter++;
97 }
98
99 TempUrlBuffer[Url_Tmp_Counter] = '\0';
100 if (TempUrlBuffer && *TempUrlBuffer)
101 {
102 oscl_memset(aUrl, 0, sizeof(aUrl));
103 oscl_strncpy(aUrl, TempUrlBuffer, (Url_Tmp_Counter));
104 aUrl[oscl_strlen(TempUrlBuffer)] = '\0';
105 aUrlMaxOutLength = Url_Tmp_Counter;
106 iRet = true;
107 }
108
109 OSCL_ARRAY_DELETE(TempUrlBuffer);
110 TempUrlBuffer = NULL;
111 return iRet;
112 }
113
114 ///////////////////////////////////////////////////////////////////////////////////////////////////////////
IllegalCharactersToEscapedEncoding(char * aUrl,uint32 & aUrlMaxOutLength)115 OSCL_EXPORT_REF bool PVStringUri::IllegalCharactersToEscapedEncoding(char* aUrl, uint32 &aUrlMaxOutLength)
116 {
117
118 int32 err;
119 uint32 Url_Counter = 0;
120 uint32 Url_Tmp_Counter = 0;
121 aUrlMaxOutLength = 0;
122 //mbchar IllegalTmpBuf[4];
123 unsigned char* IllegalTmpBuf = NULL;
124 uint32 Lenght = 0;
125 mbchar* TempUrlBuffer = NULL;
126 bool iRet = false;
127
128
129 OSCL_TRY(err, TempUrlBuffer = OSCL_ARRAY_NEW(mbchar, MAX_FULL_REQUEST_SIZE));
130 if ((err != OsclErrNone) || (TempUrlBuffer == NULL))
131 {
132 return false;
133 }
134
135
136 oscl_memset(TempUrlBuffer, 0, sizeof(TempUrlBuffer));
137
138 while (aUrl[Url_Counter] != '\0')
139 {
140 if (!(aUrl[Url_Counter] >= 63 && aUrl[Url_Counter] <= 91) &&
141 !(aUrl[Url_Counter] >= 97 && aUrl[Url_Counter] <= 122) &&
142 !(aUrl[Url_Counter] >= 35 && aUrl[Url_Counter] <= 59) &&
143 !(aUrl[Url_Counter] == 33) &&
144 !(aUrl[Url_Counter] == 61) &&
145 !(aUrl[Url_Counter] == 93) &&
146 !(aUrl[Url_Counter] == 95))
147 {
148 //Dec To Hexa Conversion
149
150 IllegalTmpBuf = DecimalToHexConverter(aUrl[Url_Counter] , Lenght);
151 TempUrlBuffer[Url_Tmp_Counter] = '%';
152 TempUrlBuffer[++Url_Tmp_Counter] = IllegalTmpBuf[1];
153 TempUrlBuffer[++Url_Tmp_Counter] = IllegalTmpBuf[2];
154 OSCL_ARRAY_DELETE(IllegalTmpBuf);
155 IllegalTmpBuf = NULL;
156 }
157
158 else
159 {
160 TempUrlBuffer[Url_Tmp_Counter] = aUrl[Url_Counter];
161
162
163 }
164
165 Url_Counter++;
166 Url_Tmp_Counter++;
167 }
168
169 TempUrlBuffer[Url_Tmp_Counter] = '\0';
170 if (TempUrlBuffer && *TempUrlBuffer)
171 {
172 oscl_memset(aUrl, 0, sizeof(aUrl));
173 oscl_strncpy(aUrl, TempUrlBuffer, Url_Tmp_Counter);
174 aUrl[oscl_strlen(TempUrlBuffer)] = '\0';
175
176 aUrlMaxOutLength = Url_Tmp_Counter;
177 iRet = true;
178 }
179
180 OSCL_ARRAY_DELETE(TempUrlBuffer);
181 TempUrlBuffer = NULL;
182 return iRet;
183 }
184
185 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
186
DecimalToHexConverter(unsigned char aNumberIn,uint32 & aUrlMaxConvertLenght)187 OSCL_EXPORT_REF unsigned char *PVStringUri::DecimalToHexConverter(unsigned char aNumberIn, uint32 & aUrlMaxConvertLenght)
188 {
189 unsigned char* FinalBuffer = NULL;
190 //FinalBuffer = 0;
191
192 unsigned char size = sizeof(unsigned char) * 2;
193 FinalBuffer = OSCL_ARRAY_NEW(unsigned char, (size + 2));
194
195 mbchar *LookUpTable = OSCL_CONST_CAST(mbchar*, "0123456789ABCDEF"); //corresponding index.
196 unsigned char Temp = aNumberIn;
197
198 FinalBuffer[0] = ' ';
199 unsigned char mask = 0x000f;
200
201 for (unsigned char Counter = 0; Counter < size; Counter++)
202 {
203 Temp = aNumberIn;
204 Temp >>= (4 * Counter);
205 Temp &= mask;
206 FinalBuffer[size - Counter] = LookUpTable[Temp];
207 }
208
209 FinalBuffer[size + 1] = '\0';
210 aUrlMaxConvertLenght = oscl_strlen((char*)FinalBuffer);
211 return FinalBuffer;
212 }
213
214