mirror of
https://git.kore.io/kore.git
synced 2024-11-11 20:59:07 +01:00
61 lines
1.8 KiB
C
61 lines
1.8 KiB
C
|
/*
|
||
|
* Copyright (c) 2014 Joris Vink <joris@coders.se>
|
||
|
*
|
||
|
* Permission to use, copy, modify, and distribute this software for any
|
||
|
* purpose with or without fee is hereby granted, provided that the above
|
||
|
* copyright notice and this permission notice appear in all copies.
|
||
|
*
|
||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||
|
*/
|
||
|
|
||
|
#ifndef _H_KORE_PGSQL
|
||
|
#define _H_KORE_PGSQL
|
||
|
|
||
|
#include <libpq-fe.h>
|
||
|
|
||
|
void kore_pgsql_init(void);
|
||
|
void kore_pgsql_handle(void *, int);
|
||
|
void kore_pgsql_cleanup(struct http_request *);
|
||
|
int kore_pgsql_query(struct http_request *, char *, int);
|
||
|
|
||
|
int kore_pgsql_ntuples(struct http_request *, int);
|
||
|
|
||
|
struct kore_pgsql {
|
||
|
u_int8_t state;
|
||
|
char *error;
|
||
|
PGresult *result;
|
||
|
};
|
||
|
|
||
|
#define KORE_PGSQL_STATE_INIT 1
|
||
|
#define KORE_PGSQL_STATE_WAIT 2
|
||
|
#define KORE_PGSQL_STATE_RESULT 3
|
||
|
#define KORE_PGSQL_STATE_ERROR 4
|
||
|
#define KORE_PGSQL_STATE_DONE 5
|
||
|
#define KORE_PGSQL_STATE_COMPLETE 6
|
||
|
|
||
|
#define KORE_PGSQL(r, q, i, s) \
|
||
|
do { \
|
||
|
if (r->pgsql[i] == NULL) \
|
||
|
kore_pgsql_query(r, q, i); \
|
||
|
if (r->pgsql[i] == NULL) \
|
||
|
return (KORE_RESULT_RETRY); \
|
||
|
switch (r->pgsql[i]->state) { \
|
||
|
case KORE_PGSQL_STATE_ERROR: \
|
||
|
case KORE_PGSQL_STATE_RESULT: \
|
||
|
s; \
|
||
|
return (KORE_RESULT_RETRY); \
|
||
|
case KORE_PGSQL_STATE_COMPLETE: \
|
||
|
break; \
|
||
|
default: \
|
||
|
return (KORE_RESULT_RETRY); \
|
||
|
} \
|
||
|
} while (0);
|
||
|
|
||
|
#endif
|