summaryrefslogtreecommitdiffstats
path: root/src/vf_access_wrappers.c
blob: ac889dcffe372dbc20a714e18fb0217661fa4809 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
/****************************************************************************

    (C) Nick Marley, 2001 -

    This software is distributed under the GNU Lesser General Public Licence.
    Please read and understand the comments at the top of vf_iface.h before use!

FILE
    $Workfile: vf_access.c $
    $Revision: 1.16 $
    $Author: tilda $
         
ORIGINAL AUTHOR
    Nick Marley

DESCRIPTION
    Wrappers on the core access functions & other utility functions.

REFERENCES
    (none)    

MODIFICATION HISTORY
 *  $Log: vf_access_wrappers.c,v $
 *  Revision 1.16  2002/11/16 13:19:10  tilda
 *  IID639288 - Implement method for adding subobjects.
 *
 *  Revision 1.15  2002/11/03 18:43:16  tilda
 *  IID619851 - Update and check headers and function prototypes.
 *
 *  Revision 1.14  2002/11/02 18:29:26  tilda
 *  IID485157 - UI does character conversion based on CHARSET property.
 *
 *  Revision 1.13  2002/10/26 16:09:24  tilda
 *  IID629125 - Ensure string functions used are portable.
 *
 *  Revision 1.12  2002/10/08 21:45:07  tilda
 *  IID620473 - reduce c-runtime dependencies.
 *
 *  Revision 1.11  2002/10/08 21:11:36  tilda
 *  Remove common.h.
 *
 *  Revision 1.10  2001/11/18 22:07:02  tilda
 *  Ensure empty BASE64 properties get the encoding set correctly.
 *
 *  Revision 1.9  2001/11/18 21:48:18  tilda
 *  Remove redundant code.
 *
 *  Revision 1.8  2001/11/17 17:40:29  tilda
 *  Image / sound dialog box now works.
 *
 *  Revision 1.7  2001/11/16 22:34:50  tilda
 *  New vf_get_property() allows append as well as find,
 *
 *  Revision 1.6  2001/11/15 08:56:06  tilda
 *  Fix bug in qualifier location code.
 *
 *  Revision 1.5  2001/11/14 22:36:56  tilda
 *  Add parameter to vf_find_prop_qual_index()
 *
 *  Revision 1.4  2001/11/14 16:05:06  tilda
 *  Extend capabilities of vf_find_prop_qual_index().
 *
 *  Revision 1.3  2001/11/06 22:51:05  tilda
 *  Supporting access functions for image selection / deletion.
 *
 *  Revision 1.2  2001/10/24 18:56:29  tilda
 *  Tidy headers after import.  Fix include path in release build.
 *
 *  Revision 1.1  2001/10/24 18:34:35  tilda
 *  Initial Version.
 *
 *****************************************************************************/

#ifndef NORCSID
static const char vf_access_wrappers_c_vss_id[] = "$Header: /cvsroot/vformat/src/vformat/src/vf_access_wrappers.c,v 1.16 2002/11/16 13:19:10 tilda Exp $";
#endif

/*============================================================================*
 ANSI C & System-wide Header Files
 *============================================================================*/


/*===========================================================================*
 Interface Header Files
 *===========================================================================*/

#include "vformat/vf_iface.h"

/*===========================================================================*
 Local Header File
 *===========================================================================*/

#include "vf_config.h"
#include "vf_malloc.h"
#include "vf_internals.h"
#include "vf_strings.h"
#include "vf_string_arrays.h"

/*===========================================================================*
 Public Data
 *===========================================================================*/
/* None */

/*===========================================================================*
 Private Defines
 *===========================================================================*/
/* None */

/*===========================================================================*
 Private Data Types
 *===========================================================================*/
/* None */

/*===========================================================================*
 Private Function Prototypes
 *===========================================================================*/
/* None */

/*===========================================================================*
 Private Data
 *===========================================================================*/
/* None */

/*===========================================================================*
 Public Function Implementations
 *===========================================================================*/

bool_t vf_prop_belongs_to_object(
    VF_PROP_T *p_prop,
    VF_OBJECT_T *p_object
    );


/*---------------------------------------------------------------------------*
 * NAME
 *      vf_get_prop_value_string()
 * 
 * DESCRIPTION
 *      Obtain string pointer value from VF_PROP_T.  If the array contains
 *      an entry for the indicated string return it. Return NULL if out of
 *      range request, ie. n_string=3 for N=0;1;2
 *
 * RETURNS
 *      Pointer to string value if value present, NULL if index  too large.
 *---------------------------------------------------------------------------*/

