source: XIOS/dev/branch_openmp/extern/src_netcdf4/occlientparams.c @ 1501

Last change on this file since 1501 was 409, checked in by ymipsl, 11 years ago

Add improved nectdf internal library src

YM

  • Property svn:eol-style set to native
File size: 2.9 KB
Line 
1/* Copyright 2009, UCAR/Unidata and OPeNDAP, Inc.
2   See the COPYRIGHT file for more information. */
3
4#include "config.h"
5#include "ocinternal.h"
6#include "ocdebug.h"
7
8#define LBRACKET '['
9#define RBRACKET ']'
10
11
12
13/*
14Client parameters are assumed to be
15one or more instances of bracketed pairs:
16e.g "[...][...]...".
17The bracket content in turn is assumed to be a
18comma separated list of <name>=<value> pairs.
19e.g. x=y,z=,a=b.
20If the same parameter is specifed more than once,
21then the first occurrence is used; this is so that
22is possible to forcibly override user specified
23parameters by prefixing.
24IMPORTANT: client parameter string is assumed to
25have blanks compress out.
26*/
27
28int
29ocparamdecode(OCstate* state)
30{
31    int i;
32    i = ocuridecodeparams(state->uri);
33    return i?OC_NOERR:OC_EBADURL;
34}
35
36
37const char*
38ocparamlookup(OCstate* state, const char* key)
39{
40    if(state == NULL || key == NULL || state->uri == NULL) return NULL;
41    return ocurilookup(state->uri,key);
42}
43
44int
45ocparamset(OCstate* state, const char* params)
46{
47    int i;
48    i = ocurisetparams(state->uri,params);
49    return i?OC_NOERR:OC_EBADURL;
50}
51
52#ifdef OCIGNORE
53void
54ocparamfree(OClist* params)
55{
56    int i;
57    if(params == NULL) return;
58    for(i=0;i<oclistlength(params);i++) {
59        char* s = (char*)oclistget(params,i);
60        if(s != NULL) free((void*)s);
61    }
62    oclistfree(params);
63}
64
65/*
66Delete the entry.
67return value = 1 => found and deleted;
68               0 => param not found
69*/
70int
71ocparamdelete(OClist* params, const char* clientparam)
72{
73    int i,found = 0;
74    if(params == NULL || clientparam == NULL) return 0;
75    for(i=0;i<oclistlength(params);i+=2) {
76        char* name = (char*)oclistget(params,i);
77        if(strcmp(clientparam,name)==0) {found=1; break;}
78    }
79    if(found) {
80        oclistremove(params,i+1); /* remove value */
81        oclistremove(params,i); /* remove name */
82    }
83    return found;
84}
85
86
87/*
88Insert new client param (name,value);
89return value = 1 => not already defined
90               0 => param already defined (no change)
91*/
92int
93ocparaminsert(OClist* params, const char* clientparam, const char* value)
94{
95    int i;
96    if(params == NULL || clientparam == NULL) return 0;
97    for(i=0;i<oclistlength(params);i+=2) {
98        char* name = (char*)oclistget(params,i);
99        if(strcmp(clientparam,name)==0) return 0;
100    }
101    /* not found, append */
102    oclistpush(params,(ocelem)nulldup(clientparam));
103    oclistpush(params,(ocelem)nulldup(value));
104    return 1;
105}
106
107
108/*
109Replace new client param (name,value);
110return value = 1 => replacement performed
111               0 => insertion performed
112*/
113int
114ocparamreplace(OClist* params, const char* clientparam, const char* value)
115{
116    int i;
117    if(params == NULL || clientparam == NULL) return 0;
118    for(i=0;i<oclistlength(params);i+=2) {
119        char* name = (char*)oclistget(params,i);
120        if(strcmp(clientparam,name)==0) {
121            oclistinsert(params,i+1,(ocelem)nulldup(value));
122            return 1;
123        }
124    }
125    ocparaminsert(params,clientparam,value);
126    return 0;
127}
128#endif
Note: See TracBrowser for help on using the repository browser.