Code cleanup

This commit is contained in:
Pierre Pronchery 2014-04-28 05:02:14 +08:00
parent d2a0edd581
commit fe9b3570f2

View File

@ -91,7 +91,8 @@ AppTransport * apptransport_new(AppTransportMode mode,
AppTransport * transport; AppTransport * transport;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "DEBUG: %s(\"%s\", \"%s\")\n", __func__, plugin, name); fprintf(stderr, "DEBUG: %s(%u, \"%s\", \"%s\")\n", __func__, mode,
plugin, name);
#endif #endif
/* check the arguments */ /* check the arguments */
if(plugin == NULL || plugin[0] == '\0') if(plugin == NULL || plugin[0] == '\0')
@ -152,7 +153,8 @@ AppTransport * apptransport_new_app(AppTransportMode mode,
String * transport; String * transport;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "DEBUG: %s(\"%s\", \"%s\")\n", __func__, app, name); fprintf(stderr, "DEBUG: %s(%u, \"%s\", \"%s\")\n", __func__, mode, app,
name);
#endif #endif
if((n = _new_app_name(app, name)) == NULL) if((n = _new_app_name(app, name)) == NULL)
return NULL; return NULL;
@ -179,11 +181,14 @@ static String * _new_app_name(char const * app, char const * name)
error_set_code(1, "%s", "Invalid App"); error_set_code(1, "%s", "Invalid App");
return NULL; return NULL;
} }
if(name != NULL) if(name != NULL && name[0] != '\0')
return string_new(name); return string_new(name);
/* obtain the desired transport and name from the environment */ /* obtain the desired transport and name from the environment */
if((var = string_new_append("APPSERVER_", app, NULL)) == NULL) if((var = string_new_append("APPSERVER_", app, NULL)) == NULL)
return NULL; return NULL;
#ifdef DEBUG
fprintf(stderr, "DEBUG: %s() \"%s\"\n", __func__, var);
#endif
name = getenv(var); name = getenv(var);
string_delete(var); string_delete(var);
if(name == NULL) if(name == NULL)
@ -200,9 +205,10 @@ static String * _new_app_transport(String ** name)
/* XXX hard-coded default value */ /* XXX hard-coded default value */
return string_new("tcp"); return string_new("tcp");
/* XXX */ /* XXX */
*(p++) = '\0'; *p = '\0';
transport = *name; transport = string_new(*name);
if((*name = string_new(p)) == NULL) *p = ':';
if(transport == NULL || (*name = string_new(++p)) == NULL)
{ {
string_delete(transport); string_delete(transport);
return NULL; return NULL;