mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-24 22:58:21 +00:00
clean up formatting to conform to coding guidelines and fix some typos (issue #6260)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@8407 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -30,7 +30,7 @@ APPS=app_adsiprog.so app_alarmreceiver.so app_authenticate.so app_cdr.so \
|
|||||||
#
|
#
|
||||||
# Obsolete things...
|
# Obsolete things...
|
||||||
#
|
#
|
||||||
#APPS+=app_sql_postgres.so
|
APPS+=app_sql_postgres.so
|
||||||
#APPS+=app_sql_odbc.so
|
#APPS+=app_sql_odbc.so
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -96,7 +96,7 @@ app_curl.so: app_curl.o
|
|||||||
$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} $(CURLLIBS)
|
$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} $(CURLLIBS)
|
||||||
|
|
||||||
app_sql_postgres.o: app_sql_postgres.c
|
app_sql_postgres.o: app_sql_postgres.c
|
||||||
$(CC) -pipe -I/usr/local/pgsql/include $(CFLAGS) -c -o app_sql_postgres.o app_sql_postgres.c
|
$(CC) -pipe -I$(CROSS_COMPILE_TARGET)/usr/local/pgsql/include -I$(CROSS_COMPILE_TARGET)/usr/include/postgresql $(CFLAGS) -c -o app_sql_postgres.o app_sql_postgres.c
|
||||||
|
|
||||||
app_sql_postgres.so: app_sql_postgres.o
|
app_sql_postgres.so: app_sql_postgres.o
|
||||||
$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -L/usr/local/pgsql/lib -lpq
|
$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -L/usr/local/pgsql/lib -lpq
|
||||||
|
@@ -58,16 +58,16 @@ static char *descrip =
|
|||||||
"Syntax:\n"
|
"Syntax:\n"
|
||||||
" PGSQL(Connect var option-string)\n"
|
" PGSQL(Connect var option-string)\n"
|
||||||
" Connects to a database. Option string contains standard PostgreSQL\n"
|
" Connects to a database. Option string contains standard PostgreSQL\n"
|
||||||
" parameters like host=, dbname=, user=. Connection identifer returned\n"
|
" parameters like host=, dbname=, user=. Connection identifier returned\n"
|
||||||
" in ${var}\n"
|
" in ${var}.\n"
|
||||||
" PGSQL(Query var ${connection_identifier} query-string)\n"
|
" PGSQL(Query var ${connection_identifier} query-string)\n"
|
||||||
" Executes standard SQL query contained in query-string using established\n"
|
" Executes standard SQL query contained in query-string using established\n"
|
||||||
" connection identified by ${connection_identifier}. Reseult of query is\n"
|
" connection identified by ${connection_identifier}. Result of query is\n"
|
||||||
" is stored in ${var}.\n"
|
" stored in ${var}.\n"
|
||||||
" PGSQL(Fetch statusvar ${result_identifier} var1 var2 ... varn)\n"
|
" PGSQL(Fetch statusvar ${result_identifier} var1 var2 ... varn)\n"
|
||||||
" Fetches a single row from a result set contained in ${result_identifier}.\n"
|
" Fetches a single row from a result set contained in ${result_identifier}.\n"
|
||||||
" Assigns returned fields to ${var1} ... ${varn}. ${statusvar} is set TRUE\n"
|
" Assigns returned fields to ${var1} ... ${varn}. ${statusvar} is set TRUE\n"
|
||||||
" if additional rows exist in reseult set.\n"
|
" if additional rows exist in result set.\n"
|
||||||
" PGSQL(Clear ${result_identifier})\n"
|
" PGSQL(Clear ${result_identifier})\n"
|
||||||
" Frees memory and data structures associated with result set.\n"
|
" Frees memory and data structures associated with result set.\n"
|
||||||
" PGSQL(Disconnect ${connection_identifier})\n"
|
" PGSQL(Disconnect ${connection_identifier})\n"
|
||||||
@@ -92,7 +92,7 @@ Syntax of SQL commands :
|
|||||||
Fetch statusvar ${result_identifier} var1 var2 var3 ... varn
|
Fetch statusvar ${result_identifier} var1 var2 var3 ... varn
|
||||||
|
|
||||||
Fetches a row from the query and stores end-of-table status in
|
Fetches a row from the query and stores end-of-table status in
|
||||||
${statusvar} and columns in ${var1}..${varn}
|
${statusvar} and columns in ${var1} ... ${varn}
|
||||||
|
|
||||||
|
|
||||||
Clear ${result_identifier}
|
Clear ${result_identifier}
|
||||||
@@ -136,7 +136,8 @@ struct ast_PGSQL_id {
|
|||||||
|
|
||||||
AST_LIST_HEAD(PGSQLidshead, ast_PGSQL_id) PGSQLidshead;
|
AST_LIST_HEAD(PGSQLidshead, ast_PGSQL_id) PGSQLidshead;
|
||||||
|
|
||||||
static void *find_identifier(int identifier,int identifier_type) {
|
static void *find_identifier(int identifier, int identifier_type)
|
||||||
|
{
|
||||||
struct PGSQLidshead *headp;
|
struct PGSQLidshead *headp;
|
||||||
struct ast_PGSQL_id *i;
|
struct ast_PGSQL_id *i;
|
||||||
void *res = NULL;
|
void *res = NULL;
|
||||||
@@ -160,10 +161,11 @@ static void *find_identifier(int identifier,int identifier_type) {
|
|||||||
AST_LIST_UNLOCK(headp);
|
AST_LIST_UNLOCK(headp);
|
||||||
}
|
}
|
||||||
|
|
||||||
return(res);
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int add_identifier(int identifier_type,void *data) {
|
static int add_identifier(int identifier_type, void *data)
|
||||||
|
{
|
||||||
struct ast_PGSQL_id *i, *j;
|
struct ast_PGSQL_id *i, *j;
|
||||||
struct PGSQLidshead *headp;
|
struct PGSQLidshead *headp;
|
||||||
int maxidentifier = 0;
|
int maxidentifier = 0;
|
||||||
@@ -174,7 +176,7 @@ static int add_identifier(int identifier_type,void *data) {
|
|||||||
|
|
||||||
if (AST_LIST_LOCK(headp)) {
|
if (AST_LIST_LOCK(headp)) {
|
||||||
ast_log(LOG_WARNING, "Unable to lock identifiers list\n");
|
ast_log(LOG_WARNING, "Unable to lock identifiers list\n");
|
||||||
return(-1);
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
i = malloc(sizeof(struct ast_PGSQL_id));
|
i = malloc(sizeof(struct ast_PGSQL_id));
|
||||||
AST_LIST_TRAVERSE(headp, j, entries) {
|
AST_LIST_TRAVERSE(headp, j, entries) {
|
||||||
@@ -189,10 +191,12 @@ static int add_identifier(int identifier_type,void *data) {
|
|||||||
AST_LIST_INSERT_HEAD(headp, i, entries);
|
AST_LIST_INSERT_HEAD(headp, i, entries);
|
||||||
AST_LIST_UNLOCK(headp);
|
AST_LIST_UNLOCK(headp);
|
||||||
}
|
}
|
||||||
return(i->identifier);
|
|
||||||
|
return i->identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int del_identifier(int identifier,int identifier_type) {
|
static int del_identifier(int identifier, int identifier_type)
|
||||||
|
{
|
||||||
struct ast_PGSQL_id *i;
|
struct ast_PGSQL_id *i;
|
||||||
struct PGSQLidshead *headp;
|
struct PGSQLidshead *headp;
|
||||||
int found = 0;
|
int found = 0;
|
||||||
@@ -203,8 +207,7 @@ static int del_identifier(int identifier,int identifier_type) {
|
|||||||
ast_log(LOG_WARNING, "Unable to lock identifiers list\n");
|
ast_log(LOG_WARNING, "Unable to lock identifiers list\n");
|
||||||
} else {
|
} else {
|
||||||
AST_LIST_TRAVERSE(headp, i, entries) {
|
AST_LIST_TRAVERSE(headp, i, entries) {
|
||||||
if ((i->identifier==identifier) &&
|
if ((i->identifier == identifier) && (i->identifier_type == identifier_type)) {
|
||||||
(i->identifier_type==identifier_type)) {
|
|
||||||
AST_LIST_REMOVE(headp, i, entries);
|
AST_LIST_REMOVE(headp, i, entries);
|
||||||
free(i);
|
free(i);
|
||||||
found = 1;
|
found = 1;
|
||||||
@@ -214,27 +217,26 @@ static int del_identifier(int identifier,int identifier_type) {
|
|||||||
AST_LIST_UNLOCK(headp);
|
AST_LIST_UNLOCK(headp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found==0) {
|
if (!found) {
|
||||||
ast_log(LOG_WARNING, "Could not find identifier %d, identifier_type %d in list to delete\n", identifier, identifier_type);
|
ast_log(LOG_WARNING, "Could not find identifier %d, identifier_type %d in list to delete\n", identifier, identifier_type);
|
||||||
return(-1);
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
return(0);
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int aPGSQL_connect(struct ast_channel *chan, void *data) {
|
static int aPGSQL_connect(struct ast_channel *chan, void *data)
|
||||||
|
{
|
||||||
char *s1;
|
char *s1;
|
||||||
char s[100] = "";
|
char s[100] = "";
|
||||||
char *optionstring;
|
char *optionstring;
|
||||||
char *var;
|
char *var;
|
||||||
int l;
|
int l;
|
||||||
int res;
|
int res;
|
||||||
PGconn *karoto;
|
PGconn *PGSQLconn;
|
||||||
int id;
|
int id;
|
||||||
char *stringp = NULL;
|
char *stringp = NULL;
|
||||||
|
|
||||||
|
|
||||||
res = 0;
|
res = 0;
|
||||||
l = strlen(data) + 2;
|
l = strlen(data) + 2;
|
||||||
s1 = malloc(l);
|
s1 = malloc(l);
|
||||||
@@ -244,14 +246,13 @@ static int aPGSQL_connect(struct ast_channel *chan, void *data) {
|
|||||||
var = strsep(&stringp, " ");
|
var = strsep(&stringp, " ");
|
||||||
optionstring = strsep(&stringp, "\n");
|
optionstring = strsep(&stringp, "\n");
|
||||||
|
|
||||||
karoto = PQconnectdb(optionstring);
|
PGSQLconn = PQconnectdb(optionstring);
|
||||||
if (PQstatus(karoto) == CONNECTION_BAD) {
|
if (PQstatus(PGSQLconn) == CONNECTION_BAD) {
|
||||||
ast_log(LOG_WARNING,"Connection to database using '%s' failed. postgress reports : %s\n", optionstring,
|
ast_log(LOG_WARNING, "Connection to database using '%s' failed. postgress reports : %s\n", optionstring, PQerrorMessage(PGSQLconn));
|
||||||
PQerrorMessage(karoto));
|
|
||||||
res = -1;
|
res = -1;
|
||||||
} else {
|
} else {
|
||||||
ast_log(LOG_WARNING,"adding identifier\n");
|
ast_log(LOG_WARNING, "Adding identifier\n");
|
||||||
id=add_identifier(AST_PGSQL_ID_CONNID,karoto);
|
id = add_identifier(AST_PGSQL_ID_CONNID, PGSQLconn);
|
||||||
snprintf(s, sizeof(s), "%d", id);
|
snprintf(s, sizeof(s), "%d", id);
|
||||||
pbx_builtin_setvar_helper(chan, var, s);
|
pbx_builtin_setvar_helper(chan, var, s);
|
||||||
}
|
}
|
||||||
@@ -260,21 +261,19 @@ static int aPGSQL_connect(struct ast_channel *chan, void *data) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int aPGSQL_query(struct ast_channel *chan, void *data) {
|
static int aPGSQL_query(struct ast_channel *chan, void *data)
|
||||||
|
{
|
||||||
|
|
||||||
char *s1, *s2, *s3, *s4;
|
char *s1, *s2, *s3, *s4;
|
||||||
char s[100] = "";
|
char s[100] = "";
|
||||||
char *querystring;
|
char *querystring;
|
||||||
char *var;
|
char *var;
|
||||||
int l;
|
int l;
|
||||||
int res, nres;
|
int res, nres;
|
||||||
PGconn *karoto;
|
PGconn *PGSQLconn;
|
||||||
PGresult *PGSQLres;
|
PGresult *PGSQLres;
|
||||||
int id, id1;
|
int id, id1;
|
||||||
char *stringp = NULL;
|
char *stringp = NULL;
|
||||||
|
|
||||||
|
|
||||||
res = 0;
|
res = 0;
|
||||||
l = strlen(data) + 2;
|
l = strlen(data) + 2;
|
||||||
s1 = malloc(l);
|
s1 = malloc(l);
|
||||||
@@ -288,14 +287,13 @@ static int aPGSQL_query(struct ast_channel *chan, void *data) {
|
|||||||
s4 = strsep(&stringp, " ");
|
s4 = strsep(&stringp, " ");
|
||||||
id = atoi(s4);
|
id = atoi(s4);
|
||||||
querystring = strsep(&stringp, "\n");
|
querystring = strsep(&stringp, "\n");
|
||||||
if ((karoto=find_identifier(id,AST_PGSQL_ID_CONNID))==NULL) {
|
if (!(PGSQLconn = find_identifier(id, AST_PGSQL_ID_CONNID))) {
|
||||||
ast_log(LOG_WARNING, "Invalid connection identifier %d passed in aPGSQL_query\n", id);
|
ast_log(LOG_WARNING, "Invalid connection identifier %d passed in aPGSQL_query\n", id);
|
||||||
res = -1;
|
res = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
PGSQLres=PQexec(karoto,querystring);
|
if (!(PGSQLres = PQexec(PGSQLconn, querystring))) {
|
||||||
if (PGSQLres==NULL) {
|
ast_log(LOG_WARNING, "aPGSQL_query: Connection Error (connection identifier = %d, error message : %s)\n", id, PQerrorMessage(PGSQLconn));
|
||||||
ast_log(LOG_WARNING,"aPGSQL_query: Connection Error (connection identifier = %d, error message : %s)\n",id,PQerrorMessage(karoto));
|
|
||||||
res = -1;
|
res = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -316,20 +314,20 @@ static int aPGSQL_query(struct ast_channel *chan, void *data) {
|
|||||||
free(s1);
|
free(s1);
|
||||||
free(s2);
|
free(s2);
|
||||||
|
|
||||||
return(res);
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int aPGSQL_fetch(struct ast_channel *chan, void *data)
|
||||||
static int aPGSQL_fetch(struct ast_channel *chan, void *data) {
|
{
|
||||||
|
char *s1, *s2, *fetchid_var, *s4, *s5, *s6;
|
||||||
char *s1,*s2,*fetchid_var,*s4,*s5,*s6,*s7;
|
const char *s7;
|
||||||
char s[100];
|
char s[100];
|
||||||
char *var;
|
char *var;
|
||||||
int l;
|
int l;
|
||||||
int res;
|
int res;
|
||||||
PGresult *PGSQLres;
|
PGresult *PGSQLres;
|
||||||
int id, id1, i, j, fnd;
|
int id, id1, i, j, fnd;
|
||||||
int *lalares=NULL;
|
int *identp = NULL;
|
||||||
int nres;
|
int nres;
|
||||||
struct ast_var_t *variables;
|
struct ast_var_t *variables;
|
||||||
struct varshead *headp;
|
struct varshead *headp;
|
||||||
@@ -351,31 +349,31 @@ static int aPGSQL_fetch(struct ast_channel *chan, void *data) {
|
|||||||
fnd = 0;
|
fnd = 0;
|
||||||
|
|
||||||
AST_LIST_TRAVERSE(headp, variables, entries) {
|
AST_LIST_TRAVERSE(headp, variables, entries) {
|
||||||
if (strncasecmp(ast_var_name(variables),fetchid_var,strlen(fetchid_var))==0) {
|
if (!(strncasecmp(ast_var_name(variables), fetchid_var, strlen(fetchid_var)))) {
|
||||||
s7 = ast_var_value(variables);
|
s7 = ast_var_value(variables);
|
||||||
fnd = 1;
|
fnd = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fnd==0) {
|
if (!fnd) {
|
||||||
s7 = "0";
|
s7 = "0";
|
||||||
pbx_builtin_setvar_helper(chan, fetchid_var, s7);
|
pbx_builtin_setvar_helper(chan, fetchid_var, s7);
|
||||||
}
|
}
|
||||||
|
|
||||||
s4 = strsep(&stringp, " ");
|
s4 = strsep(&stringp, " ");
|
||||||
id = atoi(s4); /* resultid */
|
id = atoi(s4); /* resultid */
|
||||||
if ((PGSQLres=find_identifier(id,AST_PGSQL_ID_RESID))==NULL) {
|
if (!(PGSQLres = find_identifier(id, AST_PGSQL_ID_RESID))) {
|
||||||
ast_log(LOG_WARNING, "Invalid result identifier %d passed in aPGSQL_fetch\n", id);
|
ast_log(LOG_WARNING, "Invalid result identifier %d passed in aPGSQL_fetch\n", id);
|
||||||
res = -1;
|
res = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
id = atoi(s7); /*fetchid */
|
id = atoi(s7); /*fetchid */
|
||||||
if ((lalares=find_identifier(id,AST_PGSQL_ID_FETCHID))==NULL) {
|
if (!(identp = find_identifier(id, AST_PGSQL_ID_FETCHID))) {
|
||||||
i = 0; /* fetching the very first row */
|
i = 0; /* fetching the very first row */
|
||||||
} else {
|
} else {
|
||||||
i=*lalares;
|
i = *identp;
|
||||||
free(lalares);
|
free(identp);
|
||||||
del_identifier(id, AST_PGSQL_ID_FETCHID); /* will re-add it a bit later */
|
del_identifier(id, AST_PGSQL_ID_FETCHID); /* will re-add it a bit later */
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -383,22 +381,20 @@ static int aPGSQL_fetch(struct ast_channel *chan, void *data) {
|
|||||||
nres = PQnfields(PGSQLres);
|
nres = PQnfields(PGSQLres);
|
||||||
ast_log(LOG_WARNING, "ast_PGSQL_fetch : nres = %d i = %d ;\n", nres, i);
|
ast_log(LOG_WARNING, "ast_PGSQL_fetch : nres = %d i = %d ;\n", nres, i);
|
||||||
for (j = 0; j < nres; j++) {
|
for (j = 0; j < nres; j++) {
|
||||||
s5=strsep(&stringp," ");
|
if (!(s5 = strsep(&stringp, " "))) {
|
||||||
if (s5==NULL) {
|
|
||||||
ast_log(LOG_WARNING, "ast_PGSQL_fetch : More tuples (%d) than variables (%d)\n", nres, j);
|
ast_log(LOG_WARNING, "ast_PGSQL_fetch : More tuples (%d) than variables (%d)\n", nres, j);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
s6=PQgetvalue(PGSQLres,i,j);
|
if (!(s6 = PQgetvalue(PGSQLres, i, j))) {
|
||||||
if (s6==NULL) {
|
ast_log(LOG_WARNING, "PQgetvalue(res, %d, %d) returned NULL in ast_PGSQL_fetch\n", i, j);
|
||||||
ast_log(LOG_WARNING,"PWgetvalue(res,%d,%d) returned NULL in ast_PGSQL_fetch\n",i,j);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ast_log(LOG_WARNING, "===setting variable '%s' to '%s'\n", s5, s6);
|
ast_log(LOG_WARNING, "===setting variable '%s' to '%s'\n", s5, s6);
|
||||||
pbx_builtin_setvar_helper(chan, s5, s6);
|
pbx_builtin_setvar_helper(chan, s5, s6);
|
||||||
}
|
}
|
||||||
lalares=malloc(sizeof(int));
|
identp = malloc(sizeof(int));
|
||||||
*lalares = ++i; /* advance to the next row */
|
*identp = ++i; /* advance to the next row */
|
||||||
id1 = add_identifier(AST_PGSQL_ID_FETCHID,lalares);
|
id1 = add_identifier(AST_PGSQL_ID_FETCHID, identp);
|
||||||
} else {
|
} else {
|
||||||
ast_log(LOG_WARNING, "ast_PGSQL_fetch : EOF\n");
|
ast_log(LOG_WARNING, "ast_PGSQL_fetch : EOF\n");
|
||||||
id1 = 0; /* no more rows */
|
id1 = 0; /* no more rows */
|
||||||
@@ -411,18 +407,18 @@ static int aPGSQL_fetch(struct ast_channel *chan, void *data) {
|
|||||||
|
|
||||||
free(s1);
|
free(s1);
|
||||||
free(s2);
|
free(s2);
|
||||||
return(res);
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int aPGSQL_reset(struct ast_channel *chan, void *data) {
|
static int aPGSQL_reset(struct ast_channel *chan, void *data)
|
||||||
|
{
|
||||||
char *s1, *s3;
|
char *s1, *s3;
|
||||||
int l;
|
int l;
|
||||||
PGconn *karoto;
|
PGconn *PGSQLconn;
|
||||||
int id;
|
int id;
|
||||||
char *stringp = NULL;
|
char *stringp = NULL;
|
||||||
|
|
||||||
|
|
||||||
l = strlen(data) + 2;
|
l = strlen(data) + 2;
|
||||||
s1 = malloc(l);
|
s1 = malloc(l);
|
||||||
strncpy(s1, data, l - 1);
|
strncpy(s1, data, l - 1);
|
||||||
@@ -430,25 +426,25 @@ static int aPGSQL_reset(struct ast_channel *chan, void *data) {
|
|||||||
strsep(&stringp, " "); /* eat the first token, we already know it :P */
|
strsep(&stringp, " "); /* eat the first token, we already know it :P */
|
||||||
s3 = strsep(&stringp, " ");
|
s3 = strsep(&stringp, " ");
|
||||||
id = atoi(s3);
|
id = atoi(s3);
|
||||||
if ((karoto=find_identifier(id,AST_PGSQL_ID_CONNID))==NULL) {
|
if (!(PGSQLconn = find_identifier(id, AST_PGSQL_ID_CONNID))) {
|
||||||
ast_log(LOG_WARNING, "Invalid connection identifier %d passed in aPGSQL_reset\n", id);
|
ast_log(LOG_WARNING, "Invalid connection identifier %d passed in aPGSQL_reset\n", id);
|
||||||
} else {
|
} else {
|
||||||
PQreset(karoto);
|
PQreset(PGSQLconn);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(s1);
|
free(s1);
|
||||||
return(0);
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int aPGSQL_clear(struct ast_channel *chan, void *data) {
|
static int aPGSQL_clear(struct ast_channel *chan, void *data)
|
||||||
|
{
|
||||||
char *s1, *s3;
|
char *s1, *s3;
|
||||||
int l;
|
int l;
|
||||||
PGresult *karoto;
|
PGresult *PGSQLres;
|
||||||
int id;
|
int id;
|
||||||
char *stringp = NULL;
|
char *stringp = NULL;
|
||||||
|
|
||||||
|
|
||||||
l = strlen(data) + 2;
|
l = strlen(data) + 2;
|
||||||
s1 = malloc(l);
|
s1 = malloc(l);
|
||||||
strncpy(s1, data, l - 1);
|
strncpy(s1, data, l - 1);
|
||||||
@@ -456,29 +452,26 @@ static int aPGSQL_clear(struct ast_channel *chan, void *data) {
|
|||||||
strsep(&stringp, " "); /* eat the first token, we already know it :P */
|
strsep(&stringp, " "); /* eat the first token, we already know it :P */
|
||||||
s3 = strsep(&stringp, " ");
|
s3 = strsep(&stringp, " ");
|
||||||
id = atoi(s3);
|
id = atoi(s3);
|
||||||
if ((karoto=find_identifier(id,AST_PGSQL_ID_RESID))==NULL) {
|
if (!(PGSQLres = find_identifier(id, AST_PGSQL_ID_RESID))) {
|
||||||
ast_log(LOG_WARNING, "Invalid result identifier %d passed in aPGSQL_clear\n", id);
|
ast_log(LOG_WARNING, "Invalid result identifier %d passed in aPGSQL_clear\n", id);
|
||||||
} else {
|
} else {
|
||||||
PQclear(karoto);
|
PQclear(PGSQLres);
|
||||||
del_identifier(id, AST_PGSQL_ID_RESID);
|
del_identifier(id, AST_PGSQL_ID_RESID);
|
||||||
}
|
}
|
||||||
free(s1);
|
|
||||||
return(0);
|
|
||||||
|
|
||||||
|
free(s1);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int aPGSQL_disconnect(struct ast_channel *chan, void *data)
|
||||||
|
{
|
||||||
|
|
||||||
static int aPGSQL_disconnect(struct ast_channel *chan, void *data) {
|
|
||||||
|
|
||||||
char *s1, *s3;
|
char *s1, *s3;
|
||||||
int l;
|
int l;
|
||||||
PGconn *karoto;
|
PGconn *PGSQLconn;
|
||||||
int id;
|
int id;
|
||||||
char *stringp = NULL;
|
char *stringp = NULL;
|
||||||
|
|
||||||
|
|
||||||
l = strlen(data) + 2;
|
l = strlen(data) + 2;
|
||||||
s1 = malloc(l);
|
s1 = malloc(l);
|
||||||
strncpy(s1, data, l - 1);
|
strncpy(s1, data, l - 1);
|
||||||
@@ -486,20 +479,22 @@ static int aPGSQL_disconnect(struct ast_channel *chan, void *data) {
|
|||||||
strsep(&stringp, " "); /* eat the first token, we already know it :P */
|
strsep(&stringp, " "); /* eat the first token, we already know it :P */
|
||||||
s3 = strsep(&stringp, " ");
|
s3 = strsep(&stringp, " ");
|
||||||
id = atoi(s3);
|
id = atoi(s3);
|
||||||
if ((karoto=find_identifier(id,AST_PGSQL_ID_CONNID))==NULL) {
|
if (!(PGSQLconn = find_identifier(id, AST_PGSQL_ID_CONNID))) {
|
||||||
ast_log(LOG_WARNING, "Invalid connection identifier %d passed in aPGSQL_disconnect\n", id);
|
ast_log(LOG_WARNING, "Invalid connection identifier %d passed in aPGSQL_disconnect\n", id);
|
||||||
} else {
|
} else {
|
||||||
PQfinish(karoto);
|
PQfinish(PGSQLconn);
|
||||||
del_identifier(id, AST_PGSQL_ID_CONNID);
|
del_identifier(id, AST_PGSQL_ID_CONNID);
|
||||||
}
|
}
|
||||||
free(s1);
|
|
||||||
return(0);
|
|
||||||
|
|
||||||
|
free(s1);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int aPGSQL_debug(struct ast_channel *chan, void *data) {
|
static int aPGSQL_debug(struct ast_channel *chan, void *data)
|
||||||
|
{
|
||||||
ast_log(LOG_WARNING, "Debug : %s\n", (char *)data);
|
ast_log(LOG_WARNING, "Debug : %s\n", (char *)data);
|
||||||
return(0);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int PGSQL_exec(struct ast_channel *chan, void *data)
|
static int PGSQL_exec(struct ast_channel *chan, void *data)
|
||||||
@@ -516,19 +511,19 @@ static int PGSQL_exec(struct ast_channel *chan, void *data)
|
|||||||
|
|
||||||
result = 0;
|
result = 0;
|
||||||
|
|
||||||
if (strncasecmp("connect",data,strlen("connect"))==0) {
|
if (!(strncasecmp("connect", data, strlen("connect")))) {
|
||||||
result = (aPGSQL_connect(chan, data));
|
result = (aPGSQL_connect(chan, data));
|
||||||
} else if (strncasecmp("query",data,strlen("query"))==0) {
|
} else if (!(strncasecmp("query", data, strlen("query")))) {
|
||||||
result = (aPGSQL_query(chan, data));
|
result = (aPGSQL_query(chan, data));
|
||||||
} else if (strncasecmp("fetch",data,strlen("fetch"))==0) {
|
} else if (!(strncasecmp("fetch", data, strlen("fetch")))) {
|
||||||
result = (aPGSQL_fetch(chan, data));
|
result = (aPGSQL_fetch(chan, data));
|
||||||
} else if (strncasecmp("reset",data,strlen("reset"))==0) {
|
} else if (!(strncasecmp("reset", data, strlen("reset")))) {
|
||||||
result = (aPGSQL_reset(chan, data));
|
result = (aPGSQL_reset(chan, data));
|
||||||
} else if (strncasecmp("clear",data,strlen("clear"))==0) {
|
} else if (!(strncasecmp("clear", data, strlen("clear")))) {
|
||||||
result = (aPGSQL_clear(chan, data));
|
result = (aPGSQL_clear(chan, data));
|
||||||
} else if (strncasecmp("debug",data,strlen("debug"))==0) {
|
} else if (!(strncasecmp("debug", data, strlen("debug")))) {
|
||||||
result = (aPGSQL_debug(chan, data));
|
result = (aPGSQL_debug(chan, data));
|
||||||
} else if (strncasecmp("disconnect",data,strlen("disconnect"))==0) {
|
} else if (!(strncasecmp("disconnect", data, strlen("disconnect")))) {
|
||||||
result = (aPGSQL_disconnect(chan, data));
|
result = (aPGSQL_disconnect(chan, data));
|
||||||
} else {
|
} else {
|
||||||
ast_log(LOG_WARNING, "Unknown APP_PGSQL argument : %s\n", (char *)data);
|
ast_log(LOG_WARNING, "Unknown APP_PGSQL argument : %s\n", (char *)data);
|
||||||
@@ -542,21 +537,14 @@ static int PGSQL_exec(struct ast_channel *chan, void *data)
|
|||||||
|
|
||||||
int unload_module(void)
|
int unload_module(void)
|
||||||
{
|
{
|
||||||
int res;
|
int res = ast_unregister_application(app);
|
||||||
|
|
||||||
res = ast_unregister_application(app);
|
|
||||||
|
|
||||||
STANDARD_HANGUP_LOCALUSERS;
|
STANDARD_HANGUP_LOCALUSERS;
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int load_module(void)
|
int load_module(void)
|
||||||
{
|
{
|
||||||
struct PGSQLidshead *headp;
|
struct PGSQLidshead *headp = &PGSQLidshead;
|
||||||
|
|
||||||
headp=&PGSQLidshead;
|
|
||||||
|
|
||||||
AST_LIST_HEAD_INIT(headp);
|
AST_LIST_HEAD_INIT(headp);
|
||||||
return ast_register_application(app, PGSQL_exec, synopsis, descrip);
|
return ast_register_application(app, PGSQL_exec, synopsis, descrip);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user