char *vf_get_prop_value_string(
    VF_PROP_T *p_prop,
    uint32_t n_string
    )
{
    VPROP_T *p_vprop = (VPROP_T *)p_prop;
    char *p_ret = NULL;

    if (p_vprop->value.v.s.pp_strings)
    {      
        if (n_string < p_vprop->value.v.s.n_strings)
        {
            p_ret = p_vprop->value.v.s.pp_strings[n_string];
        }
    }

    return p_ret;
}





/*---------------------------------------------------------------------------*
 * NAME
 *      vf_set_prop_value_string()
 * 
 * DESCRIPTION
 *      Set the value of a property.
 *
 * RETURNS
 *      TRUE <=> set successfully.
 *---------------------------------------------------------------------------*/

bool_t vf_set_prop_value_string(
    VF_PROP_T *p_prop,
    uint32_t n_string,
    const char *p_string
    )
{
    return vf_set_prop_value(p_prop, (char *)p_string, n_string, VF_ENC_7BIT, TRUE);
}








/*---------------------------------------------------------------------------*
 * NAME
 *      vf_get_prop_value_base64()
 * 
 * DESCRIPTION
 *      Obtain data pointer for BASE64 data.
 *
 * RETURNS
 *      Pointer to data.
 *---------------------------------------------------------------------------*/

const uint8_t *vf_get_prop_value_base64(
    VF_PROP_T *p_prop,          /* Property we're setting a value in */
    uint32_t *p_length          /* Length of the binary data */
    )    
{
    const uint8_t *p_return = NULL;

    if (p_prop)
    {
        VPROP_T *p_vprop = (VPROP_T *)p_prop;

        p_return = p_vprop->value.v.b.p_buffer;

        if (p_length)
        {
            *p_length = p_vprop->value.v.b.n_bufsize;
        }
    }

    return p_return;
}





/*---------------------------------------------------------------------------*
 * NAME
 *      vf_set_prop_value_base64()
 * 
 * DESCRIPTION
 *      Set the value of a property.
 *
 * RETURNS
 *      TRUE <=> set successfully.
 *---------------------------------------------------------------------------*/

bool_t vf_set_prop_value_base64(
    VF_PROP_T *p_prop,          /* Property we're setting a value in */
    const uint8_t *p_data,      /* Pointer to the binary data */
    uint32_t length,            /* Length of the binary data */
    bool_t copy                 /* Copy or keep pointer */
    )
{
    return vf_set_prop_value(p_prop, (char *)p_data, length, VF_ENC_BASE64, copy);
}






/*---------------------------------------------------------------------------*
 * NAME
 *      vf_get_prop_value_object()
 * 
 * DESCRIPTION
 *      Obtain object pointer value from VF_PROP_T.
 *
 * RETURNS
 *      Pointer to vobject value (or NULL if not found).
 *---------------------------------------------------------------------------*/

VF_OBJECT_T *vf_get_prop_value_object(
    VF_PROP_T *p_prop
    )
{
    VPROP_T *p_vprop = (VPROP_T *)p_prop;

    if (VF_ENC_VOBJECT == p_vprop->value.encoding)
    {
        return (VF_OBJECT_T *)(p_vprop->value.v.o.p_object);
    }

    return NULL;
}





/*---------------------------------------------------------------------------*
 * NAME
 *      vf_set_prop_value_object()
 * 
 * DESCRIPTION
 *      Set the value of the indicated property to be a VOBJECT.
 *
 * RETURNS
 *      TRUE <=> set successfully.
 *---------------------------------------------------------------------------*/

bool_t vf_set_prop_value_object(
    VF_PROP_T *p_prop,
    VF_OBJECT_T *p_object
    )
{
    VPROP_T *p_vprop = (VPROP_T *)p_prop;
    bool_t ret = FALSE;

    /*
     * Avoid various sillies.
     */
    if (p_prop && p_object && !vf_prop_belongs_to_object(p_prop, p_object))
    {
        delete_prop_contents(p_prop, FALSE);
        
        p_vprop->value.v.o.p_object = (VOBJECT_T *)p_object;
        p_vprop->value.encoding = VF_ENC_VOBJECT;
    }

    return TRUE;
}








/*---------------------------------------------------------------------------*
 * NAME
 *      vf_get_prop_name_string()
 * 
 * DESCRIPTION
 *      Get n'th name string.
 *
 * RETURNS
 *      Pointer to string value if value present, NULL if index  too large.
 *---------------------------------------------------------------------------*/

