提交 18feeb10 authored 作者: Daniel Swarbrick's avatar Daniel Swarbrick

Coding style, fix some C90 warnings about mixed decls/code

上级 5401c604
...@@ -8,6 +8,7 @@ else ...@@ -8,6 +8,7 @@ else
LOCAL_LDFLAGS=-L/usr/postgres/8.3/lib -R/usr/postgres/8.3/lib -lpq -static LOCAL_LDFLAGS=-L/usr/postgres/8.3/lib -R/usr/postgres/8.3/lib -lpq -static
endif endif
else else
LOCAL_CFLAGS=-I/usr/include/postgresql
LOCAL_LDFLAGS=-lpq -static LOCAL_LDFLAGS=-lpq -static
endif endif
include ../../../../build/modmake.rules include ../../../../build/modmake.rules
...@@ -190,6 +190,8 @@ static int save_cdr(const char* const table, const char* const template, const c ...@@ -190,6 +190,8 @@ static int save_cdr(const char* const table, const char* const template, const c
char* query; char* query;
const char* const query_template = "INSERT INTO %s (%s) VALUES (%s);"; const char* const query_template = "INSERT INTO %s (%s) VALUES (%s);";
PGresult* res; PGresult* res;
char *spaceColumns, *pt, *nullValues, *temp, *tp;
int spaceCounter = 0, nullCounter = 0, charCounter = 0;
if (!table || !*table || !template || !*template || !cdr || !*cdr) { if (!table || !*table || !template || !*template || !cdr || !*cdr) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Bad parameter\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Bad parameter\n");
...@@ -218,112 +220,112 @@ static int save_cdr(const char* const table, const char* const template, const c ...@@ -218,112 +220,112 @@ static int save_cdr(const char* const table, const char* const template, const c
} }
} }
vlen = p - values; vlen = p - values;
/*
Patch for changing spaces (; ;) in the template paterns to NULL (ex.) ; ; --PACH--> null /*
- added new functionality - space removing * Patch for changing spaces (; ;) in the template paterns to NULL
*/ * (eg.) ; ; --PATCH--> null
char *spaceColumns; * - added new functionality - space removing
int spaceCounter=0; */
for (p=columns; *p; ++p) for (p = columns; *p; ++p) {
{ if (*p == ' ') {
if (*p==' ')
{
spaceCounter++; spaceCounter++;
} }
} }
spaceColumns = (char*)malloc(clen-spaceCounter+1);
char *pt=spaceColumns; spaceColumns = (char *) malloc(clen - spaceCounter + 1);
for (p=columns; *p; ++p) pt = spaceColumns;
{
if (*p!=' ') for (p = columns; *p; ++p) {
{ if (*p != ' ') {
*pt=*p; *pt=*p;
pt++; pt++;
} }
} }
*pt=0;
pt=columns; *pt = 0;
columns=spaceColumns; pt = columns;
columns = spaceColumns;
free(pt); free(pt);
char *nullValues;
int nullCounter=0; for (p = values; *p; ++p) {
int charCounter=0; if (*p == ',') {
for (p=values; *p; ++p) if (charCounter == 0) {
{
if (*p==',')
{
if (charCounter==0)
{
nullCounter++; nullCounter++;
} }
charCounter=0; charCounter = 0;
} } else if (*p != ' ' && *p != '\'') {
else if (*p!=' ' && *p!='\'')
{
charCounter++; charCounter++;
} }
} }
if (charCounter==0)
{ if (charCounter == 0) {
nullCounter++; nullCounter++;
} }
charCounter=0;
nullCounter*=4; charCounter = 0;
vlen+=nullCounter; nullCounter *= 4;
nullValues=(char*)malloc(strlen(values)+nullCounter+1); vlen += nullCounter;
charCounter=0; nullValues = (char *) malloc(strlen(values) + nullCounter + 1);
char *temp=nullValues; charCounter = 0;
char *tp=nullValues; temp = nullValues;
for (p=values; *p; ++tp,++p) tp = nullValues;
{
if (*p==',') for (p = values; *p; ++tp, ++p) {
{ if (*p == ',') {
if (charCounter==0) if (charCounter == 0) {
{ temp++;
*temp = 'n';
temp++;
if (temp == tp) tp++;
*temp = 'u';
temp++; temp++;
*temp='n';temp++; if (temp == tp) tp++;
if (temp==tp) tp++; *temp = 'l';
*temp='u';temp++; temp++;
if (temp==tp) tp++; if (temp == tp) tp++;
*temp='l';temp++; *temp = 'l';
if (temp==tp) tp++; temp++;
*temp='l';temp++; while (temp != tp) {
while (temp!=tp) *temp = ' ';
{ temp++;
*temp=' ';temp++; }
} }
} charCounter = 0;
charCounter=0; temp = tp;
temp=tp; } else if (*p != ' ' && *p != '\'') {
}
else if (*p!=' ' && *p!='\'')
{
charCounter++; charCounter++;
} }
*tp=*p; *tp = *p;
} }
if (charCounter==0)
{ if (charCounter == 0) {
temp++;
*temp = 'n';
temp++;
if (temp == tp) tp++;
*temp = 'u';
temp++; temp++;
*temp='n';temp++; if (temp == tp) tp++;
if (temp==tp) tp++; *temp = 'l';
*temp='u';temp++; temp++;
if (temp==tp) tp++; if (temp == tp) tp++;
*temp='l';temp++; *temp = 'l';
if (temp==tp) tp++; temp++;
*temp='l';temp++; while (temp != tp) {
while (temp!=tp) *temp = ' ';
{ temp++;
*temp=' ';temp++; }
} }
}
charCounter=0; charCounter = 0;
temp=tp; temp = tp;
*tp=0; *tp = 0;
tp=values; tp = values;
values=nullValues; values = nullValues;
free(tp); free(tp);
//-----------------------------END_OF_PATCH----------------------------------------------------------------
//----------------------------- END_OF_PATCH -------------------------------
query = malloc(strlen(query_template) - 6 + strlen(table) + clen + vlen + 1); query = malloc(strlen(query_template) - 6 + strlen(table) + clen + vlen + 1);
sprintf(query, query_template, table, columns, values); sprintf(query, query_template, table, columns, values);
free(columns); free(columns);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论