text stringlengths 0 357 |
|---|
* @param param Parameter object to modify. |
* @param packed Parameters to set, see comment above. |
* @return None. |
*/ |
void dc_param_set_packed(dc_param_t* param, const char* packed) |
{ |
if (param==NULL) { |
return; |
} |
dc_param_empty(param); |
if (packed) { |
free(param->packed); |
param->packed = dc_strdup(packed); |
} |
} |
/** |
* Same as dc_param_set_packed() but uses '&' as a separator (instead '\n'). |
* Urldecoding itself is not done by this function, this is up to the caller. |
*/ |
void dc_param_set_urlencoded(dc_param_t* param, const char* urlencoded) |
{ |
if (param==NULL) { |
return; |
} |
dc_param_empty(param); |
if (urlencoded) { |
free(param->packed); |
param->packed = dc_strdup(urlencoded); |
dc_str_replace(¶m->packed, "&", "\n"); |
} |
} |
/** |
* Check if a parameter exists. |
* |
* @memberof dc_param_t |
* @param param Parameter object to query. |
* @param key Key of the parameter to check the existance, one of the DC_PARAM_* constants. |
* @return 1=parameter exists in object, 0=parameter does not exist in parameter object. |
*/ |
int dc_param_exists(dc_param_t* param, int key) |
{ |
char *p2 = NULL; |
if (param==NULL || key==0) { |
return 0; |
} |
return find_param(param->packed, key, &p2)? 1 : 0; |
} |
/** |
* Get value of a parameter. |
* |
* @memberof dc_param_t |
* @param param Parameter object to query. |
* @param key Key of the parameter to get, one of the DC_PARAM_* constants. |
* @param def Value to return if the parameter is not set. |
* @return The stored value or the default value. In both cases, the returned value must be free()'d. |
*/ |
char* dc_param_get(const dc_param_t* param, int key, const char* def) |
{ |
char* p1 = NULL; |
char* p2 = NULL; |
char bak = 0; |
char* ret = NULL; |
if (param==NULL || key==0) { |
return def? dc_strdup(def) : NULL; |
} |
p1 = find_param(param->packed, key, &p2); |
if (p1==NULL) { |
return def? dc_strdup(def) : NULL; |
} |
p1 += 2; /* skip key and "=" (safe as find_param checks for its existance) */ |
bak = *p2; |
*p2 = 0; |
ret = dc_strdup(p1); |
dc_rtrim(ret); /* to be safe with '\r' characters ... */ |
*p2 = bak; |
return ret; |
} |
/** |
* Get value of a parameter. |
* |
* @memberof dc_param_t |
* @param param Parameter object to query. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.