const char *pg_db = gtk_entry_get_text(GTK_ENTRY(entry_pg_db));
char *connection_string = NULL;
- if ( ! pg_host || strlen(pg_host) == 0 )
- {
- pgui_seterr("Fill in the server host.");
- return NULL;
- }
- if ( ! pg_port || strlen(pg_port) == 0 )
- {
- pgui_seterr("Fill in the server port.");
- return NULL;
- }
- if ( ! pg_user || strlen(pg_user) == 0 )
+ stringbuffer_t *sb = stringbuffer_create();
+
+ /* Read the host */
+ if ( pg_host && strlen(pg_host) > 0 )
{
- pgui_seterr("Fill in the user name.");
- return NULL;
+ vasbappend(sb, "host=%s ", pg_host);
}
- if ( ! pg_db || strlen(pg_db) == 0 )
- {
- pgui_seterr("Fill in the database name.");
- return NULL;
+
+ /* Read the port */
+ if ( pg_port && strlen(pg_port) > 0 )
+ {
+ if ( ! atoi(pg_port) )
+ {
+ pgui_seterr("Server port must be a number.");
+ stringbuffer_destroy(sb);
+ return NULL;
+ }
+ vasbappend(sb, "port=%s ", pg_port);
}
- if ( ! atoi(pg_port) )
+
+ /* Read the user name */
+ if ( pg_user && strlen(pg_user) > 0 )
{
- pgui_seterr("Server port must be a number.");
- return NULL;
+ vasbappend(sb, "user=%s ", pg_user);
}
- if ( ! lw_asprintf(&connection_string, "user=%s password=%s port=%s host=%s dbname=%s", pg_user, pg_pass, pg_port, pg_host, pg_db) )
+
+ /* Read the database name */
+ if ( pg_db && strlen(pg_db) > 0 )
{
- return NULL;
+ vasbappend(sb, "dbname=%s ", pg_db);
}
- if ( connection_string )
+
+ /* Read the password */
+ if ( pg_pass && strlen(pg_pass) > 0 )
{
- return connection_string;
+ vasbappend(sb, "password=%s ", pg_pass);
}
- return NULL;
+
+ /* Return the connection string */
+ connection_string = strdup(stringbuffer_getstring(sb));
+ stringbuffer_destroy(sb);
+ return connection_string;
}
static void