mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-10-27 21:54:16 +00:00
spring cleaning
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4795 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
1 parent
a021945cef
commit
3a54126261
143 files changed
+22413
-31567
No files matched your search
@@ -46,30 +46,30 @@
|
||||
static const char modname[] = "ODBC";
|
||||
|
||||
struct odbc_obj {
|
||||
char *dsn;
|
||||
char *username;
|
||||
char *password;
|
||||
SQLHENV env;
|
||||
SQLHDBC con;
|
||||
SQLHSTMT stmt;
|
||||
uint32_t state;
|
||||
SQLCHAR *colbuf;
|
||||
int32 cblen;
|
||||
SQLCHAR *code;
|
||||
int32 codelen;
|
||||
char *dsn;
|
||||
char *username;
|
||||
char *password;
|
||||
SQLHENV env;
|
||||
SQLHDBC con;
|
||||
SQLHSTMT stmt;
|
||||
uint32_t state;
|
||||
SQLCHAR *colbuf;
|
||||
int32 cblen;
|
||||
SQLCHAR *code;
|
||||
int32 codelen;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
ODBC_STATE_INIT,
|
||||
ODBC_STATE_DOWN,
|
||||
ODBC_STATE_CONNECTED,
|
||||
ODBC_STATE_ERROR
|
||||
ODBC_STATE_INIT,
|
||||
ODBC_STATE_DOWN,
|
||||
ODBC_STATE_CONNECTED,
|
||||
ODBC_STATE_ERROR
|
||||
} odbc_state_t;
|
||||
typedef struct odbc_obj odbc_obj_t;
|
||||
|
||||
typedef enum {
|
||||
ODBC_SUCCESS = 0,
|
||||
ODBC_FAIL = -1
|
||||
ODBC_SUCCESS = 0,
|
||||
ODBC_FAIL = -1
|
||||
} odbc_status_t;
|
||||
|
||||
|
||||
@@ -77,59 +77,59 @@ static odbc_obj_t *new_odbc_obj(char *dsn, char *username, char *password)
|
||||
{
|
||||
odbc_obj_t *new_obj;
|
||||
|
||||
if (!(new_obj = malloc(sizeof(*new_obj)))) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!(new_obj->dsn = strdup(dsn))) {
|
||||
goto err;
|
||||
}
|
||||
if (!(new_obj = malloc(sizeof(*new_obj)))) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!(new_obj->username = strdup(username))) {
|
||||
goto err;
|
||||
}
|
||||
if (!(new_obj->dsn = strdup(dsn))) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!(new_obj->password = strdup(password))) {
|
||||
goto err;
|
||||
}
|
||||
if (!(new_obj->username = strdup(username))) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!(new_obj->password = strdup(password))) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
new_obj->env = SQL_NULL_HANDLE;
|
||||
new_obj->state = ODBC_STATE_INIT;
|
||||
|
||||
|
||||
return new_obj;
|
||||
|
||||
err:
|
||||
err:
|
||||
if (new_obj) {
|
||||
switch_safe_free(new_obj->dsn);
|
||||
switch_safe_free(new_obj->username);
|
||||
switch_safe_free(new_obj->password);
|
||||
switch_safe_free(new_obj);
|
||||
switch_safe_free(new_obj);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
odbc_status_t odbc_obj_disconnect(odbc_obj_t *obj)
|
||||
odbc_status_t odbc_obj_disconnect(odbc_obj_t * obj)
|
||||
{
|
||||
int result;
|
||||
|
||||
if (obj->state == ODBC_STATE_CONNECTED) {
|
||||
result = SQLDisconnect(obj->con);
|
||||
if (result == ODBC_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Disconnected %d from [%s]\n", result, obj->dsn);
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Disconnectiong [%s]\n", obj->dsn);
|
||||
}
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "[%s] already disconnected\n", obj->dsn);
|
||||
}
|
||||
|
||||
if (obj->state == ODBC_STATE_CONNECTED) {
|
||||
result = SQLDisconnect(obj->con);
|
||||
if (result == ODBC_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Disconnected %d from [%s]\n", result, obj->dsn);
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Disconnectiong [%s]\n", obj->dsn);
|
||||
}
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "[%s] already disconnected\n", obj->dsn);
|
||||
}
|
||||
|
||||
obj->state = ODBC_STATE_DOWN;
|
||||
|
||||
return ODBC_SUCCESS;
|
||||
}
|
||||
|
||||
odbc_status_t odbc_obj_connect(odbc_obj_t *obj)
|
||||
odbc_status_t odbc_obj_connect(odbc_obj_t * obj)
|
||||
{
|
||||
int result;
|
||||
SQLINTEGER err;
|
||||
@@ -140,14 +140,14 @@ odbc_status_t odbc_obj_connect(odbc_obj_t *obj)
|
||||
result = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &obj->env);
|
||||
|
||||
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error AllocHandle\n");
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error AllocHandle\n");
|
||||
return ODBC_FAIL;
|
||||
}
|
||||
|
||||
result = SQLSetEnvAttr(obj->env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
|
||||
|
||||
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error SetEnv\n");
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error SetEnv\n");
|
||||
SQLFreeHandle(SQL_HANDLE_ENV, obj->env);
|
||||
return ODBC_FAIL;
|
||||
}
|
||||
@@ -155,7 +155,7 @@ odbc_status_t odbc_obj_connect(odbc_obj_t *obj)
|
||||
result = SQLAllocHandle(SQL_HANDLE_DBC, obj->env, &obj->con);
|
||||
|
||||
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error AllocHDB %d\n", result);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error AllocHDB %d\n", result);
|
||||
SQLFreeHandle(SQL_HANDLE_ENV, obj->env);
|
||||
return ODBC_FAIL;
|
||||
}
|
||||
@@ -169,14 +169,14 @@ odbc_status_t odbc_obj_connect(odbc_obj_t *obj)
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connecting %s\n", obj->dsn);
|
||||
|
||||
result = SQLConnect(obj->con,
|
||||
(SQLCHAR *) obj->dsn, SQL_NTS,
|
||||
(SQLCHAR *) obj->username, SQL_NTS,
|
||||
(SQLCHAR *) obj->password, SQL_NTS);
|
||||
|
||||
(SQLCHAR *) obj->dsn, SQL_NTS,
|
||||
(SQLCHAR *) obj->username, SQL_NTS, (SQLCHAR *) obj->password, SQL_NTS);
|
||||
|
||||
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
|
||||
SQLGetDiagRec(SQL_HANDLE_DBC, obj->con, 1, stat, &err, msg, 100, &mlen);
|
||||
SQLFreeHandle(SQL_HANDLE_ENV, obj->env);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error SQLConnect=%d errno=%d %s\n", result, (int)err, msg);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error SQLConnect=%d errno=%d %s\n", result, (int) err,
|
||||
msg);
|
||||
return ODBC_FAIL;
|
||||
} else {
|
||||
|
||||
@@ -187,9 +187,9 @@ odbc_status_t odbc_obj_connect(odbc_obj_t *obj)
|
||||
return ODBC_SUCCESS;
|
||||
}
|
||||
|
||||
static void destroy_odbc_obj(odbc_obj_t **objp)
|
||||
static void destroy_odbc_obj(odbc_obj_t ** objp)
|
||||
{
|
||||
odbc_obj_t *obj = *objp;
|
||||
odbc_obj_t *obj = *objp;
|
||||
|
||||
odbc_obj_disconnect(obj);
|
||||
|
||||
@@ -198,282 +198,284 @@ static void destroy_odbc_obj(odbc_obj_t **objp)
|
||||
SQLFreeHandle(SQL_HANDLE_ENV, obj->env);
|
||||
|
||||
switch_safe_free(obj->dsn);
|
||||
switch_safe_free(obj->username);
|
||||
switch_safe_free(obj->password);
|
||||
switch_safe_free(obj->username);
|
||||
switch_safe_free(obj->password);
|
||||
switch_safe_free(obj->colbuf);
|
||||
switch_safe_free(obj->code);
|
||||
switch_safe_free(obj);
|
||||
switch_safe_free(obj);
|
||||
}
|
||||
|
||||
|
||||
/* ODBC Object */
|
||||
/*********************************************************************************/
|
||||
static JSBool odbc_construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
static JSBool odbc_construct(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
|
||||
{
|
||||
odbc_obj_t *odbc_obj = NULL;
|
||||
char *dsn, *username, *password;
|
||||
int32 blen = 1024;
|
||||
odbc_obj_t *odbc_obj = NULL;
|
||||
char *dsn, *username, *password;
|
||||
int32 blen = 1024;
|
||||
|
||||
if (argc < 3) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
if (argc < 3) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
dsn = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
|
||||
username = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
|
||||
password = JS_GetStringBytes(JS_ValueToString(cx, argv[2]));
|
||||
dsn = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
|
||||
username = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
|
||||
password = JS_GetStringBytes(JS_ValueToString(cx, argv[2]));
|
||||
|
||||
if (argc > 3) {
|
||||
int32 len;
|
||||
JS_ValueToInt32(cx, argv[3], &len);
|
||||
if (argc > 3) {
|
||||
int32 len;
|
||||
JS_ValueToInt32(cx, argv[3], &len);
|
||||
|
||||
if (len > 0) {
|
||||
blen = len;
|
||||
}
|
||||
}
|
||||
|
||||
if (dsn && username && password) {
|
||||
odbc_obj = new_odbc_obj(dsn, username, password);
|
||||
}
|
||||
if (len > 0) {
|
||||
blen = len;
|
||||
}
|
||||
}
|
||||
|
||||
if (!odbc_obj) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
if (dsn && username && password) {
|
||||
odbc_obj = new_odbc_obj(dsn, username, password);
|
||||
}
|
||||
|
||||
if (!(odbc_obj->colbuf = (SQLCHAR *) malloc(blen))) {
|
||||
destroy_odbc_obj(&odbc_obj);
|
||||
return JS_FALSE;
|
||||
}
|
||||
if (!odbc_obj) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
odbc_obj->cblen = blen;
|
||||
if (!(odbc_obj->colbuf = (SQLCHAR *) malloc(blen))) {
|
||||
destroy_odbc_obj(&odbc_obj);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
blen += 1536;
|
||||
odbc_obj->cblen = blen;
|
||||
|
||||
if (!(odbc_obj->code = (SQLCHAR *) malloc(blen))) {
|
||||
destroy_odbc_obj(&odbc_obj);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
odbc_obj->codelen = blen;
|
||||
blen += 1536;
|
||||
|
||||
if (!(odbc_obj->code = (SQLCHAR *) malloc(blen))) {
|
||||
destroy_odbc_obj(&odbc_obj);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
odbc_obj->codelen = blen;
|
||||
|
||||
JS_SetPrivate(cx, obj, odbc_obj);
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static void odbc_destroy(JSContext *cx, JSObject *obj)
|
||||
static void odbc_destroy(JSContext * cx, JSObject * obj)
|
||||
{
|
||||
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
|
||||
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
|
||||
|
||||
if (odbc_obj) {
|
||||
destroy_odbc_obj(&odbc_obj);
|
||||
}
|
||||
if (odbc_obj) {
|
||||
destroy_odbc_obj(&odbc_obj);
|
||||
}
|
||||
}
|
||||
|
||||
static JSBool odbc_connect(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
static JSBool odbc_connect(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
|
||||
{
|
||||
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
|
||||
JSBool tf = JS_TRUE;
|
||||
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
|
||||
JSBool tf = JS_TRUE;
|
||||
|
||||
if (odbc_obj) {
|
||||
if (odbc_obj_connect(odbc_obj) == ODBC_SUCCESS) {
|
||||
tf = JS_TRUE;
|
||||
} else {
|
||||
tf = JS_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
*rval = BOOLEAN_TO_JSVAL( tf );
|
||||
if (odbc_obj) {
|
||||
if (odbc_obj_connect(odbc_obj) == ODBC_SUCCESS) {
|
||||
tf = JS_TRUE;
|
||||
} else {
|
||||
tf = JS_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
*rval = BOOLEAN_TO_JSVAL(tf);
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static JSBool odbc_exec(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
static JSBool odbc_exec(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
|
||||
{
|
||||
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
|
||||
char *sql;
|
||||
JSBool tf = JS_FALSE;
|
||||
int result;
|
||||
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
|
||||
char *sql;
|
||||
JSBool tf = JS_FALSE;
|
||||
int result;
|
||||
|
||||
if (argc < 1) {
|
||||
goto done;
|
||||
}
|
||||
if (argc < 1) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (odbc_obj->state != ODBC_STATE_CONNECTED) {
|
||||
goto done;
|
||||
}
|
||||
if (odbc_obj->state != ODBC_STATE_CONNECTED) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (odbc_obj->stmt) {
|
||||
SQLFreeHandle (SQL_HANDLE_STMT, odbc_obj->stmt);
|
||||
odbc_obj->stmt = NULL;
|
||||
}
|
||||
|
||||
sql = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
|
||||
if (odbc_obj->stmt) {
|
||||
SQLFreeHandle(SQL_HANDLE_STMT, odbc_obj->stmt);
|
||||
odbc_obj->stmt = NULL;
|
||||
}
|
||||
|
||||
if (SQLAllocHandle(SQL_HANDLE_STMT, odbc_obj->con, &odbc_obj->stmt) != SQL_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
sql = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
|
||||
|
||||
if (SQLPrepare(odbc_obj->stmt, (unsigned char *)sql, SQL_NTS) != SQL_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
if (SQLAllocHandle(SQL_HANDLE_STMT, odbc_obj->con, &odbc_obj->stmt) != SQL_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
result = SQLExecute(odbc_obj->stmt);
|
||||
if (SQLPrepare(odbc_obj->stmt, (unsigned char *) sql, SQL_NTS) != SQL_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (result != SQL_SUCCESS && result != SQL_SUCCESS_WITH_INFO) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
tf = JS_TRUE;
|
||||
|
||||
done:
|
||||
result = SQLExecute(odbc_obj->stmt);
|
||||
|
||||
*rval = BOOLEAN_TO_JSVAL( tf );
|
||||
if (result != SQL_SUCCESS && result != SQL_SUCCESS_WITH_INFO) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
return JS_TRUE;
|
||||
tf = JS_TRUE;
|
||||
|
||||
done:
|
||||
|
||||
*rval = BOOLEAN_TO_JSVAL(tf);
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static JSBool odbc_num_rows(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
static JSBool odbc_num_rows(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
|
||||
{
|
||||
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
|
||||
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
|
||||
|
||||
SQLSMALLINT rows = 0;
|
||||
SQLSMALLINT rows = 0;
|
||||
|
||||
if (odbc_obj->state != ODBC_STATE_CONNECTED) {
|
||||
goto done;
|
||||
}
|
||||
if (odbc_obj->state != ODBC_STATE_CONNECTED) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (odbc_obj->stmt) {
|
||||
SQLNumResultCols(odbc_obj->stmt, &rows);
|
||||
}
|
||||
if (odbc_obj->stmt) {
|
||||
SQLNumResultCols(odbc_obj->stmt, &rows);
|
||||
}
|
||||
|
||||
done:
|
||||
done:
|
||||
|
||||
*rval = INT_TO_JSVAL( rows );
|
||||
*rval = INT_TO_JSVAL(rows);
|
||||
|
||||
return JS_TRUE;
|
||||
return JS_TRUE;
|
||||
|
||||
}
|
||||
|
||||
|
||||
static JSBool odbc_next_row(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
static JSBool odbc_next_row(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
|
||||
{
|
||||
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
|
||||
int result = 0;
|
||||
JSBool tf = JS_FALSE;
|
||||
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
|
||||
int result = 0;
|
||||
JSBool tf = JS_FALSE;
|
||||
|
||||
if (odbc_obj->state != ODBC_STATE_CONNECTED) {
|
||||
goto done;
|
||||
}
|
||||
if (odbc_obj->state != ODBC_STATE_CONNECTED) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (odbc_obj->stmt) {
|
||||
if ((result = SQLFetch(odbc_obj->stmt) == SQL_SUCCESS)) {
|
||||
tf = JS_TRUE;
|
||||
}
|
||||
}
|
||||
if (odbc_obj->stmt) {
|
||||
if ((result = SQLFetch(odbc_obj->stmt) == SQL_SUCCESS)) {
|
||||
tf = JS_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
done:
|
||||
|
||||
*rval = BOOLEAN_TO_JSVAL( tf );
|
||||
*rval = BOOLEAN_TO_JSVAL(tf);
|
||||
|
||||
return JS_TRUE;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static char *escape_data(char *in)
|
||||
{
|
||||
switch_size_t nlen = strlen(in);
|
||||
uint32_t qc = 0;
|
||||
char *p, *q, *r;
|
||||
switch_size_t nlen = strlen(in);
|
||||
uint32_t qc = 0;
|
||||
char *p, *q, *r;
|
||||
|
||||
for(p = in; p && *p; p++) {
|
||||
if (*p == '"') {
|
||||
qc += 2;
|
||||
}
|
||||
}
|
||||
|
||||
nlen += qc + 1;
|
||||
for (p = in; p && *p; p++) {
|
||||
if (*p == '"') {
|
||||
qc += 2;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(q = (char *) malloc(nlen))) {
|
||||
return NULL;
|
||||
}
|
||||
nlen += qc + 1;
|
||||
|
||||
r = q;
|
||||
qc = 0;
|
||||
for(p = in; p && *p; p++) {
|
||||
if (*p == '"') {
|
||||
*r++ = '\\';
|
||||
}
|
||||
*r++ = *p;
|
||||
if (++qc > nlen) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
*r++ = '\0';
|
||||
if (!(q = (char *) malloc(nlen))) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
r = q;
|
||||
qc = 0;
|
||||
for (p = in; p && *p; p++) {
|
||||
if (*p == '"') {
|
||||
*r++ = '\\';
|
||||
}
|
||||
*r++ = *p;
|
||||
if (++qc > nlen) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
*r++ = '\0';
|
||||
|
||||
return q;
|
||||
|
||||
return q;
|
||||
|
||||
}
|
||||
|
||||
|
||||
static JSBool odbc_get_data(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
static JSBool odbc_get_data(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
|
||||
{
|
||||
|
||||
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
|
||||
JSBool tf = JS_FALSE;
|
||||
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
|
||||
JSBool tf = JS_FALSE;
|
||||
|
||||
if (odbc_obj->state != ODBC_STATE_CONNECTED) {
|
||||
goto done;
|
||||
}
|
||||
if (odbc_obj->state != ODBC_STATE_CONNECTED) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (odbc_obj->stmt) {
|
||||
SQLSMALLINT c = 0, x = 0;
|
||||
int result;
|
||||
char code[66560];
|
||||
if (odbc_obj->stmt) {
|
||||
SQLSMALLINT c = 0, x = 0;
|
||||
int result;
|
||||
char code[66560];
|
||||
|
||||
snprintf(code, sizeof(code), "~var _oDbC_dB_RoW_DaTa_ = {}");
|
||||
eval_some_js(code, cx, obj, rval);
|
||||
if (*rval == JS_FALSE) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
snprintf(code, sizeof(code), "~var _oDbC_dB_RoW_DaTa_ = {}");
|
||||
eval_some_js(code, cx, obj, rval);
|
||||
if (*rval == JS_FALSE) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
result = SQLNumResultCols(odbc_obj->stmt, &c);
|
||||
if (result == SQL_SUCCESS || result == SQL_SUCCESS_WITH_INFO) {
|
||||
for (x = 1; x <= c; x++) {
|
||||
SQLSMALLINT NameLength, DataType, DecimalDigits, Nullable;
|
||||
SQLUINTEGER ColumnSize;
|
||||
SQLCHAR name[1024] = "";
|
||||
SQLCHAR *data = odbc_obj->colbuf;
|
||||
SQLCHAR *esc = NULL;
|
||||
result = SQLNumResultCols(odbc_obj->stmt, &c);
|
||||
if (result == SQL_SUCCESS || result == SQL_SUCCESS_WITH_INFO) {
|
||||
for (x = 1; x <= c; x++) {
|
||||
SQLSMALLINT NameLength, DataType, DecimalDigits, Nullable;
|
||||
SQLUINTEGER ColumnSize;
|
||||
SQLCHAR name[1024] = "";
|
||||
SQLCHAR *data = odbc_obj->colbuf;
|
||||
SQLCHAR *esc = NULL;
|
||||
|
||||
SQLDescribeCol(odbc_obj->stmt, x, name, sizeof(name), &NameLength, &DataType, &ColumnSize, &DecimalDigits, &Nullable);
|
||||
SQLGetData(odbc_obj->stmt, x, SQL_C_CHAR, odbc_obj->colbuf, odbc_obj->cblen, NULL);
|
||||
|
||||
if (strchr((char *)odbc_obj->colbuf, '"')) { /* please don't */
|
||||
esc = (SQLCHAR *) escape_data((char *)odbc_obj->colbuf);
|
||||
data = esc;
|
||||
}
|
||||
SQLDescribeCol(odbc_obj->stmt, x, name, sizeof(name), &NameLength, &DataType, &ColumnSize,
|
||||
&DecimalDigits, &Nullable);
|
||||
SQLGetData(odbc_obj->stmt, x, SQL_C_CHAR, odbc_obj->colbuf, odbc_obj->cblen, NULL);
|
||||
|
||||
snprintf((char *)odbc_obj->code, odbc_obj->codelen, "~_oDbC_dB_RoW_DaTa_[\"%s\"] = \"%s\"", name, data);
|
||||
switch_safe_free(esc);
|
||||
if (strchr((char *) odbc_obj->colbuf, '"')) { /* please don't */
|
||||
esc = (SQLCHAR *) escape_data((char *) odbc_obj->colbuf);
|
||||
data = esc;
|
||||
}
|
||||
|
||||
eval_some_js((char *)odbc_obj->code, cx, obj, rval);
|
||||
snprintf((char *) odbc_obj->code, odbc_obj->codelen, "~_oDbC_dB_RoW_DaTa_[\"%s\"] = \"%s\"", name,
|
||||
data);
|
||||
switch_safe_free(esc);
|
||||
|
||||
if (*rval == JS_FALSE) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
}
|
||||
eval_some_js((char *) odbc_obj->code, cx, obj, rval);
|
||||
|
||||
JS_GetProperty(cx, obj, "_oDbC_dB_RoW_DaTa_", rval);
|
||||
return JS_TRUE;
|
||||
}
|
||||
if (*rval == JS_FALSE) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
JS_GetProperty(cx, obj, "_oDbC_dB_RoW_DaTa_", rval);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
done:
|
||||
}
|
||||
|
||||
*rval = BOOLEAN_TO_JSVAL( tf );
|
||||
done:
|
||||
|
||||
return JS_TRUE;
|
||||
*rval = BOOLEAN_TO_JSVAL(tf);
|
||||
|
||||
return JS_TRUE;
|
||||
|
||||
}
|
||||
|
||||
@@ -492,50 +494,40 @@ static JSFunctionSpec odbc_methods[] = {
|
||||
|
||||
|
||||
static JSPropertySpec odbc_props[] = {
|
||||
// {"name", odbc_NAME, JSPROP_READONLY|JSPROP_PERMANENT},
|
||||
// {"name", odbc_NAME, JSPROP_READONLY|JSPROP_PERMANENT},
|
||||
{0}
|
||||
};
|
||||
|
||||
|
||||
static JSBool odbc_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
static JSBool odbc_getProperty(JSContext * cx, JSObject * obj, jsval id, jsval * vp)
|
||||
{
|
||||
JSBool res = JS_TRUE;
|
||||
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
JSClass odbc_class = {
|
||||
modname, JSCLASS_HAS_PRIVATE,
|
||||
JS_PropertyStub, JS_PropertyStub, odbc_getProperty, JS_PropertyStub,
|
||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, odbc_destroy, NULL, NULL, NULL,
|
||||
modname, JSCLASS_HAS_PRIVATE,
|
||||
JS_PropertyStub, JS_PropertyStub, odbc_getProperty, JS_PropertyStub,
|
||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, odbc_destroy, NULL, NULL, NULL,
|
||||
odbc_construct
|
||||
};
|
||||
|
||||
|
||||
switch_status_t odbc_load(JSContext *cx, JSObject *obj)
|
||||
switch_status_t odbc_load(JSContext * cx, JSObject * obj)
|
||||
{
|
||||
JS_InitClass(cx,
|
||||
obj,
|
||||
NULL,
|
||||
&odbc_class,
|
||||
odbc_construct,
|
||||
3,
|
||||
odbc_props,
|
||||
odbc_methods,
|
||||
odbc_props,
|
||||
odbc_methods
|
||||
);
|
||||
JS_InitClass(cx, obj, NULL, &odbc_class, odbc_construct, 3, odbc_props, odbc_methods, odbc_props, odbc_methods);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
const sm_module_interface_t odbc_module_interface = {
|
||||
/*.name = */ modname,
|
||||
/*.spidermonkey_load*/ odbc_load,
|
||||
/*.next*/ NULL
|
||||
/*.spidermonkey_load */ odbc_load,
|
||||
/*.next */ NULL
|
||||
};
|
||||
|
||||
SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t **module_interface)
|
||||
SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t ** module_interface)
|
||||
{
|
||||
*module_interface = &odbc_module_interface;
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
|
||||
Reference in new issue
Block a user