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 #ifndef PVMI_KVP_UTIL_H_INCLUDED
19 #include "pvmi_kvp_util.h"
20 #endif
21
22 #ifndef OSCL_MIME_STRING_UTILS_H
23 #include "pv_mime_string_utils.h"
24 #endif
25
26 #ifndef OSCL_STRING_CONTAINERS_H_INCLUDED
27 #include "oscl_string_containers.h"
28 #endif
29
30 #ifndef OSCL_EXCLUSIVE_PTR_H_INCLUDED
31 #include "oscl_exclusive_ptr.h"
32 #endif
33
GetTypeFromKeyString(PvmiKeyType aKeyString)34 OSCL_EXPORT_REF PvmiKvpType GetTypeFromKeyString(PvmiKeyType aKeyString)
35 {
36 if (aKeyString == NULL)
37 {
38 return PVMI_KVPTYPE_UNKNOWN;
39 }
40
41 // Determine the type
42 char* paramstr = NULL;
43 OSCL_StackString<24> typestr;
44 OSCL_StackString<10> basestr(PVMI_KVPTYPE_STRING_CONSTCHAR);
45
46 // value
47 typestr = basestr;
48 typestr += PVMI_KVPTYPE_VALUE_STRING_CONSTCHAR;
49 if (pv_mime_string_parse_param(aKeyString, typestr.get_str(), paramstr) > 0)
50 {
51 return PVMI_KVPTYPE_VALUE;
52 }
53
54 // pointer
55 typestr = basestr;
56 typestr += PVMI_KVPTYPE_POINTER_STRING_CONSTCHAR;
57 if (pv_mime_string_parse_param(aKeyString, typestr.get_str(), paramstr) > 0)
58 {
59 return PVMI_KVPTYPE_POINTER;
60 }
61
62 // aggregate
63 typestr = basestr;
64 typestr += PVMI_KVPTYPE_AGGREGATE_STRING_CONSTCHAR;
65 if (pv_mime_string_parse_param(aKeyString, typestr.get_str(), paramstr) > 0)
66 {
67 return PVMI_KVPTYPE_AGGREGATE;
68 }
69
70 return PVMI_KVPTYPE_UNKNOWN;
71 }
72
73
GetAttrTypeFromKeyString(PvmiKeyType aKeyString)74 OSCL_EXPORT_REF PvmiKvpAttr GetAttrTypeFromKeyString(PvmiKeyType aKeyString)
75 {
76 if (aKeyString == NULL)
77 {
78 return PVMI_KVPATTR_UNKNOWN;
79 }
80
81 // Determine the attribute type
82 char* paramstr = NULL;
83 OSCL_StackString<16> attrstr;
84 OSCL_StackString<8> basestr(PVMI_KVPATTR_STRING_CONSTCHAR);
85
86 // cap
87 attrstr = basestr;
88 attrstr += PVMI_KVPATTR_CAP_STRING_CONSTCHAR;
89 if (pv_mime_string_parse_param(aKeyString, attrstr.get_str(), paramstr) > 0)
90 {
91 return PVMI_KVPATTR_CAP;
92 }
93 // def
94 attrstr = basestr;
95 attrstr += PVMI_KVPATTR_DEF_STRING_CONSTCHAR;
96 if (pv_mime_string_parse_param(aKeyString, attrstr.get_str(), paramstr) > 0)
97 {
98 return PVMI_KVPATTR_DEF;
99 }
100 // cur
101 attrstr = basestr;
102 attrstr += PVMI_KVPATTR_CUR_STRING_CONSTCHAR;
103 if (pv_mime_string_parse_param(aKeyString, attrstr.get_str(), paramstr) > 0)
104 {
105 return PVMI_KVPATTR_CUR;
106 }
107
108 return PVMI_KVPATTR_UNKNOWN;
109 }
110
111
GetValTypeFromKeyString(PvmiKeyType aKeyString)112 OSCL_EXPORT_REF PvmiKvpValueType GetValTypeFromKeyString(PvmiKeyType aKeyString)
113 {
114 if (aKeyString == NULL)
115 {
116 return PVMI_KVPVALTYPE_UNKNOWN;
117 }
118
119 // Determine the valtype
120 char* paramstr = NULL;
121 OSCL_StackString<64> valtypestr;
122 OSCL_StackString<10> basestr(PVMI_KVPVALTYPE_STRING_CONSTCHAR);
123
124 // bool
125 valtypestr = basestr;
126 valtypestr += PVMI_KVPVALTYPE_BOOL_STRING_CONSTCHAR;
127 if (pv_mime_string_parse_param(aKeyString, valtypestr.get_str(), paramstr) > 0)
128 {
129 return PVMI_KVPVALTYPE_BOOL;
130 }
131 // float
132 valtypestr = basestr;
133 valtypestr += PVMI_KVPVALTYPE_FLOAT_STRING_CONSTCHAR;
134 if (pv_mime_string_parse_param(aKeyString, valtypestr.get_str(), paramstr) > 0)
135 {
136 return PVMI_KVPVALTYPE_FLOAT;
137 }
138 // double
139 valtypestr = basestr;
140 valtypestr += PVMI_KVPVALTYPE_DOUBLE_STRING_CONSTCHAR;
141 if (pv_mime_string_parse_param(aKeyString, valtypestr.get_str(), paramstr) > 0)
142 {
143 return PVMI_KVPVALTYPE_DOUBLE;
144 }
145 // uint8
146 valtypestr = basestr;
147 valtypestr += PVMI_KVPVALTYPE_UINT8_STRING_CONSTCHAR;
148 if (pv_mime_string_parse_param(aKeyString, valtypestr.get_str(), paramstr) > 0)
149 {
150 return PVMI_KVPVALTYPE_UINT8;
151 }
152 // int32
153 valtypestr = basestr;
154 valtypestr += PVMI_KVPVALTYPE_INT32_STRING_CONSTCHAR;
155 if (pv_mime_string_parse_param(aKeyString, valtypestr.get_str(), paramstr) > 0)
156 {
157 return PVMI_KVPVALTYPE_INT32;
158 }
159 // uint32
160 valtypestr = basestr;
161 valtypestr += PVMI_KVPVALTYPE_UINT32_STRING_CONSTCHAR;
162 if (pv_mime_string_parse_param(aKeyString, valtypestr.get_str(), paramstr) > 0)
163 {
164 return PVMI_KVPVALTYPE_UINT32;
165 }
166 // int64
167 valtypestr = basestr;
168 valtypestr += PVMI_KVPVALTYPE_INT64_STRING_CONSTCHAR;
169 if (pv_mime_string_parse_param(aKeyString, valtypestr.get_str(), paramstr) > 0)
170 {
171 return PVMI_KVPVALTYPE_INT32;
172 }
173 // uint64
174 valtypestr = basestr;
175 valtypestr += PVMI_KVPVALTYPE_UINT64_STRING_CONSTCHAR;
176 if (pv_mime_string_parse_param(aKeyString, valtypestr.get_str(), paramstr) > 0)
177 {
178 return PVMI_KVPVALTYPE_UINT32;
179 }
180 // wchar*
181 valtypestr = basestr;
182 valtypestr += PVMI_KVPVALTYPE_WCHARPTR_STRING_CONSTCHAR;
183 if (pv_mime_string_parse_param(aKeyString, valtypestr.get_str(), paramstr) > 0)
184 {
185 return PVMI_KVPVALTYPE_WCHARPTR;
186 }
187 // char*
188 valtypestr = basestr;
189 valtypestr += PVMI_KVPVALTYPE_CHARPTR_STRING_CONSTCHAR;
190 if (pv_mime_string_parse_param(aKeyString, valtypestr.get_str(), paramstr) > 0)
191 {
192 return PVMI_KVPVALTYPE_CHARPTR;
193 }
194 // uint8*
195 valtypestr = basestr;
196 valtypestr += PVMI_KVPVALTYPE_UINT8PTR_STRING_CONSTCHAR;
197 if (pv_mime_string_parse_param(aKeyString, valtypestr.get_str(), paramstr) > 0)
198 {
199 return PVMI_KVPVALTYPE_UINT8PTR;
200 }
201 // int32*
202 valtypestr = basestr;
203 valtypestr += PVMI_KVPVALTYPE_INT32PTR_STRING_CONSTCHAR;
204 if (pv_mime_string_parse_param(aKeyString, valtypestr.get_str(), paramstr) > 0)
205 {
206 return PVMI_KVPVALTYPE_INT32PTR;
207 }
208 // uint32*
209 valtypestr = basestr;
210 valtypestr += PVMI_KVPVALTYPE_UINT32PTR_STRING_CONSTCHAR;
211 if (pv_mime_string_parse_param(aKeyString, valtypestr.get_str(), paramstr) > 0)
212 {
213 return PVMI_KVPVALTYPE_UINT32PTR;
214 }
215 // int64*
216 valtypestr = basestr;
217 valtypestr += PVMI_KVPVALTYPE_INT64PTR_STRING_CONSTCHAR;
218 if (pv_mime_string_parse_param(aKeyString, valtypestr.get_str(), paramstr) > 0)
219 {
220 return PVMI_KVPVALTYPE_INT64PTR;
221 }
222 // uint64*
223 valtypestr = basestr;
224 valtypestr += PVMI_KVPVALTYPE_UINT64PTR_STRING_CONSTCHAR;
225 if (pv_mime_string_parse_param(aKeyString, valtypestr.get_str(), paramstr) > 0)
226 {
227 return PVMI_KVPVALTYPE_UINT64PTR;
228 }
229 // float*
230 valtypestr = basestr;
231 valtypestr += PVMI_KVPVALTYPE_FLOATPTR_STRING_CONSTCHAR;
232 if (pv_mime_string_parse_param(aKeyString, valtypestr.get_str(), paramstr) > 0)
233 {
234 return PVMI_KVPVALTYPE_FLOATPTR;
235 }
236 // double*
237 valtypestr = basestr;
238 valtypestr += PVMI_KVPVALTYPE_DOUBLEPTR_STRING_CONSTCHAR;
239 if (pv_mime_string_parse_param(aKeyString, valtypestr.get_str(), paramstr) > 0)
240 {
241 return PVMI_KVPVALTYPE_DOUBLEPTR;
242 }
243 // ksv
244 valtypestr = basestr;
245 valtypestr += PVMI_KVPVALTYPE_KSV_STRING_CONSTCHAR;
246 if (pv_mime_string_parse_param(aKeyString, valtypestr.get_str(), paramstr) > 0)
247 {
248 return PVMI_KVPVALTYPE_KSV;
249 }
250 // pKvp
251 valtypestr = basestr;
252 valtypestr += PVMI_KVPVALTYPE_PKVP_STRING_CONSTCHAR;
253 if (pv_mime_string_parse_param(aKeyString, valtypestr.get_str(), paramstr) > 0)
254 {
255 return PVMI_KVPVALTYPE_PKVP;
256 }
257 // ppKvp
258 valtypestr = basestr;
259 valtypestr += PVMI_KVPVALTYPE_PPKVP_STRING_CONSTCHAR;
260 if (pv_mime_string_parse_param(aKeyString, valtypestr.get_str(), paramstr) > 0)
261 {
262 return PVMI_KVPVALTYPE_PPKVP;
263 }
264 // range_float
265 valtypestr = basestr;
266 valtypestr += PVMI_KVPVALTYPE_RANGE_FLOAT_STRING_CONSTCHAR;
267 if (pv_mime_string_parse_param(aKeyString, valtypestr.get_str(), paramstr) > 0)
268 {
269 return PVMI_KVPVALTYPE_RANGE_FLOAT;
270 }
271 // range_double
272 valtypestr = basestr;
273 valtypestr += PVMI_KVPVALTYPE_RANGE_DOUBLE_STRING_CONSTCHAR;
274 if (pv_mime_string_parse_param(aKeyString, valtypestr.get_str(), paramstr) > 0)
275 {
276 return PVMI_KVPVALTYPE_RANGE_DOUBLE;
277 }
278 // range_uint8
279 valtypestr = basestr;
280 valtypestr += PVMI_KVPVALTYPE_RANGE_UINT8_STRING_CONSTCHAR;
281 if (pv_mime_string_parse_param(aKeyString, valtypestr.get_str(), paramstr) > 0)
282 {
283 return PVMI_KVPVALTYPE_RANGE_UINT8;
284 }
285 // range_int32
286 valtypestr = basestr;
287 valtypestr += PVMI_KVPVALTYPE_RANGE_INT32_STRING_CONSTCHAR;
288 if (pv_mime_string_parse_param(aKeyString, valtypestr.get_str(), paramstr) > 0)
289 {
290 return PVMI_KVPVALTYPE_RANGE_INT32;
291 }
292 // range_uint32
293 valtypestr = basestr;
294 valtypestr += PVMI_KVPVALTYPE_RANGE_UINT32_STRING_CONSTCHAR;
295 if (pv_mime_string_parse_param(aKeyString, valtypestr.get_str(), paramstr) > 0)
296 {
297 return PVMI_KVPVALTYPE_RANGE_UINT32;
298 }
299 // range_int64
300 valtypestr = basestr;
301 valtypestr += PVMI_KVPVALTYPE_RANGE_INT64_STRING_CONSTCHAR;
302 if (pv_mime_string_parse_param(aKeyString, valtypestr.get_str(), paramstr) > 0)
303 {
304 return PVMI_KVPVALTYPE_RANGE_INT64;
305 }
306 // range_uint64
307 valtypestr = basestr;
308 valtypestr += PVMI_KVPVALTYPE_RANGE_UINT64_STRING_CONSTCHAR;
309 if (pv_mime_string_parse_param(aKeyString, valtypestr.get_str(), paramstr) > 0)
310 {
311 return PVMI_KVPVALTYPE_RANGE_UINT64;
312 }
313 // bitarray32
314 valtypestr = basestr;
315 valtypestr += PVMI_KVPVALTYPE_BITARRAY32_STRING_CONSTCHAR;
316 if (pv_mime_string_parse_param(aKeyString, valtypestr.get_str(), paramstr) > 0)
317 {
318 return PVMI_KVPVALTYPE_BITARRAY32;
319 }
320 // bitarray64
321 valtypestr = basestr;
322 valtypestr += PVMI_KVPVALTYPE_BITARRAY64_STRING_CONSTCHAR;
323 if (pv_mime_string_parse_param(aKeyString, valtypestr.get_str(), paramstr) > 0)
324 {
325 return PVMI_KVPVALTYPE_BITARRAY64;
326 }
327
328 return PVMI_KVPVALTYPE_UNKNOWN;
329 }
330
CreateKVPForWStringValue(PvmiKvp & aKeyVal,const char * aKeyTypeString,OSCL_wString & aValString,char * aMiscKeyParam,uint32 aMaxSize,uint32 aTruncateFlag)331 OSCL_EXPORT_REF PVMFStatus PVMFCreateKVPUtils::CreateKVPForWStringValue(PvmiKvp& aKeyVal,
332 const char* aKeyTypeString,
333 OSCL_wString& aValString,
334 char* aMiscKeyParam,
335 uint32 aMaxSize,
336 uint32 aTruncateFlag)
337 {
338 // Check parameters
339 if (aKeyVal.key != NULL || aKeyTypeString == NULL || aValString.get_size() == 0)
340 {
341 return PVMFErrArgument;
342 }
343
344 aKeyVal.value.pWChar_value = NULL;
345 aKeyVal.key = NULL;
346
347 // Determine the length of strings
348 uint32 keylen = oscl_strlen(aKeyTypeString) + 1; // for key string and ";"
349 keylen += oscl_strlen(PVMI_KVPVALTYPE_STRING_CONSTCHAR); // for "valtype="
350 keylen += oscl_strlen(PVMI_KVPVALTYPE_WCHARPTR_STRING_CONSTCHAR) + 1; // for "wchar*" and NULL terminator
351 if (aMiscKeyParam)
352 {
353 keylen += oscl_strlen(aMiscKeyParam);
354 }
355 uint32 valuelen = aValString.get_size() + 1;
356
357 /* Allocate memory for the strings
358 "keyExclusivePtr" pointer is used to prevent any memory leak
359 in case some exception occurs while allocating memory for "value array" */
360
361 OsclExclusiveArrayPtr<char> keyExclusivePtr;
362 aKeyVal.key = OSCL_ARRAY_NEW(char, keylen);
363 keyExclusivePtr.set(aKeyVal.key);
364
365 if (aTruncateFlag)
366 {
367 if (aMaxSize < valuelen)
368 {
369 valuelen = aMaxSize + 1;
370 }
371 }
372 if (aMaxSize >= valuelen)
373 {
374 aKeyVal.value.pWChar_value = OSCL_ARRAY_NEW(oscl_wchar, valuelen);
375 }
376
377 keyExclusivePtr.release();
378 // Copy the key string
379 oscl_strncpy(aKeyVal.key, aKeyTypeString, oscl_strlen(aKeyTypeString) + 1);
380 oscl_strncat(aKeyVal.key, PVMI_KVP_SEMICOLON_STRING_CONSTCHAR, oscl_strlen(PVMI_KVP_SEMICOLON_STRING_CONSTCHAR));
381 oscl_strncat(aKeyVal.key, PVMI_KVPVALTYPE_STRING_CONSTCHAR, oscl_strlen(PVMI_KVPVALTYPE_STRING_CONSTCHAR));
382 oscl_strncat(aKeyVal.key, PVMI_KVPVALTYPE_WCHARPTR_STRING_CONSTCHAR, oscl_strlen(PVMI_KVPVALTYPE_WCHARPTR_STRING_CONSTCHAR));
383 if (aMiscKeyParam)
384 {
385 oscl_strncat(aKeyVal.key, aMiscKeyParam, oscl_strlen(aMiscKeyParam));
386 }
387 aKeyVal.key[keylen-1] = '\0';
388 // Copy the value
389 if (aKeyVal.value.pWChar_value != NULL)
390 {
391 oscl_strncpy(aKeyVal.value.pWChar_value, aValString.get_cstr(), valuelen);
392 aKeyVal.value.pWChar_value[valuelen-1] = '\0';
393 }
394 // Set the length and capacity
395 aKeyVal.length = valuelen;
396 aKeyVal.capacity = valuelen;
397
398 return PVMFSuccess;
399 }
400
401
CreateKVPForCharStringValue(PvmiKvp & aKeyVal,const char * aKeyTypeString,const char * aValString,char * aMiscKeyParam,uint32 aMaxSize,uint32 aTruncateFlag)402 OSCL_EXPORT_REF PVMFStatus PVMFCreateKVPUtils::CreateKVPForCharStringValue(PvmiKvp& aKeyVal,
403 const char* aKeyTypeString,
404 const char* aValString,
405 char* aMiscKeyParam,
406 uint32 aMaxSize,
407 uint32 aTruncateFlag)
408 {
409 // Check parameters
410 if (aKeyVal.key != NULL || aKeyTypeString == NULL)
411 {
412 return PVMFErrArgument;
413 }
414
415 aKeyVal.value.pChar_value = NULL;
416 aKeyVal.key = NULL;
417
418 // Determine the length of strings
419 uint32 keylen = oscl_strlen(aKeyTypeString) + 1; // for key string and ";"
420 keylen += oscl_strlen(PVMI_KVPVALTYPE_STRING_CONSTCHAR); // for "valtype="
421 keylen += oscl_strlen(PVMI_KVPVALTYPE_CHARPTR_STRING_CONSTCHAR) + 1; // for "char*" and NULL terminator
422 if (aMiscKeyParam)
423 {
424 keylen += oscl_strlen(aMiscKeyParam);
425 }
426
427 uint32 valuelen = oscl_strlen(aValString) + 1;
428 /* keyExclusivePtr" pointer is used to prevent any memory leak
429 in case some exception occurs while allocating memory for "value array" */
430 OsclExclusiveArrayPtr<char> keyExclusivePtr;
431 aKeyVal.key = OSCL_ARRAY_NEW(char, keylen);
432 keyExclusivePtr.set(aKeyVal.key);
433
434 if (aTruncateFlag)
435 {
436 if (aMaxSize < valuelen)
437 {
438 valuelen = aMaxSize + 1;
439 }
440
441 }
442 if (aMaxSize >= valuelen)
443 aKeyVal.value.pChar_value = OSCL_ARRAY_NEW(char, valuelen);
444
445 keyExclusivePtr.release();
446 // Copy the key string
447 oscl_strncpy(aKeyVal.key, aKeyTypeString, oscl_strlen(aKeyTypeString) + 1);
448 oscl_strncat(aKeyVal.key, PVMI_KVP_SEMICOLON_STRING_CONSTCHAR, oscl_strlen(PVMI_KVP_SEMICOLON_STRING_CONSTCHAR));
449 oscl_strncat(aKeyVal.key, PVMI_KVPVALTYPE_STRING_CONSTCHAR, oscl_strlen(PVMI_KVPVALTYPE_STRING_CONSTCHAR));
450 oscl_strncat(aKeyVal.key, PVMI_KVPVALTYPE_CHARPTR_STRING_CONSTCHAR, oscl_strlen(PVMI_KVPVALTYPE_CHARPTR_STRING_CONSTCHAR));
451 if (aMiscKeyParam)
452 {
453 oscl_strncat(aKeyVal.key, aMiscKeyParam, oscl_strlen(aMiscKeyParam));
454 }
455 aKeyVal.key[keylen-1] = '\0';
456 // Copy the value
457 if (aKeyVal.value.pChar_value != NULL)
458 {
459 oscl_strncpy(aKeyVal.value.pChar_value, aValString, valuelen);
460 aKeyVal.value.pChar_value[valuelen-1] = '\0';
461 }
462 // Set the length and capacity
463 aKeyVal.length = valuelen;
464 aKeyVal.capacity = valuelen;
465
466 return PVMFSuccess;
467 }
468
CreateKVPForByteArrayValue(PvmiKvp & aKeyVal,const char * aKeyTypeString,uint8 * aValue,uint32 aValueLen,char * aMiscKeyParam,uint32 aMaxSize)469 OSCL_EXPORT_REF PVMFStatus PVMFCreateKVPUtils::CreateKVPForByteArrayValue(PvmiKvp& aKeyVal,
470 const char* aKeyTypeString,
471 uint8* aValue,
472 uint32 aValueLen,
473 char* aMiscKeyParam,
474 uint32 aMaxSize)
475 {
476 OSCL_UNUSED_ARG(aMaxSize);
477 /* Check parameters */
478 if (aKeyVal.key != NULL || aKeyTypeString == NULL || aValueLen == 0)
479 {
480 return PVMFErrArgument;
481 }
482
483 /* Determine the length of strings */
484 uint32 keylen = oscl_strlen(aKeyTypeString) + 1; // for key string and ";"
485 keylen += oscl_strlen(PVMI_KVPVALTYPE_STRING_CONSTCHAR); // for "valtype="
486 keylen += oscl_strlen(PVMI_KVPVALTYPE_UINT8PTR_STRING_CONSTCHAR) + 1; // for "char*" and NULL terminator
487 if (aMiscKeyParam)
488 {
489 keylen += oscl_strlen(aMiscKeyParam);
490 }
491
492 /* Allocate memory for the strings
493 "keyExclusivePtr" pointer is used to prevent any memory leak
494 in case some exception occurs while allocating memory for "value array" */
495 OsclExclusiveArrayPtr<char> keyExclusivePtr;
496 aKeyVal.key = OSCL_ARRAY_NEW(char, keylen);
497 keyExclusivePtr.set(aKeyVal.key);
498 aKeyVal.value.pUint8_value = OSCL_ARRAY_NEW(uint8, aValueLen);
499 keyExclusivePtr.release();
500
501 /* Copy the key string */
502 oscl_strncpy(aKeyVal.key,
503 aKeyTypeString,
504 oscl_strlen(aKeyTypeString) + 1);
505 oscl_strncat(aKeyVal.key,
506 PVMI_KVP_SEMICOLON_STRING_CONSTCHAR,
507 oscl_strlen(PVMI_KVP_SEMICOLON_STRING_CONSTCHAR));
508 oscl_strncat(aKeyVal.key,
509 PVMI_KVPVALTYPE_STRING_CONSTCHAR,
510 oscl_strlen(PVMI_KVPVALTYPE_STRING_CONSTCHAR));
511 oscl_strncat(aKeyVal.key,
512 PVMI_KVPVALTYPE_UINT8PTR_STRING,
513 oscl_strlen(PVMI_KVPVALTYPE_UINT8PTR_STRING));
514 if (aMiscKeyParam)
515 {
516 oscl_strncat(aKeyVal.key, aMiscKeyParam, oscl_strlen(aMiscKeyParam));
517 }
518 aKeyVal.key[keylen-1] = NULL_TERM_CHAR;
519 /* Copy the value */
520 oscl_memcpy(aKeyVal.value.pUint8_value, aValue, aValueLen);
521 aKeyVal.length = aValueLen;
522 aKeyVal.capacity = aValueLen;
523
524 return PVMFSuccess;
525 }
526
CreateKVPForUInt32Value(PvmiKvp & aKeyVal,const char * aKeyTypeString,uint32 & aValueUInt32,char * aMiscKeyParam)527 OSCL_EXPORT_REF PVMFStatus PVMFCreateKVPUtils::CreateKVPForUInt32Value(PvmiKvp& aKeyVal,
528 const char* aKeyTypeString,
529 uint32& aValueUInt32,
530 char* aMiscKeyParam)
531 {
532 // Check parameters
533 if (aKeyVal.key != NULL || aKeyTypeString == NULL)
534 {
535 return PVMFErrArgument;
536 }
537
538 // Determine the length of strings
539 uint32 keylen = oscl_strlen(aKeyTypeString) + 1; // for key string and ";"
540 keylen += oscl_strlen(PVMI_KVPVALTYPE_STRING_CONSTCHAR); // for "valtype="
541 keylen += oscl_strlen(PVMI_KVPVALTYPE_UINT32_STRING_CONSTCHAR) + 1; // for "uint32" and NULL terminator
542 if (aMiscKeyParam)
543 {
544 keylen += oscl_strlen(aMiscKeyParam);
545 }
546
547 // Allocate memory for the strings
548 aKeyVal.key = OSCL_ARRAY_NEW(char, keylen);
549
550
551 // Copy the key string
552 oscl_strncpy(aKeyVal.key, aKeyTypeString, oscl_strlen(aKeyTypeString) + 1);
553 oscl_strncat(aKeyVal.key, PVMI_KVP_SEMICOLON_STRING_CONSTCHAR, oscl_strlen(PVMI_KVP_SEMICOLON_STRING_CONSTCHAR));
554 oscl_strncat(aKeyVal.key, PVMI_KVPVALTYPE_STRING_CONSTCHAR, oscl_strlen(PVMI_KVPVALTYPE_STRING_CONSTCHAR));
555 oscl_strncat(aKeyVal.key, PVMI_KVPVALTYPE_UINT32_STRING_CONSTCHAR, oscl_strlen(PVMI_KVPVALTYPE_UINT32_STRING_CONSTCHAR));
556 if (aMiscKeyParam)
557 {
558 oscl_strncat(aKeyVal.key, aMiscKeyParam, oscl_strlen(aMiscKeyParam));
559 }
560 aKeyVal.key[keylen-1] = '\0';
561 // Copy the value
562 aKeyVal.value.uint32_value = aValueUInt32;
563 // Set the length and capacity
564 aKeyVal.length = 1;
565 aKeyVal.capacity = 1;
566
567 return PVMFSuccess;
568 }
569
570
CreateKVPForFloatValue(PvmiKvp & aKeyVal,const char * aKeyTypeString,float & aValueFloat,char * aMiscKeyParam)571 OSCL_EXPORT_REF PVMFStatus PVMFCreateKVPUtils::CreateKVPForFloatValue(PvmiKvp& aKeyVal,
572 const char* aKeyTypeString,
573 float& aValueFloat,
574 char* aMiscKeyParam)
575 {
576 // Check parameters
577 if (aKeyVal.key != NULL || aKeyTypeString == NULL)
578 {
579 return PVMFErrArgument;
580 }
581
582 // Determine the length of strings
583 uint32 keylen = oscl_strlen(aKeyTypeString) + 1; // for key string and ";"
584 keylen += oscl_strlen(PVMI_KVPVALTYPE_STRING_CONSTCHAR); // for "valtype="
585 keylen += oscl_strlen(PVMI_KVPVALTYPE_FLOAT_STRING_CONSTCHAR) + 1; // for "float" and NULL terminator
586 if (aMiscKeyParam)
587 {
588 keylen += oscl_strlen(aMiscKeyParam);
589 }
590
591 // Allocate memory for the strings
592 aKeyVal.key = OSCL_ARRAY_NEW(char, keylen);
593
594 // Copy the key string
595 oscl_strncpy(aKeyVal.key, aKeyTypeString, oscl_strlen(aKeyTypeString) + 1);
596 oscl_strncat(aKeyVal.key, PVMI_KVP_SEMICOLON_STRING_CONSTCHAR, oscl_strlen(PVMI_KVP_SEMICOLON_STRING_CONSTCHAR));
597 oscl_strncat(aKeyVal.key, PVMI_KVPVALTYPE_STRING_CONSTCHAR, oscl_strlen(PVMI_KVPVALTYPE_STRING_CONSTCHAR));
598 oscl_strncat(aKeyVal.key, PVMI_KVPVALTYPE_FLOAT_STRING_CONSTCHAR, oscl_strlen(PVMI_KVPVALTYPE_FLOAT_STRING_CONSTCHAR));
599 if (aMiscKeyParam)
600 {
601 oscl_strncat(aKeyVal.key, aMiscKeyParam, oscl_strlen(aMiscKeyParam));
602 }
603 aKeyVal.key[keylen-1] = '\0';
604 // Copy the value
605 aKeyVal.value.float_value = aValueFloat;
606 // Set length and capacity
607 aKeyVal.length = 1;
608 aKeyVal.capacity = 1;
609
610 return PVMFSuccess;
611 }
612
613
CreateKVPForBoolValue(PvmiKvp & aKeyVal,const char * aKeyTypeString,bool & aValueBool,char * aMiscKeyParam)614 OSCL_EXPORT_REF PVMFStatus PVMFCreateKVPUtils::CreateKVPForBoolValue(PvmiKvp& aKeyVal,
615 const char* aKeyTypeString,
616 bool& aValueBool,
617 char* aMiscKeyParam)
618 {
619 // Check parameters
620 if (aKeyVal.key != NULL || aKeyTypeString == NULL)
621 {
622 return PVMFErrArgument;
623 }
624
625 // Determine the length of strings
626 uint32 keylen = oscl_strlen(aKeyTypeString) + 1; // for key string and ";"
627 keylen += oscl_strlen(PVMI_KVPVALTYPE_STRING_CONSTCHAR); // for "valtype="
628 keylen += oscl_strlen(PVMI_KVPVALTYPE_BOOL_STRING_CONSTCHAR) + 1; // for "bool" and NULL terminator
629 if (aMiscKeyParam)
630 {
631 keylen += oscl_strlen(aMiscKeyParam);
632 }
633
634 // Allocate memory for the strings
635 aKeyVal.key = OSCL_ARRAY_NEW(char, keylen);
636
637 // Copy the key string
638 oscl_strncpy(aKeyVal.key, aKeyTypeString, oscl_strlen(aKeyTypeString) + 1);
639 oscl_strncat(aKeyVal.key, PVMI_KVP_SEMICOLON_STRING_CONSTCHAR, oscl_strlen(PVMI_KVP_SEMICOLON_STRING_CONSTCHAR));
640 oscl_strncat(aKeyVal.key, PVMI_KVPVALTYPE_STRING_CONSTCHAR, oscl_strlen(PVMI_KVPVALTYPE_STRING_CONSTCHAR));
641 oscl_strncat(aKeyVal.key, PVMI_KVPVALTYPE_BOOL_STRING_CONSTCHAR, oscl_strlen(PVMI_KVPVALTYPE_BOOL_STRING_CONSTCHAR));
642 if (aMiscKeyParam)
643 {
644 oscl_strncat(aKeyVal.key, aMiscKeyParam, oscl_strlen(aMiscKeyParam));
645 }
646 aKeyVal.key[keylen-1] = '\0';
647 // Copy the value
648 aKeyVal.value.bool_value = aValueBool;
649 // Set length and capacity
650 aKeyVal.length = 1;
651 aKeyVal.capacity = 1;
652
653 return PVMFSuccess;
654 }
655
CreateKVPForKSVValue(PvmiKvp & aKeyVal,const char * aKeyTypeString,OsclAny * aValue,char * aMiscKeyParam)656 OSCL_EXPORT_REF PVMFStatus PVMFCreateKVPUtils::CreateKVPForKSVValue(PvmiKvp& aKeyVal,
657 const char* aKeyTypeString,
658 OsclAny* aValue,
659 char* aMiscKeyParam)
660 {
661 /* Check parameters */
662 if (aKeyVal.key != NULL || aKeyTypeString == NULL)
663 {
664 return PVMFErrArgument;
665 }
666
667 /* Determine the length of strings */
668 uint32 keylen = oscl_strlen(aKeyTypeString) + 1; // for key string and ";"
669 keylen += oscl_strlen(PVMI_KVPVALTYPE_STRING_CONSTCHAR); // for "valtype="
670 keylen += oscl_strlen(PVMI_KVPVALTYPE_UINT8PTR_STRING_CONSTCHAR) + 1; // for "char*" and NULL terminator
671 if (aMiscKeyParam)
672 {
673 keylen += oscl_strlen(aMiscKeyParam);
674 }
675
676 /* Allocate memory for the strings */
677 aKeyVal.key = OSCL_ARRAY_NEW(char, keylen);
678 aKeyVal.value.key_specific_value = NULL;
679
680
681 /* Copy the key string */
682 oscl_strncpy(aKeyVal.key,
683 aKeyTypeString,
684 oscl_strlen(aKeyTypeString) + 1);
685 oscl_strncat(aKeyVal.key,
686 PVMI_KVP_SEMICOLON_STRING_CONSTCHAR,
687 oscl_strlen(PVMI_KVP_SEMICOLON_STRING_CONSTCHAR));
688 oscl_strncat(aKeyVal.key,
689 PVMI_KVPVALTYPE_STRING_CONSTCHAR,
690 oscl_strlen(PVMI_KVPVALTYPE_STRING_CONSTCHAR));
691 oscl_strncat(aKeyVal.key,
692 PVMI_KVPVALTYPE_KSV_STRING,
693 oscl_strlen(PVMI_KVPVALTYPE_KSV_STRING));
694 if (aMiscKeyParam)
695 {
696 oscl_strncat(aKeyVal.key, aMiscKeyParam, oscl_strlen(aMiscKeyParam));
697 }
698 aKeyVal.key[keylen-1] = '\0';
699 /* Copy the value */
700 aKeyVal.value.key_specific_value = aValue;
701
702 return PVMFSuccess;
703 }
704
705