mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-26 14:27:14 +00:00
Merged revisions 149687 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk ........ r149687 | tilghman | 2008-10-15 14:07:39 -0500 (Wed, 15 Oct 2008) | 7 lines Permit data fields to contain more than 255 characters. (closes issue #13631) Reported by: seanbright Patches: 20081015__bug13631.diff.txt uploaded by Corydon76 (license 14) Tested by: blitzrage ........ git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.1@149688 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -85,6 +85,9 @@ AST_RWLIST_HEAD_STATIC(queries, acf_odbc_query);
|
|||||||
|
|
||||||
static int resultcount = 0;
|
static int resultcount = 0;
|
||||||
|
|
||||||
|
AST_THREADSTORAGE(coldata_buf);
|
||||||
|
AST_THREADSTORAGE(colnames_buf);
|
||||||
|
|
||||||
static void odbc_datastore_free(void *data)
|
static void odbc_datastore_free(void *data)
|
||||||
{
|
{
|
||||||
struct odbc_datastore *result = data;
|
struct odbc_datastore *result = data;
|
||||||
@@ -256,7 +259,8 @@ static int acf_odbc_read(struct ast_channel *chan, const char *cmd, char *s, cha
|
|||||||
{
|
{
|
||||||
struct odbc_obj *obj = NULL;
|
struct odbc_obj *obj = NULL;
|
||||||
struct acf_odbc_query *query;
|
struct acf_odbc_query *query;
|
||||||
char varname[15], colnames[2048] = "", rowcount[12] = "-1";
|
char varname[15], rowcount[12] = "-1";
|
||||||
|
struct ast_str *colnames = ast_str_thread_get(&colnames_buf, 16);
|
||||||
int res, x, y, buflen = 0, escapecommas, rowlimit = 1, dsn, bogus_chan = 0;
|
int res, x, y, buflen = 0, escapecommas, rowlimit = 1, dsn, bogus_chan = 0;
|
||||||
AST_DECLARE_APP_ARGS(args,
|
AST_DECLARE_APP_ARGS(args,
|
||||||
AST_APP_ARG(field)[100];
|
AST_APP_ARG(field)[100];
|
||||||
@@ -385,42 +389,43 @@ static int acf_odbc_read(struct ast_channel *chan, const char *cmd, char *s, cha
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (y = 0; y < rowlimit; y++) {
|
for (y = 0; y < rowlimit; y++) {
|
||||||
*buf = '\0';
|
|
||||||
for (x = 0; x < colcount; x++) {
|
for (x = 0; x < colcount; x++) {
|
||||||
int i;
|
int i;
|
||||||
char coldata[256];
|
struct ast_str *coldata = ast_str_thread_get(&coldata_buf, 16);
|
||||||
|
|
||||||
if (y == 0) {
|
if (y == 0) {
|
||||||
char colname[256];
|
char colname[256];
|
||||||
int namelen;
|
SQLULEN maxcol;
|
||||||
|
|
||||||
res = SQLDescribeCol(stmt, x + 1, (unsigned char *)colname, sizeof(colname), &collength, NULL, NULL, NULL, NULL);
|
res = SQLDescribeCol(stmt, x + 1, (unsigned char *)colname, sizeof(colname), &collength, NULL, &maxcol, NULL, NULL);
|
||||||
|
ast_debug(3, "Got collength of %d and maxcol of %d for column '%s' (offset %d)\n", (int)collength, (int)maxcol, colname, x);
|
||||||
if (((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) || collength == 0) {
|
if (((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) || collength == 0) {
|
||||||
snprintf(colname, sizeof(colname), "field%d", x);
|
snprintf(colname, sizeof(colname), "field%d", x);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ast_strlen_zero(colnames))
|
if (coldata->len < maxcol + 1) {
|
||||||
strncat(colnames, ",", sizeof(colnames) - strlen(colnames) - 1);
|
ast_str_make_space(&coldata, maxcol + 1);
|
||||||
namelen = strlen(colnames);
|
}
|
||||||
|
|
||||||
|
if (colnames->used) {
|
||||||
|
ast_str_append(&colnames, 0, ",");
|
||||||
|
}
|
||||||
|
ast_str_make_space(&colnames, strlen(colname) * 2 + 1 + colnames->used);
|
||||||
|
|
||||||
/* Copy data, encoding '\' and ',' for the argument parser */
|
/* Copy data, encoding '\' and ',' for the argument parser */
|
||||||
for (i = 0; i < sizeof(colname); i++) {
|
for (i = 0; i < sizeof(colname); i++) {
|
||||||
if (escapecommas && (colname[i] == '\\' || colname[i] == ',')) {
|
if (escapecommas && (colname[i] == '\\' || colname[i] == ',')) {
|
||||||
colnames[namelen++] = '\\';
|
colnames->str[colnames->used++] = '\\';
|
||||||
}
|
}
|
||||||
colnames[namelen++] = colname[i];
|
colnames->str[colnames->used++] = colname[i];
|
||||||
|
|
||||||
if (namelen >= sizeof(colnames) - 2) {
|
if (colname[i] == '\0') {
|
||||||
colnames[namelen >= sizeof(colnames) ? sizeof(colnames) - 1 : namelen] = '\0';
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (colname[i] == '\0')
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resultset) {
|
if (resultset) {
|
||||||
void *tmp = ast_realloc(resultset, sizeof(*resultset) + strlen(colnames) + 1);
|
void *tmp = ast_realloc(resultset, sizeof(*resultset) + colnames->used + 1);
|
||||||
if (!tmp) {
|
if (!tmp) {
|
||||||
ast_log(LOG_ERROR, "No space for a new resultset?\n");
|
ast_log(LOG_ERROR, "No space for a new resultset?\n");
|
||||||
ast_free(resultset);
|
ast_free(resultset);
|
||||||
@@ -436,14 +441,15 @@ static int acf_odbc_read(struct ast_channel *chan, const char *cmd, char *s, cha
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
resultset = tmp;
|
resultset = tmp;
|
||||||
strcpy((char *)resultset + sizeof(*resultset), colnames);
|
strcpy((char *)resultset + sizeof(*resultset), colnames->str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buflen = strlen(buf);
|
buflen = strlen(buf);
|
||||||
res = SQLGetData(stmt, x + 1, SQL_CHAR, coldata, sizeof(coldata), &indicator);
|
res = SQLGetData(stmt, x + 1, SQL_CHAR, coldata->str, coldata->len, &indicator);
|
||||||
if (indicator == SQL_NULL_DATA) {
|
if (indicator == SQL_NULL_DATA) {
|
||||||
coldata[0] = '\0';
|
ast_debug(3, "Got NULL data\n");
|
||||||
|
ast_str_reset(coldata);
|
||||||
res = SQL_SUCCESS;
|
res = SQL_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -454,25 +460,30 @@ static int acf_odbc_read(struct ast_channel *chan, const char *cmd, char *s, cha
|
|||||||
goto end_acf_read;
|
goto end_acf_read;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ast_debug(2, "Got coldata of '%s'\n", coldata->str);
|
||||||
|
coldata->used = strlen(coldata->str);
|
||||||
|
|
||||||
/* Copy data, encoding '\' and ',' for the argument parser */
|
/* Copy data, encoding '\' and ',' for the argument parser */
|
||||||
for (i = 0; i < sizeof(coldata); i++) {
|
for (i = 0; i < coldata->used; i++) {
|
||||||
if (escapecommas && (coldata[i] == '\\' || coldata[i] == ',')) {
|
if (escapecommas && (coldata->str[i] == '\\' || coldata->str[i] == ',')) {
|
||||||
buf[buflen++] = '\\';
|
buf[buflen++] = '\\';
|
||||||
}
|
}
|
||||||
buf[buflen++] = coldata[i];
|
buf[buflen++] = coldata->str[i];
|
||||||
|
|
||||||
if (buflen >= len - 2)
|
if (buflen >= len - 2)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (coldata[i] == '\0')
|
if (coldata->str[i] == '\0')
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf[buflen - 1] = ',';
|
buf[buflen++] = ',';
|
||||||
buf[buflen] = '\0';
|
buf[buflen] = '\0';
|
||||||
|
ast_debug(2, "buf is now set to '%s'\n", buf);
|
||||||
}
|
}
|
||||||
/* Trim trailing comma */
|
/* Trim trailing comma */
|
||||||
buf[buflen - 1] = '\0';
|
buf[buflen - 1] = '\0';
|
||||||
|
ast_debug(2, "buf is now set to '%s'\n", buf);
|
||||||
|
|
||||||
if (resultset) {
|
if (resultset) {
|
||||||
row = ast_calloc(1, sizeof(*row) + buflen);
|
row = ast_calloc(1, sizeof(*row) + buflen);
|
||||||
@@ -497,7 +508,7 @@ static int acf_odbc_read(struct ast_channel *chan, const char *cmd, char *s, cha
|
|||||||
end_acf_read:
|
end_acf_read:
|
||||||
snprintf(rowcount, sizeof(rowcount), "%d", y);
|
snprintf(rowcount, sizeof(rowcount), "%d", y);
|
||||||
pbx_builtin_setvar_helper(chan, "ODBCROWS", rowcount);
|
pbx_builtin_setvar_helper(chan, "ODBCROWS", rowcount);
|
||||||
pbx_builtin_setvar_helper(chan, "~ODBCFIELDS~", colnames);
|
pbx_builtin_setvar_helper(chan, "~ODBCFIELDS~", colnames->str);
|
||||||
if (resultset) {
|
if (resultset) {
|
||||||
int uid;
|
int uid;
|
||||||
struct ast_datastore *odbc_store;
|
struct ast_datastore *odbc_store;
|
||||||
|
|||||||
Reference in New Issue
Block a user