taskrambler  0.1.8
Web server and task management solution.
config/value.c File Reference
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "class.h"
#include "config/value.h"
#include "utils/memory.h"
#include "utils/hash.h"
+ Include dependency graph for config/value.c:

Go to the source code of this file.

Functions

static int configValueCtor (void *_this, va_list *params)
 
static void configValueDtor (void *_this)
 
static unsigned long configValueGetHash (void *_this)
 
static void configValueHandleDouble (void *_this, void *_double)
 
 INIT_IFACE (Class, configValueCtor, configValueDtor, NULL)
 
 INIT_IFACE (Hashable, configValueGetHash, configValueHandleDouble)
 
 CREATE_CLASS (ConfigValue, NULL, IFACE(Class), IFACE(Hashable))
 

Detailed Description

Author
Georg Hopp

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file config/value.c.

Function Documentation

static int configValueCtor ( void *  _this,
va_list *  params 
)
static

if we find the value enclosed by single or double quotes we take it as a string, else we take it as a numeric which is treated as a long long right now.

Definition at line 35 of file config/value.c.

References CONFIG_VALUE_NUMERIC, CONFIG_VALUE_STRING, memMalloc(), and sdbm().

36 {
37  ConfigValue this = _this;
38 
39  char * key = va_arg(*params, char *);
40  size_t nkey = va_arg(*params, size_t);
41  char * value = va_arg(*params, char *);
42  size_t nvalue = va_arg(*params, size_t);
43 
44  this->hash = sdbm((unsigned char *)key, nkey);
45 
46  /**
47  * if we find the value enclosed by single or double
48  * quotes we take it as a string, else we take it
49  * as a numeric which is treated as a long long
50  * right now.
51  */
52  if (('"' == value[0] && '"' == value[nvalue-1])
53  || ('\'' == value[0] && '\'' == value[nvalue-1]))
54  {
55  this->type = CONFIG_VALUE_STRING;
56  (this->value).string = memMalloc(nvalue-1);
57  (this->value).string[nvalue-2] = '\0';
58  memcpy((this->value).string, value+1, nvalue-2);
59  this->nvalue = nvalue;
60  } else {
61  this->type = CONFIG_VALUE_NUMERIC;
62  (this->value).number = atoll(value);
63  this->nvalue = sizeof(long long);
64  }
65 
66  return 0;
67 }
unsigned long sdbm(const unsigned char *, size_t)
Definition: utils/hash.c:45
void * memMalloc(size_t)
Definition: memory.c:783

+ Here is the call graph for this function:

static void configValueDtor ( void *  _this)
static

Definition at line 71 of file config/value.c.

References CONFIG_VALUE_STRING, and MEM_FREE.

72 {
73  ConfigValue this = _this;
74 
75  if (CONFIG_VALUE_STRING == this->type) {
76  MEM_FREE((this->value).string);
77  }
78 }
#define MEM_FREE(seg)
Definition: memory.h:28
static unsigned long configValueGetHash ( void *  _this)
static

Definition at line 82 of file config/value.c.

83 {
84  ConfigValue this = _this;
85 
86  return this->hash;
87 }
static void configValueHandleDouble ( void *  _this,
void *  _double 
)
static

Definition at line 91 of file config/value.c.

92 {
93  /* right now I do nothing...but I could :D */
94 }
CREATE_CLASS ( ConfigValue  ,
NULL  ,
IFACE(Class)  ,
IFACE(Hashable)   
)
INIT_IFACE ( Class  ,
configValueCtor  ,
configValueDtor  ,
NULL   
)
INIT_IFACE ( Hashable  ,
configValueGetHash  ,
configValueHandleDouble   
)