[prev in list] [next in list] [prev in thread] [next in thread]
List: pecl-cvs
Subject: [PECL-CVS] cvs: pecl(OAUTH_1A_STREAMS) /oauth oauth.c php_oauth.h /oauth/tests oauth_sbs.phpt oauth
From: "Tjerk Anne Meesters" <datibbaw () php ! net>
Date: 2009-05-20 14:23:12
Message-ID: cvsdatibbaw1242829392 () cvsserver
[Download RAW message or body]
datibbaw Wed May 20 14:23:12 2009 UTC
Added files: (Branch: OAUTH_1A_STREAMS)
/pecl/oauth/tests oauth_standard.phpt
Modified files:
/pecl/oauth oauth.c php_oauth.h
/pecl/oauth/tests oauth_sbs.phpt
Log:
* added support for numeric indexes in oauth_http_build_query()
* removed filters from oauth_http_build_query() - FILTER_NONE is assumed for all
* fixed return values for setVersion() and setNonce()
* added testcases
["datibbaw-20090520142312.txt" (text/plain)]
http://cvs.php.net/viewvc.cgi/pecl/oauth/oauth.c?r1=1.58.2.8&r2=1.58.2.9&diff_format=u
Index: pecl/oauth/oauth.c
diff -u pecl/oauth/oauth.c:1.58.2.8 pecl/oauth/oauth.c:1.58.2.9
--- pecl/oauth/oauth.c:1.58.2.8 Wed May 20 13:29:16 2009
+++ pecl/oauth/oauth.c Wed May 20 14:23:11 2009
@@ -8,7 +8,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: oauth.c,v 1.58.2.8 2009/05/20 13:29:16 datibbaw Exp $ */
+/* $Id: oauth.c,v 1.58.2.9 2009/05/20 14:23:11 datibbaw Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -429,49 +429,53 @@
}
/* }}} */
-/* build url-encoded string from args, optionally starting with & and optionally \
filter oauth params or non-oauth params */
-int oauth_http_build_query(smart_str *s, HashTable *args, zend_bool prepend_amp, int \
filter) +/* build url-encoded string from args, optionally starting with & */
+int oauth_http_build_query(smart_str *s, HashTable *args, zend_bool prepend_amp)
{
void *cur_val;
char *arg_key = NULL, *param_value;
zend_hash_key_type cur_key;
uint cur_key_len;
- int numargs = 0;
- int is_oauth_param = 0;
+ int numargs = 0, hash_key_type;
ulong num_index;
HashPosition pos;
if (args) {
for (zend_hash_internal_pointer_reset_ex(args, &pos);
- HASH_KEY_NON_EXISTANT!=zend_hash_get_current_key_ex(args, &cur_key, \
&cur_key_len, &num_index, 0, &pos); \
+ HASH_KEY_NON_EXISTANT!=(hash_key_type=zend_hash_get_current_key_ex(args, \
&cur_key, &cur_key_len, &num_index, 0, &pos)); zend_hash_move_forward_ex(args, \
&pos)) {
- if (!cur_key) {
- continue;
+ switch (hash_key_type) {
+ case HASH_KEY_IS_STRING:
+ arg_key = oauth_url_encode(ZEND_HASH_KEY_STRVAL(cur_key));
+ break;
+ case HASH_KEY_IS_LONG:
+ // take value of num_index instead
+ arg_key = NULL;
+ break;
+ default:
+ // unicode keys not yet supported
+ continue;
+ }
+ if (prepend_amp) {
+ smart_str_appendc(s, '&');
+ }
+ zend_hash_get_current_data_ex(args, (void **)&cur_val, &pos);
+ param_value = oauth_url_encode(Z_STRVAL_PP((zval **)cur_val));
+
+ if (arg_key) {
+ smart_str_appends(s, arg_key);
+ efree(arg_key);
+ } else {
+ smart_str_append_unsigned(s, num_index);
}
- is_oauth_param = !strncmp(OAUTH_PARAM_PREFIX, ZEND_HASH_KEY_STRVAL(cur_key), \
OAUTH_PARAM_PREFIX_LEN);
- /* apply filter where applicable */
- if (filter==PARAMS_FILTER_NONE
- || (filter==PARAMS_FILTER_OAUTH && !is_oauth_param)
- || (filter==PARAMS_FILTER_NON_OAUTH && is_oauth_param)) {
- if (prepend_amp) {
- smart_str_appendc(s, '&');
- }
- zend_hash_get_current_data_ex(args, (void **)&cur_val, &pos);
- arg_key = oauth_url_encode(ZEND_HASH_KEY_STRVAL(cur_key));
- param_value = oauth_url_encode(Z_STRVAL_PP((zval **)cur_val));
-
- if(arg_key) {
- smart_str_appends(s, arg_key);
- efree(arg_key);
- }
- smart_str_appendc(s, '=');
- if (param_value) {
- smart_str_appends(s, param_value);
- efree(param_value);
- }
- prepend_amp = TRUE;
- ++numargs;
+ /* even if param_value is empty, we still show the equals sign */
+ smart_str_appendc(s, '=');
+ if (param_value) {
+ smart_str_appends(s, param_value);
+ efree(param_value);
}
+ prepend_amp = TRUE;
+ ++numargs;
}
}
return numargs;
@@ -534,9 +538,9 @@
smart_str_appends(&sbuf, urlparts->path);
smart_str_0(&sbuf);
- numargs += oauth_http_build_query(&squery, post_args, FALSE, PARAMS_FILTER_NONE);
+ numargs += oauth_http_build_query(&squery, post_args, FALSE);
- numargs += oauth_http_build_query(&squery, extra_args, numargs ? TRUE : FALSE, \
PARAMS_FILTER_NONE); + numargs += oauth_http_build_query(&squery, extra_args, \
numargs ? TRUE : FALSE);
if (urlparts->query) {
smart_str_appendc(&squery, '&');
@@ -575,7 +579,7 @@
prepend_amp = FALSE;
/* this one should check if values are non empty */
- oauth_http_build_query(&squery, decoded_args, FALSE, PARAMS_FILTER_NONE);
+ oauth_http_build_query(&squery, decoded_args, FALSE);
smart_str_0(&squery);
} else {
soo_handle_error(soo, OAUTH_ERR_INTERNAL_ERROR, "Was not able to get oauth \
parameters!", NULL TSRMLS_CC); @@ -1225,7 +1229,7 @@
switch (Z_TYPE_P(request_params)) {
case IS_ARRAY:
rargs = HASH_OF(request_params);
- oauth_http_build_query(&postdata, rargs, FALSE, PARAMS_FILTER_NONE);
+ oauth_http_build_query(&postdata, rargs, FALSE);
break;
case IS_STRING:
smart_str_appendl(&postdata, Z_STRVAL_P(request_params), \
Z_STRLEN_P(request_params)); @@ -1315,12 +1319,12 @@
if (!strcmp(auth_type, OAUTH_AUTH_TYPE_FORM)) {
/* append/set post data with oauth parameters */
- oauth_http_build_query(&payload, oauth_args, payload.len, PARAMS_FILTER_NONE);
+ oauth_http_build_query(&payload, oauth_args, payload.len);
smart_str_0(&payload);
} else if (!strcmp(auth_type, OAUTH_AUTH_TYPE_URI)) {
/* extend url request with oauth parameters */
if (!is_redirect) {
- oauth_http_build_query(http_prepare_url_concat(&surl), oauth_args, FALSE, \
PARAMS_FILTER_NONE); + oauth_http_build_query(http_prepare_url_concat(&surl), \
oauth_args, FALSE); }
/* TODO look into merging oauth parameters if they occur in the current url */
} else if (!strcmp(auth_type, OAUTH_AUTH_TYPE_AUTHORIZATION)) {
@@ -1851,7 +1855,7 @@
MAKE_STD_ZVAL(zver);
ZVAL_STRING(zver, vers, 1);
- if (soo_set_property(soo, zver, OAUTH_ATTR_OAUTH_VERSION TSRMLS_CC)) {
+ if (SUCCESS==soo_set_property(soo, zver, OAUTH_ATTR_OAUTH_VERSION TSRMLS_CC)) {
RETURN_TRUE;
}
@@ -1913,7 +1917,7 @@
MAKE_STD_ZVAL(zonce);
ZVAL_STRING(zonce, nonce, 1);
- if (soo_set_property(soo, zonce, OAUTH_ATTR_OAUTH_USER_NONCE TSRMLS_CC)) {
+ if (SUCCESS==soo_set_property(soo, zonce, OAUTH_ATTR_OAUTH_USER_NONCE TSRMLS_CC)) {
RETURN_TRUE;
}
@@ -2342,7 +2346,7 @@
#else
php_info_print_table_row(2, "Request engine support", "php_streams");
#endif
- php_info_print_table_row(2, "source version", "$Id: oauth.c,v 1.58.2.8 2009/05/20 \
13:29:16 datibbaw Exp $"); + php_info_print_table_row(2, "source version", "$Id: \
oauth.c,v 1.58.2.9 2009/05/20 14:23:11 datibbaw Exp $"); php_info_print_table_row(2, \
"version", OAUTH_EXT_VER); php_info_print_table_end();
}
http://cvs.php.net/viewvc.cgi/pecl/oauth/php_oauth.h?r1=1.18.2.4&r2=1.18.2.5&diff_format=u
Index: pecl/oauth/php_oauth.h
diff -u pecl/oauth/php_oauth.h:1.18.2.4 pecl/oauth/php_oauth.h:1.18.2.5
--- pecl/oauth/php_oauth.h:1.18.2.4 Mon May 18 13:42:35 2009
+++ pecl/oauth/php_oauth.h Wed May 20 14:23:12 2009
@@ -8,7 +8,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_oauth.h,v 1.18.2.4 2009/05/18 13:42:35 datibbaw Exp $ */
+/* $Id: php_oauth.h,v 1.18.2.5 2009/05/20 14:23:12 datibbaw Exp $ */
#ifndef PHP_OAUTH_H
#define PHP_OAUTH_H
@@ -62,10 +62,6 @@
#define OAUTH_HTTP_METHOD_PUT "PUT"
#define OAUTH_HTTP_METHOD_HEAD "HEAD"
-#define PARAMS_FILTER_OAUTH 1
-#define PARAMS_FILTER_NON_OAUTH 2
-#define PARAMS_FILTER_NONE 0
-
#define OAUTH_REQENGINE_STREAMS 1
#define OAUTH_REQENGINE_CURL 2
http://cvs.php.net/viewvc.cgi/pecl/oauth/tests/oauth_sbs.phpt?r1=1.1.2.1&r2=1.1.2.2&diff_format=u
Index: pecl/oauth/tests/oauth_sbs.phpt
diff -u pecl/oauth/tests/oauth_sbs.phpt:1.1.2.1 \
pecl/oauth/tests/oauth_sbs.phpt:1.1.2.2
--- pecl/oauth/tests/oauth_sbs.phpt:1.1.2.1 Tue May 19 16:14:17 2009
+++ pecl/oauth/tests/oauth_sbs.phpt Wed May 20 14:23:12 2009
@@ -3,18 +3,32 @@
--FILE--
<?php
+echo "-- only two parameters --\n";
echo oauth_get_sbs('GET', 'http://127.0.0.1:12342/'),"\n";
+echo "-- using empty array --\n";
echo oauth_get_sbs('GET', 'http://127.0.0.1:12342/', array()),"\n";
+echo "-- using string instead of array --\n";
echo oauth_get_sbs('GET', 'http://127.0.0.1:12342/',''),"\n";
+echo "-- using numeric keys masked as a string --\n";
+echo oauth_get_sbs('GET', 'http://127.0.0.1:12342/',array('1'=>'hello')),"\n";
+echo "-- using string keys --\n";
echo oauth_get_sbs('GET', 'http://127.0.0.1:12342/',array('test'=>'hello')),"\n";
+echo "-- using same var in url and params --\n";
echo oauth_get_sbs('GET', \
'http://127.0.0.1:12342/?test=hi',array('test'=>'hello')),"\n";
?>
--EXPECTF--
+-- only two parameters --
GET&http%3A%2F%2F127.0.0.1%3A12342%2F&
+-- using empty array --
GET&http%3A%2F%2F127.0.0.1%3A12342%2F&
+-- using string instead of array --
Warning: oauth_get_sbs() expects parameter 3 to be array, string given in %s
+-- using numeric keys masked as a string --
+GET&http%3A%2F%2F127.0.0.1%3A12342%2F&1%3Dhello
+-- using string keys --
GET&http%3A%2F%2F127.0.0.1%3A12342%2F&test%3Dhello
+-- using same var in url and params --
GET&http%3A%2F%2F127.0.0.1%3A12342%2F&test%3Dhi
http://cvs.php.net/viewvc.cgi/pecl/oauth/tests/oauth_standard.phpt?view=markup&rev=1.1
Index: pecl/oauth/tests/oauth_standard.phpt
+++ pecl/oauth/tests/oauth_standard.phpt
--
PECL CVS Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic