Some work on wtp and ktv config files
FossilOrigin-Name: 3747732055809fd587f96cff65c389a0878a09a197947c1e68a76f605bdb44a0
This commit is contained in:
42
src/cw/cw_ktv_add.c
Normal file
42
src/cw/cw_ktv_add.c
Normal file
@ -0,0 +1,42 @@
|
||||
#include "ktv.h"
|
||||
#include "cw.h"
|
||||
|
||||
#include "log.h"
|
||||
#include "dbg.h"
|
||||
|
||||
const char * cw_ktv_add(mavl_t kvtstore, const char *key, const struct cw_Type *type,
|
||||
const uint8_t * data, int len)
|
||||
{
|
||||
cw_KTV_t mdata, *mresult;
|
||||
int exists;
|
||||
|
||||
/* cw_dbg(DBG_ELEM,"KVStore (%p,%d) add elem (%s): %s", kvstore, kvstore->count,
|
||||
type->name, key );
|
||||
*/
|
||||
mdata.key=cw_strdup(key);
|
||||
if (!mdata.key){
|
||||
cw_log(LOG_ERR, "Can't allocate memory for key %s: %s",
|
||||
key,strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mresult = type->get(&mdata,data,len);
|
||||
if (!mresult){
|
||||
cw_log(LOG_ERR, "Can't create kvstore element for key %s of type %s: %s",
|
||||
key,type->name, strerror(errno));
|
||||
free(mdata.key);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mresult = mavl_add(kvtstore, &mdata, &exists);
|
||||
if (exists){
|
||||
cw_log(LOG_ERR, "Element already exists %s", key);
|
||||
/* element already exists */
|
||||
free(mdata.key);
|
||||
if (type->del)
|
||||
type->del(&mdata);
|
||||
return key;
|
||||
}
|
||||
|
||||
return mdata.key;
|
||||
}
|
Reference in New Issue
Block a user