[Home]

Summary:ASTERISK-11216: [patch] res_config_curl
Reporter:Tilghman Lesher (tilghman)Labels:
Date Opened:2008-01-12 00:08:44.000-0600Date Closed:2008-01-16 16:19:41.000-0600
Priority:MinorRegression?No
Status:Closed/CompleteComponents:Resources/NewFeature
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) 1.4_res_config_curl.c
( 1) 20080116__bug11747.diff.txt
( 2) patch.txt
( 3) res_config_curl.c
Description:As discussed with jmls.

****** ADDITIONAL INFORMATION ******

To use:

in extconfig.conf, in place of the database field, set the base URL from which queries are to be made.  PATH_INFO is used to determine which function (no path info means a single record lookup).

"single": single record lookup; parameters are passed via HTTP POST
"multi": multiple record query; parameters are passed via HTTP POST
"update": lookup is passed in the query string of the URL; parameters to update are passed via HTTP POST
"store": all fields are passed via HTTP POST
"destroy": all lookup fields are passed via HTTP POST
"static": filename is passed in the query string of the URL

The records passed back are expected to be line-oriented, and all variables with multiple values should be passed back separated into separate key/value pairs (e.g. "allow=ulaw&allow=gsm", not "allow=ulaw;gsm"):

"single": single line, URI-encoded
multi: multiple lines, URI-encoded
update: single line, integer, number of rows affected (-1 to indicate failure)
store: single line, integer, number of rows affected (-1 to indicate failure)
destroy: single line, integer, number of rows affected (-1 to indicate failure)
static: multiple lines, URI-encoded, one line for each row encoded, with the expected variables cat_metric, category, var_name, var_val.
Comments:By: jmls (jmls) 2008-01-12 08:25:43.000-0600

compiling this against the latest trunk:

[CC] res_config_curl.c -> res_config_curl.o
res_config_curl.c: In function âconfig_curlâ:
res_config_curl.c:404: warning: âvar_valâ may be used uninitialized in this function
res_config_curl.c:404: warning: âvar_nameâ may be used uninitialized in this function
res_config_curl.c:404: warning: âcategoryâ may be used uninitialized in this function
  [LD] res_config_curl.o -> res_config_curl.so

By: Olle Johansson (oej) 2008-01-12 08:46:18.000-0600

Cool. I've been telling people to use the #exec for similar readonly setups.

By: jmls (jmls) 2008-01-13 03:46:55.000-0600

Just trying to get my slow brain around this one.

Taking voicemail as an example, in extconfig.conf I would have


voicemail => curl,http://myserver.co.uk/vm

I would then get a set of posts containing data for voicemail set in key/value pairs ? (where does the PATH_INFO get set - is this part of the curl request - http://myserver.co.uk/vm/update?foo=bar&abc=def )

When responding to the request, for an update, I need to pass back "-1" as the data if all is not ok ?

for a "multi" request, I pass back "multi?foo-bar&abc=def" ?

thanks

By: jmls (jmls) 2008-01-13 03:52:59.000-0600

this may be asking a bit much, but is there any way of having a back-port of this to 1.4 ? I could do a lot more testing with this, as I could attach it to our standard test system with is in use _all_ the time.

By: Tilghman Lesher (tilghman) 2008-01-13 10:24:03.000-0600

Where PATH_INFO is set depends upon the language.  In Perl, it's set as an environmental variable, $ENV{'PATH_INFO'}.  In PHP, it's $_SERVER["PATH_INFO"] (PHP has an additional note of:  "Apache 2 users may use AcceptPathInfo = On inside httpd.conf to define PATH_INFO.")

For a multi-request, the response should be of the form of:
foo=one&bar=one&baz=one
foo=two&bar=two&baz=two
foo=three&bar=three&baz=three
...
where foo, bar, and baz are the field names in the corresponding records, one line each to a record.  Any embedded newlines (or other "special" characters, such as '=' and '&') should be encoded in %FF format, according to their ASCII code.

By: Tilghman Lesher (tilghman) 2008-01-13 10:24:35.000-0600

Oh, and I don't see any reason why this shouldn't work directly in 1.4.

By: jmls (jmls) 2008-01-13 10:32:44.000-0600

given my example, would PATH_INFO be http://myserver.co.uk/vm/update ?

By: jmls (jmls) 2008-01-13 10:33:26.000-0600

It does not compile under 1.4 - ast_str_create seems to be a trunk function (it is in strings.h in trunk, but not 1.4)

By: Tilghman Lesher (tilghman) 2008-01-13 12:21:40.000-0600

PATH_INFO would be "/update" or simply "update", depending on the web server.

By: jmls (jmls) 2008-01-13 14:23:41.000-0600

voicemail => http://myserver.co.uk

gives a segfault on startup

voicemail => curl,http://myserver.co.uk

gives a segfault on VoiceMail(MBox)

this is because my program is not yet returning any data. Utils.c (line 478) assumes that there is data ..



By: jmls (jmls) 2008-01-14 05:51:09.000-0600

Having played with this, I would find it easier if:

PATH_INFO was "realtime"

post variables of

TableName: voicemail / queue / queuemember etc
Mode: query/multi/update/store/destroy/Static

or

PATH_INFO realtime_voicemail/realtime_queue etc

post variables of
Mode: query/multi/update/store/destroy/Static

By: jmls (jmls) 2008-01-14 06:22:47.000-0600

patch.txt contains fixes for the pbx_substitute_variables_helper function: sizeof(buffer) is always 4, so I replaced it with the size of the malloc

By: jmls (jmls) 2008-01-16 06:47:53.000-0600

it's now broken ;)

when trying to access a voicemail box, the url is now reported as invalid.