[asterisk-bugs] [Asterisk 0018037]: [patch] func_uri could use a QSFIELD function to parse x-www-form-urlencoded data

Asterisk Bug Tracker noreply at bugs.digium.com
Sat Oct 2 11:09:23 CDT 2010


A NOTE has been added to this issue. 
====================================================================== 
https://issues.asterisk.org/view.php?id=18037 
====================================================================== 
Reported By:                wdoekes
Assigned To:                
====================================================================== 
Project:                    Asterisk
Issue ID:                   18037
Category:                   Functions/func_uri
Reproducibility:            always
Severity:                   feature
Priority:                   normal
Status:                     ready for testing
Asterisk Version:           1.6.2.13 
JIRA:                       SWP-2294 
Regression:                 No 
Reviewboard Link:            
SVN Branch (only for SVN checkouts, not tarball releases): N/A 
SVN Revision (number only!):  
Request Review:              
====================================================================== 
Date Submitted:             2010-09-23 10:18 CDT
Last Modified:              2010-10-02 11:09 CDT
====================================================================== 
Summary:                    [patch] func_uri could use a QSFIELD function to
parse x-www-form-urlencoded data
Description: 
Hi,

I've added a QSFIELD function to func_uri.c to get fields from a
querystring. I thought this would be an acceptable way to read an ordered
dictionary gotten through e.g. func_curl.


[Synopsis]
Gets a single field from a application/x-www-form-urlencoded query string.


[Description]
Returns the URI-decoded content from the <index>-th field with name
<field>
from query string found in variable <varname>.

[Syntax]
QSFIELD(varname,field[,index])


Example:

exten =>
_IDX!,n,Set(qsdata=field1=pe%20%25%40%26%3dna&field1=pe+na2&field2=pena3)
exten => _IDX!,n,NoOp(qsdata is ${qsdata})
exten => _IDX!,n,NoOp(qstest ${QSFIELD(qsdata,field1,-1)})
exten => _IDX!,n,NoOp(qstest ${QSFIELD(qsdata,field2,-1)})
exten => _IDX!,n,NoOp(qstest ${QSFIELD(qsdata,field1,0)})
exten => _IDX!,n,NoOp(qstest ${QSFIELD(qsdata,field2,0)})
exten => _IDX!,n,NoOp(qstest ${QSFIELD(qsdata,field1,1)})
exten => _IDX!,n,NoOp(qstest ${QSFIELD(qsdata,field2,1)})

Set("qsdata=field1=pe%20%25%40%26%3dna&field1=pe+na2&field2=pena3")
NoOp("qsdata is field1=pe%20%25%40%26%3dna&field1=pe+na2&field2=pena3")
NoOp("qstest pe na2")
NoOp("qstest pena3")
NoOp("qstest pe %@&=na")
NoOp("qstest pena3")
NoOp("qstest pe na2")
NOTICE[4224]: func_uri.c:243 qsfield: Field field2= not found in query
string from qsdata on requested index
NoOp("qstest ")
====================================================================== 

---------------------------------------------------------------------- 
 (0127607) wdoekes (reporter) - 2010-10-02 11:09
 https://issues.asterisk.org/view.php?id=18037#c127607 
---------------------------------------------------------------------- 
It depends a bit on whether a patch from
https://issues.asterisk.org/view.php?id=18046 is included or not. Tilghman
and I disagree a bit about the usefulness of decoding (the widely used)
x-www-form-urlencoded data (where spaces are encoded as pluses).

What it/I'm trying to do is simple: I just need to get a small dictionary
of data from the customer. (In my case using a HTTP GET request, so
x-www-form-urlencoding is by far the simplest encoding scheme for the
customer and myself.)

For my purposes I would need either the hashcompat-mode of CURLOPT to be
tweaked, or this QSFIELD function.

Now, this QSFIELD function is more versatile (the dictionary source
needn't be a CURL request and it supports duplicate keys), but the
advantages over the CURLOPT method will probably not be needed by anyone.
So, tweaking the hashcompat-mode seems like the least intrusive / to be
preferred method.

But, if this stands a chance of being included while the CURLOPT patch
isn't, then I'd rather go with this one. (I really like to keep my patches
down to a minimum.)


(There is a third solution: I could get the unparsed data using CURL,
STRREPLACE the pluses with spaces (or %20) and finally run a (to be
created) function that does what CURLOPT(hashcompat)=yes does. But I'm not
sure how desirable that is.) 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2010-10-02 11:09 wdoekes        Note Added: 0127607                          
======================================================================




More information about the asterisk-bugs mailing list