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