[T106][ZXW-22]7520V3SCV2.01.01.02P42U09_VEC_V0.8_AP_VEC origin source commit
Change-Id: Ic6e05d89ecd62fc34f82b23dcf306c93764aec4b
diff --git a/ap/app/cwmp/netcwmp/libcwmp/src/cfg.c b/ap/app/cwmp/netcwmp/libcwmp/src/cfg.c
new file mode 100755
index 0000000..5925b23
--- /dev/null
+++ b/ap/app/cwmp/netcwmp/libcwmp/src/cfg.c
@@ -0,0 +1,140 @@
+/************************************************************************
+ * Id: cfg.c *
+ * *
+ * TR069 Project: A TR069 library in C *
+ * Copyright (C) 2013-2014 netcwmp.netcwmp group *
+ * *
+ * *
+ * Email: netcwmp ( & ) gmail dot com *
+ * *
+ ***********************************************************************/
+
+#include <cwmp/cwmp.h>
+#include <cwmp/pool.h>
+#include <cwmp/log.h>
+#include <cwmp/cfg.h>
+#include <ini.h>
+
+
+typedef struct conf_t conf_t;
+
+struct conf_t {
+ char * filename;
+ FILE * fd;
+};
+
+
+static conf_t * cwmp_conf_handle = NULL;
+
+int cwmp_conf_open(const char * filename)
+{
+ FUNCTION_TRACE();
+ cwmp_conf_handle = malloc(sizeof(conf_t)+1);
+ if (!cwmp_conf_handle)
+ {
+ cwmp_log_error("conf malloc faild.\n");
+ return CWMP_ERROR;
+ }
+ cwmp_conf_handle->filename = TRstrdup(filename);
+ if(NULL == cwmp_conf_handle->filename)
+ {
+ cwmp_log_error("cwmp_conf_handle->filename is null, filename:%s", filename);
+ return CWMP_ERROR;
+ }
+
+ return CWMP_OK;
+}
+
+void cwmp_conf_split(char * name, char **s , char **k)
+{
+ *s = strchr(name, ':');
+ if(*s == NULL)
+ {
+ k = &name;
+ *s = "cwmp";
+ }
+ else
+ {
+ *s[0] = 0;
+ *k = *s+1;
+ *s = name;
+ }
+}
+
+int cwmp_conf_get(const char * key, char *value)
+{
+ char * s, *k;
+ char name[INI_BUFFERSIZE+1] = {0};
+ //char value[INI_BUFFERSIZE] = {0};
+ FUNCTION_TRACE();
+ if(key == NULL)
+ {
+ return -1;
+ }
+ TRstrncpy(name, key, INI_BUFFERSIZE);
+ cwmp_conf_split(name, &s, &k);
+
+ ini_gets(s,k,NULL,value,INI_BUFFERSIZE, cwmp_conf_handle->filename);
+ return 0;
+}
+
+int cwmp_conf_set(const char * key, const char * value)
+{
+ char * s, *k;
+ char name[INI_BUFFERSIZE+1] = {0};
+ FUNCTION_TRACE();
+ if(key == NULL)
+ {
+ return CWMP_ERROR;
+ }
+ TRstrncpy(name, key, INI_BUFFERSIZE);
+ cwmp_conf_split(name, &s, &k);
+
+ return ini_puts(s, k, value, cwmp_conf_handle->filename);
+}
+
+char * cwmp_conf_pool_get(pool_t * pool, const char * key)
+{
+ char * s, *k;
+ char name[INI_BUFFERSIZE+1] = {0};
+ char value[INI_BUFFERSIZE+1] = {0};
+ //FUNCTION_TRACE();
+ if(key == NULL)
+ {
+ return NULL;
+ }
+ TRstrncpy(name, key, INI_BUFFERSIZE);
+
+ cwmp_conf_split(name, &s, &k);
+
+ ini_gets(s,k,NULL,value,INI_BUFFERSIZE, cwmp_conf_handle->filename);
+
+ return pool_pstrdup(pool, value);
+}
+
+int cwmp_conf_get_int(const char * key)
+{
+ char * s, *k;
+ char name[INI_BUFFERSIZE+1] = {0};
+
+ FUNCTION_TRACE();
+ if(key == NULL)
+ {
+ cwmp_log_error("key is NULL");
+ return 0;
+ }
+ TRstrncpy(name, key, INI_BUFFERSIZE);
+ cwmp_conf_split(name, &s, &k);
+
+ return (int)ini_getl(s,k,0,cwmp_conf_handle->filename);
+}
+
+
+
+
+
+
+
+
+
+