开发者

How should I go about DB Conn persisting in Apache when mod_dbd doesnt support my driver?

I am working with the ODBTP interface to SQL Server from a Linux Apache 2.x host. mod_dbm does not support this and I require being able to move the code to any host that supports Apache.

A note on my environment: I am using the Apache 2.2.17, C++ wrapped in C for Apache, ODBTP 1.14, SQL Server 2008.

I have successfully implemente开发者_如何学God the ODBTP connections and I am able to fully use the data within the module itself, but i wanted to persist the connections rather continuously connecting, disconnecting, and starting over again for my application that uses local HTTP calls to the retrieve data in a JSON format.

The issue is that I need to deploy this application and module in an environment where I do not trust the security of the plain text written application, to safely guard by the database credentials. When the application connects over HTTP, it provides only encrypted credentials that my module decrypts before sending to the database.

I am currently creating a handle for the database and storing it in a keyed apr_hash_t table in the module definition. Once the application connects, the module looks up the unique per request token that the application specifies in the URL to find the connection for that application. This works but only one time.

The hash key is 32 digit key that is initially a char * created out of the pool, and stored with the ODBTP handle as a row in the hash table. Some how, the key in between calls is being modified and the original key is now a truncated version.

Example: 1) I make 1 call from my application to start a persisted connection. This works. 2) I make 3 back to back calls from my application to execute a sql string. (/stars/execute_sql/unique/<>/sql/<>) x 3

The first call is perfect and I retrieve the data. The next call the token saved as the key is truncated and the module can't find the associated key. The next call the token is in the same truncated state as in attempt 2.

I am not sure if I am overwriting memory or not? I wrote a short loop function to spit out the contents of the hash table so that i could stick the function at every point in my code to find out where the data may have been corrupted, but my findings make no sense. I have to split the uri in order to find data embedded in the uri. I tracked the memory shifting to a line in this function as "raw = apr_psprintf(apache->pool,"%s", subject);" which is in the code below.

void theRequest::get_exploded_str(char *subject, char *delimiter)
{
    // variables
    char *raw, *next, *last;
    // create the split chars database if not created
    loadSDB();
    apr_array_clear(x_split_chars);
    subject = apr_pstrndup(apache->pool, subject, string(subject).length());
    raw = apr_psprintf(apache->pool,"%s", subject);

    next = (char*)apr_strtok(raw, delimiter, &last);

    while (next)
    {
        // add next to array
        *(char **) apr_array_push(x_split_chars) = apr_pstrdup(apache->pool, next);
        // fetch next
        next = (char*)apr_strtok(NULL, delimiter, &last);
    }

    return;
};

It works perfectly on call 1, but not on call 2, because the key is being shifted somehow.

Any ideas? Or even some thoughts on how I could use APR_RESLIST to accomplish this better?

Thanks in Advance!


I found that I was unable to directly pool via the application but through the ODBTP library itself. Being that it is a TCP to ODBC bridge it was able to pool the connections to a degree, but not efficiently enough.

I have abandoned this mission though and have move to using SQLite3 for the application database because of a server environment change.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