char *vf_get_prop_name_string(
    VF_PROP_T *p_prop,
    uint32_t n_string
    )
{
    VPROP_T *p_vprop = (VPROP_T *)p_prop;
    char *p_ret = NULL;

    if (p_vprop->name.pp_strings)
    {      
        if (n_string < p_vprop->name.n_strings)
        {
            p_ret = p_vprop->name.pp_strings[n_string];
        }
    }

    return p_ret;
}




/*---------------------------------------------------------------------------*
 * NAME
 *      vf_set_prop_name_string()
 * 
 * DESCRIPTION
 *      Set n'th name string.
 *
 * RETURNS
 *      TRUE iff allocation OK, FALSE else.
 *---------------------------------------------------------------------------*/

bool_t vf_set_prop_name_string(
    VF_PROP_T *p_prop,          /* Property we're setting a value in */
    uint32_t n_string,          /* Index to string */
    const char *p_string        /* Pointer to string */
    )
{
    VPROP_T *p_vprop;
    bool_t ret = FALSE;

    p_vprop = (VPROP_T *)p_prop;

    if (p_vprop)
    {
        if ((-1) == n_string)
        {
            ret = add_string_to_array(&p_vprop->name, p_string);
        }
        else
        {
            ret = set_string_array_entry(&p_vprop->name, p_string, n_string);
        }
    }

    return TRUE;
}






/*---------------------------------------------------------------------------*
 * NAME
 *      vf_find_prop_qual_index()
 * 
 * DESCRIPTION
 *      Locate property qualifier given either an array of possible values
 *      or a single token that is either present or absent.  For example
 *      if we have a property:
 *
 *      NAME;THIRD;TIME;LUCKY:VALUE1;VALUE2;VALUE3
 *
 *      Then there are two possible searches.
 *
 *      Firstly we can look for the property qualifier which can take values
 *      from the array { "FIRST", "SECOND", THIRD" } in which case the array
 *      is passed as pp_possible_values and the function returns with the
 *      values *p_found_value_index=2, p_qualifier_index=1
 *
 *      Secondly we can look for the token with value "TIME" in which case
 *      p_token is set to "TIME" and the function returns *p_qualifier_index=2.
 *
 * RETURNS
 *      TRUE iff found, FALSE else.
 *---------------------------------------------------------------------------*/

bool_t vf_find_prop_qual_index(
    VF_PROP_T *p_prop,                  /* The property we're querying */
    uint32_t *p_qualifier_index,        /* Ptr to output name index */
    uint32_t *p_found_value_index,      /* Ptr to output index in array */
    const char **pp_possible_values,    /* Array of possible values */
    const char *p_token,                /* Token searched for */
    vf_search_flags_t match             /* String comparison flags */
    )
{
    uint32_t n;
    bool_t ret;

    VPROP_T *p_vprop = (VPROP_T *)p_prop;

    for (n = 0, ret = FALSE;!ret && (n < p_vprop->name.n_strings);n++)
    {
        const char *p_string = p_vprop->name.pp_strings[n];

        if (p_string)
        {
            if (pp_possible_values)
            {
                uint32_t i;

                for (i = 0;!ret && pp_possible_values[i];i++)
                {
                    if (0 == p_stricmp(pp_possible_values[i], p_string))
                    {
                        if (p_found_value_index)
                            *p_found_value_index = i;
                        if (p_qualifier_index)
                            *p_qualifier_index = n;

                        ret = TRUE;
                    }
                }
            }
            else
            if (p_token)
            {
                if (0 == p_stricmp(p_token, p_string))
                {
                    if (p_qualifier_index)
                        *p_qualifier_index = n;

                    ret = TRUE;
                }
            }
            else
            {
                /*???*/
            }
        }
    }

    return ret;
}






/*----------------------------------------------------------------------------*
 * NAME
 *      vf_find_charset()
 * 
 * DESCRIPTION
 *      Locate the charset 
 *
 * RETURNS
 *      vf_charset_t.
 *---------------------------------------------------------------------------*/

const char *vf_find_charset(
    VF_PROP_T *p_prop
    )
{
    VPROP_T *p_vprop = (VPROP_T *)p_prop;
    char *ret;

    if (!string_array_contains_string(&p_vprop->name, &ret, -1, VFP_CHARSET, FALSE))
    {
        ret = NULL;
    }
    else
    {
        ret += 1 + p_strlen(VFP_CHARSET);
    }

    return ret;
}





/*===========================================================================*
 Private Function Implementations
 *===========================================================================*/

bool_t vf_prop_belongs_to_object(
    VF_PROP_T *p_prop,
    VF_OBJECT_T *p_object
    )
{
    return FALSE;
}

/*===========================================================================*
 End Of File
 *===========================================================================*/