allow multiple result items

This commit is contained in:
whottgen 2005-04-01 15:10:07 +00:00
parent 7f31dace87
commit 75734d2899

View File

@ -59,6 +59,9 @@ typedef struct pg_container_handle_s {
char *dbname;
char *dbuser;
char *dbpass;
int allow_multiple_result_items;
char *multiple_result_item_separator;
int consider_many_items_as_failure;
} pg_container_handle_t;
typedef struct pg_worker_handle_s {
@ -183,8 +186,18 @@ int pg_worker_init(cfgl_t *cfg, void **handle) {
return -1;
}
pch->allow_multiple_result_items = atoi(findcfglx(pch->cfg, "allow_multiple_result_items", "0"));
pch->multiple_result_item_separator = findcfgl(pch->cfg, "multiple_result_item_separator");
pch->consider_many_items_as_failure = atoi(findcfglx(pch->cfg, "consider_many_items_as_failure", "0"));
if (pch->allow_multiple_result_items && pch->consider_many_items_as_failure) {
syslog(LOG_ERR, "pgworker pg_worker_init: allow_multiple_result_items and consider_many_items_as failure exclude each other");
return -1;
}
if (pch->allow_multiple_result_items && ! pch->multiple_result_item_separator) {
syslog(LOG_ERR, "pgworker pg_worker_init: multiple result items allowed but no separator given");
return -1;
}
*handle = pch;
return 0;
}
@ -364,25 +377,34 @@ static int process(pg_worker_handle_t *pwh, char *input, htbuffer_t *output) {
f = PQnfields(pgr);
syslog(LOG_DEBUG, "pgworker (%p) process PQnfields=%d", pwh, f);
if (t > 0) {
if (NULL == pwh->pch->output_format_string) {
if (f > 1)
syslog(LOG_WARNING,
"pgworker (%p) process: more than one result fields (%d) but no format string",
pwh, f);
htbuffer_strcpy(output, PQgetvalue(pgr, 0, 0));
res = SMM_OK;
} else {
if (0 == (res = populate_output_format(pwh, pgr, output, 0))) {
syslog(LOG_DEBUG, "pgworker (%p) process: output %s", pwh, output->buf);
res = SMM_OK;
} else {
syslog(LOG_ERR, "pgworker (%p) process failure in population of output", pwh);
}
}
} else {
if (t == 0) {
syslog(LOG_DEBUG, "pgworker (%p) process: no output", pwh);
res = SMM_NOT_FOUND_NOK;
} else if ((t > 1) && pwh->pch->consider_many_items_as_failure) {
syslog(LOG_DEBUG, "pgworker (%p) process: many items, considered as failure", pwh);
res = SMM_NOT_FOUND_NOK;
} else if (t > 0) {
t = (pwh->pch->allow_multiple_result_items) ? t : 1;
for (i = 0; i < t; i++) {
if (i > 0)
htbuffer_strcat(output, pwh->pch->multiple_result_item_separator);
if (NULL == pwh->pch->output_format_string) {
if (f > 1)
syslog(LOG_WARNING,
"pgworker (%p) process: more than one result fields (%d) but no format string",
pwh, f);
htbuffer_strcat(output, PQgetvalue(pgr, i, 0));
res = SMM_OK;
} else {
if (0 == (res = populate_output_format(pwh, pgr, output, i))) {
syslog(LOG_DEBUG, "pgworker (%p) process: output %s", pwh, output->buf);
res = SMM_OK;
} else {
syslog(LOG_ERR, "pgworker (%p) process failure in population of output", pwh);
break;
}
}
}
}
PQclear(pgr);