Code cleanup
This commit is contained in:
parent
f1cd4a8c5c
commit
e6d4faf25d
|
@ -135,10 +135,9 @@ AppInterface * appinterface_new(char const * app)
|
|||
#ifdef WITH_SSL
|
||||
static int ssl_init = 0;
|
||||
#endif
|
||||
AppInterface * appinterface;
|
||||
/* FIXME read this from available Servers configuration, or imagine a
|
||||
* solution to negociate it directly */
|
||||
struct iface
|
||||
static const struct iface
|
||||
{
|
||||
char * name;
|
||||
int (*func)(AppInterface *);
|
||||
|
@ -152,7 +151,8 @@ AppInterface * appinterface_new(char const * app)
|
|||
{ "VFS", _new_vfs, 4245 },
|
||||
{ "Directory", _new_directory, 4247 }
|
||||
};
|
||||
size_t const ifaces_cnt = sizeof(ifaces) / sizeof(struct iface);
|
||||
static const size_t ifaces_cnt = sizeof(ifaces) / sizeof(struct iface);
|
||||
AppInterface * appinterface;
|
||||
size_t i;
|
||||
|
||||
#ifdef WITH_SSL
|
||||
|
@ -167,22 +167,18 @@ AppInterface * appinterface_new(char const * app)
|
|||
return NULL;
|
||||
appinterface->calls = NULL;
|
||||
appinterface->calls_cnt = 0;
|
||||
error_set_code(1, "%s", "Unknown interface");
|
||||
for(i = 0; i < ifaces_cnt; i++)
|
||||
{
|
||||
if(string_compare(app, ifaces[i].name) != 0)
|
||||
continue;
|
||||
if(ifaces[i].func(appinterface) != 0)
|
||||
i = ifaces_cnt;
|
||||
else
|
||||
error_set_code(0, "");
|
||||
break;
|
||||
if(ifaces[i].func(appinterface) == 0)
|
||||
break;
|
||||
free(appinterface);
|
||||
return NULL;
|
||||
}
|
||||
if(i == ifaces_cnt)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "DEBUG: AppInterface creation failed\n");
|
||||
#endif
|
||||
error_set_code(1, "%s", "Unknown interface");
|
||||
free(appinterface);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -216,7 +212,7 @@ static int _new_append(AppInterface * ai, AppInterfaceCallType type,
|
|||
if(string_compare(ai->calls[i].name, function) == 0)
|
||||
return 1;
|
||||
if((p = realloc(ai->calls, sizeof(AppInterfaceCall) * (i + 1))) == NULL)
|
||||
return 1; /* FIXME report error */
|
||||
return error_set_code(1, "%s", strerror(errno));
|
||||
ai->calls = p;
|
||||
ai->calls_cnt++;
|
||||
_append_arg(&ai->calls[i].type, type, AICD_OUT);
|
||||
|
@ -344,7 +340,8 @@ static int _new_vfs(AppInterface * ai)
|
|||
|
||||
static int _new_directory(AppInterface * appinterface)
|
||||
{
|
||||
return _new_append(appinterface, AICT_UINT32, "_register", 3,
|
||||
/* uint32_t directory_register(in String, in Buffer, out Buffer); */
|
||||
return _new_append(appinterface, AICT_UINT32, "directory_register", 3,
|
||||
AICT_STRING | AICD_IN, AICT_BUFFER | AICD_IN,
|
||||
AICT_BUFFER | AICD_OUT);
|
||||
}
|
||||
|
|
50
src/config.c
50
src/config.c
|
@ -27,6 +27,19 @@
|
|||
|
||||
|
||||
/* Config */
|
||||
/* private */
|
||||
/* types */
|
||||
/* FIXME should be an API to avoid this */
|
||||
typedef struct _HashEntry
|
||||
{
|
||||
char * name;
|
||||
void * data;
|
||||
} HashEntry;
|
||||
|
||||
|
||||
/* public */
|
||||
/* functions */
|
||||
/* config_new */
|
||||
Config * config_new(void)
|
||||
{
|
||||
Config * config;
|
||||
|
@ -36,15 +49,11 @@ Config * config_new(void)
|
|||
return config;
|
||||
}
|
||||
|
||||
/* FIXME should be an API to avoid this */
|
||||
typedef struct _HashEntry
|
||||
{
|
||||
char * name;
|
||||
void * data;
|
||||
} HashEntry;
|
||||
|
||||
/* config_delete */
|
||||
void config_delete(Config * config)
|
||||
{
|
||||
unsigned int i;
|
||||
size_t i;
|
||||
HashEntry * hi;
|
||||
int j;
|
||||
HashEntry * hj;
|
||||
|
@ -63,17 +72,19 @@ void config_delete(Config * config)
|
|||
}
|
||||
|
||||
|
||||
/* useful */
|
||||
/* accessors */
|
||||
/* config_get */
|
||||
char * config_get(Config * config, char const * section, char const * variable)
|
||||
{
|
||||
void * p;
|
||||
Hash * h;
|
||||
|
||||
if((p = hash_get(config, section)) == NULL)
|
||||
if((h = hash_get(config, section)) == NULL)
|
||||
return NULL;
|
||||
return hash_get(p, variable);
|
||||
return hash_get(h, variable);
|
||||
}
|
||||
|
||||
|
||||
/* config_set */
|
||||
int config_set(Config * config, char const * section, char const * variable,
|
||||
char const * value)
|
||||
{
|
||||
|
@ -101,9 +112,12 @@ int config_set(Config * config, char const * section, char const * variable,
|
|||
}
|
||||
|
||||
|
||||
/* useful */
|
||||
/* config_load */
|
||||
static char * _load_section(FILE * fp);
|
||||
static char * _load_variable(FILE * fp, int c);
|
||||
static char * _load_value(FILE * fp);
|
||||
|
||||
int config_load(Config * config, char const * filename)
|
||||
{
|
||||
FILE * fp;
|
||||
|
@ -239,13 +253,15 @@ static char * _load_value(FILE * fp)
|
|||
}
|
||||
|
||||
|
||||
static int _save_section(Hash * h, unsigned int i, FILE * fp);
|
||||
/* config_save */
|
||||
static int _save_section(Hash * h, size_t i, FILE * fp);
|
||||
static int _save_variables(Hash * h, FILE * fp);
|
||||
|
||||
int config_save(Config * config, char const * filename)
|
||||
{
|
||||
FILE * fp;
|
||||
unsigned int i;
|
||||
unsigned int j;
|
||||
size_t i;
|
||||
size_t j;
|
||||
int ret = 0;
|
||||
|
||||
if((i = array_count(config)) == 0)
|
||||
|
@ -263,7 +279,7 @@ int config_save(Config * config, char const * filename)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int _save_section(Hash * h, unsigned int i, FILE * fp)
|
||||
static int _save_section(Hash * h, size_t i, FILE * fp)
|
||||
{
|
||||
HashEntry * he;
|
||||
|
||||
|
@ -283,8 +299,8 @@ static int _save_section(Hash * h, unsigned int i, FILE * fp)
|
|||
|
||||
static int _save_variables(Hash * h, FILE * fp)
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned int j;
|
||||
size_t i;
|
||||
size_t j;
|
||||
HashEntry * he;
|
||||
|
||||
i = array_count(h);
|
||||
|
|
Loading…
Reference in New Issue
Block a user