text
stringlengths
0
357
* @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.
*/
int32_t dc_param_get_int(const dc_param_t* param, int key, int32_t def)
{
if (param==NULL || key==0) {
return def;
}
char* str = dc_param_get(param, key, NULL);
if (str==NULL) {
return def;
}
int32_t ret = atol(str);
free(str);
return ret;
}
/**
* 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.
*/
double dc_param_get_float(const dc_param_t* param, int key, double def)
{
if (param==NULL || key==0) {
return def;
}
char* str = dc_param_get(param, key, NULL);
if (str==NULL) {
return def;
}
double ret = dc_atof(str);
free(str);
return ret;
}
/**
* Set parameter to a string.
*
* @memberof dc_param_t
* @param param Parameter object to modify.
* @param key Key of the parameter to modify, one of the DC_PARAM_* constants.
* @param value Value to store for key. NULL to clear the value.
* @return None.
*/
void dc_param_set(dc_param_t* param, int key, const char* value)
{
char* old1 = NULL;
char* old2 = NULL;
char* new1 = NULL;
if (param==NULL || key==0) {
return;
}
old1 = param->packed;
old2 = NULL;
/* remove existing parameter from packed string, if any */
if (old1) {
char *p1, *p2;
p1 = find_param(old1, key, &p2);
if (p1 != NULL) {
*p1 = 0;
old2 = p2;
}
else if (value==NULL) {
return; /* parameter does not exist and should be cleared -> done. */
}
}
dc_rtrim(old1); /* trim functions are null-pointer-safe */
dc_ltrim(old2);
if (old1 && old1[0]==0) { old1 = NULL; }
if (old2 && old2[0]==0) { old2 = NULL; }
/* create new string */
if (value) {
new1 = dc_mprintf("%s%s%c=%s%s%s",
old1? old1 : "",
old1? "\n" : "",
key,
value,
old2? "\n" : "",
old2? old2 : "");
}
else {
new1 = dc_mprintf("%s%s%s",
old1? old1 : "",
(old1&&old2)? "\n" : "",