Skip to content

Commit e94e7c8

Browse files
authored
Merge branch 'master' into 2.0.4
2 parents f3b84a4 + 770a18a commit e94e7c8

File tree

7 files changed

+57
-41
lines changed

7 files changed

+57
-41
lines changed

config.m4

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
dnl
2-
dnl $Id$
3-
dnl
4-
51
PHP_ARG_ENABLE(oauth, for oauth support,
62
[ --enable-oauth Include oauth support])
73

@@ -21,7 +17,7 @@ if test "$PHP_OAUTH" != "no"; then
2117
AC_MSG_CHECKING(for cURL in default path)
2218
have_curl=no
2319
for i in /usr/local /usr; do
24-
if test -r $i/include/curl/easy.h; then
20+
if test -r $i/include/curl/easy.h -o -r $i/include/x86_64-linux-gnu/curl/easy.h; then
2521
have_curl=yes
2622
CURL_DIR=$i
2723
AC_MSG_RESULT(found in $i)

config.w32

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// $Id$
21
// vim:ft=javascript
32

43
ARG_WITH("oauth", "oAuth support", "no");

oauth.c

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
+----------------------------------------------------------------------+
1010
*/
1111

12-
/* $Id$ */
13-
1412
#include "php_oauth.h"
1513
#include "provider.h"
1614

@@ -196,7 +194,6 @@ void soo_handle_error(php_so_object *soo, long errorCode, char *msg, char *respo
196194
}
197195
/* }}} */
198196

199-
200197
zend_string *soo_sign_hmac(php_so_object *soo, char *message, const char *cs, const char *ts, const oauth_sig_context *ctx) /* {{{ */
201198
{
202199
zval args[4], retval, func;
@@ -234,7 +231,7 @@ zend_string *soo_sign_hmac(php_so_object *soo, char *message, const char *cs, co
234231
}
235232
/* }}} */
236233

237-
zend_string *soo_sign_rsa(php_so_object *soo, char *message, const oauth_sig_context *ctx)
234+
zend_string *soo_sign_rsa(php_so_object *soo, char *message, const oauth_sig_context *ctx) /* {{{ */
238235
{
239236
zval args[3], func, retval;
240237
zend_string *result;
@@ -249,6 +246,7 @@ zend_string *soo_sign_rsa(php_so_object *soo, char *message, const oauth_sig_con
249246
/* TODO: add support for other algorithms instead of OPENSSL_ALGO_SHA1 */
250247

251248
ZVAL_STRING(&args[0], message);
249+
ZVAL_NULL(&args[1]);
252250
ZVAL_DUP(&args[2], &ctx->privatekey);
253251

254252
call_user_function_ex(EG(function_table), NULL, &func, &retval, 3, args, 0, NULL);
@@ -274,7 +272,7 @@ zend_string *soo_sign_plain(php_so_object *soo, const char *cs, const char *ts)
274272
}
275273
/* }}} */
276274

277-
oauth_sig_context *oauth_create_sig_context(const char *sigmethod)
275+
oauth_sig_context *oauth_create_sig_context(const char *sigmethod) /* {{{ */
278276
{
279277
oauth_sig_context *ctx;
280278

@@ -291,8 +289,9 @@ oauth_sig_context *oauth_create_sig_context(const char *sigmethod)
291289

292290
return ctx;
293291
}
292+
/* }}} */
294293

295-
zend_string *soo_sign(php_so_object *soo, char *message, zval *cs, zval *ts, const oauth_sig_context *ctx)
294+
zend_string *soo_sign(php_so_object *soo, char *message, zval *cs, zval *ts, const oauth_sig_context *ctx) /* {{{ */
296295
{
297296
const char *csec = cs?Z_STRVAL_P(cs):"", *tsec = ts?Z_STRVAL_P(ts):"";
298297

@@ -305,6 +304,7 @@ zend_string *soo_sign(php_so_object *soo, char *message, zval *cs, zval *ts, con
305304
}
306305
return NULL;
307306
}
307+
/* }}} */
308308

309309
static inline zval *soo_get_property(php_so_object *soo, char *prop_name) /* {{{ */
310310
{
@@ -340,7 +340,7 @@ zend_string *oauth_url_encode(char *url, int url_len) /* {{{ */
340340
}
341341
/* }}} */
342342

343-
zend_string *oauth_http_encode_value(zval *v)
343+
zend_string *oauth_http_encode_value(zval *v) /* {{{ */
344344
{
345345
zend_string *param_value = NULL;
346346

@@ -356,8 +356,9 @@ zend_string *oauth_http_encode_value(zval *v)
356356

357357
return param_value;
358358
}
359+
/* }}} */
359360

360-
static int oauth_strcmp(zval *first, zval *second)
361+
static int oauth_strcmp(zval *first, zval *second) /* {{{ */
361362
{
362363
int result;
363364
result = string_compare_function(first, second);
@@ -370,17 +371,19 @@ static int oauth_strcmp(zval *first, zval *second)
370371

371372
return 0;
372373
}
374+
/* }}} */
373375

374-
static int oauth_compare_value(const void *a, const void *b)
376+
static int oauth_compare_value(const void *a, const void *b) /* {{{ */
375377
{
376378
Bucket *f, *s;
377379
f = (Bucket *)a;
378380
s = (Bucket *)b;
379381

380382
return oauth_strcmp(&f->val, &s->val);
381383
}
384+
/* }}} */
382385

383-
static int oauth_compare_key(const void *a, const void *b)
386+
static int oauth_compare_key(const void *a, const void *b) /* {{{ */
384387
{
385388
zval first, second;
386389
int result;
@@ -405,9 +408,10 @@ static int oauth_compare_key(const void *a, const void *b)
405408
zval_ptr_dtor(&second);
406409
return result;
407410
}
411+
/* }}} */
408412

409413
/* build url-encoded string from args, optionally starting with & */
410-
int oauth_http_build_query(php_so_object *soo, smart_string *s, HashTable *args, zend_bool prepend_amp)
414+
int oauth_http_build_query(php_so_object *soo, smart_string *s, HashTable *args, zend_bool prepend_amp) /* {{{ */
411415
{
412416
zval *cur_val;
413417
zend_string *cur_key, *arg_key, *param_value;
@@ -537,9 +541,10 @@ int oauth_http_build_query(php_so_object *soo, smart_string *s, HashTable *args,
537541
}
538542
return numargs;
539543
}
544+
/* }}} */
540545

541546
/* retrieves parameter value from the _GET or _POST superglobal */
542-
void get_request_param(char *arg_name, char **return_val, int *return_len)
547+
void get_request_param(char *arg_name, char **return_val, int *return_len) /* {{{ */
543548
{
544549
zval *ptr;
545550
if (
@@ -553,12 +558,12 @@ void get_request_param(char *arg_name, char **return_val, int *return_len)
553558
*return_val = NULL;
554559
*return_len = 0;
555560
}
561+
/* }}} */
556562

557563
/*
558564
* This function does not currently care to respect parameter precedence, in the sense that if a common param is defined
559565
* in POST/GET or Authorization header, the precendence is defined by: OAuth Core 1.0 section 9.1.1
560566
*/
561-
562567
zend_string *oauth_generate_sig_base(php_so_object *soo, const char *http_method, const char *uri, HashTable *post_args, HashTable *extra_args) /* {{{ */
563568
{
564569
zval params;
@@ -665,7 +670,8 @@ zend_string *oauth_generate_sig_base(php_so_object *soo, const char *http_method
665670
}
666671
/* }}} */
667672

668-
static void oauth_set_debug_info(php_so_object *soo) {
673+
static void oauth_set_debug_info(php_so_object *soo) /* {{{ */
674+
{
669675
zval *debugInfo;
670676
if (soo->debug_info) {
671677
debugInfo = &soo->debugArr;
@@ -690,6 +696,7 @@ static void oauth_set_debug_info(php_so_object *soo) {
690696
ZVAL_UNDEF(&soo->debugArr);
691697
}
692698
}
699+
/* }}} */
693700

694701
static int add_arg_for_req(HashTable *ht, const char *arg, const char *val) /* {{{ */
695702
{
@@ -702,7 +709,7 @@ static int add_arg_for_req(HashTable *ht, const char *arg, const char *val) /* {
702709
}
703710
/* }}} */
704711

705-
void oauth_add_signature_header(HashTable *request_headers, HashTable *oauth_args, smart_string *header)
712+
void oauth_add_signature_header(HashTable *request_headers, HashTable *oauth_args, smart_string *header) /* {{{ */
706713
{
707714
smart_string sheader = {0};
708715
zend_bool prepend_comma = FALSE;
@@ -711,13 +718,14 @@ void oauth_add_signature_header(HashTable *request_headers, HashTable *oauth_arg
711718
zend_string *param_name, *param_val;
712719
zend_string *cur_key;
713720
ulong num_key;
721+
HashPosition pos;
714722

715723
smart_string_appends(&sheader, "OAuth ");
716724

717-
for (zend_hash_internal_pointer_reset(oauth_args);
718-
(curval = zend_hash_get_current_data(oauth_args)) != NULL;
719-
zend_hash_move_forward(oauth_args)) {
720-
zend_hash_get_current_key(oauth_args, &cur_key, &num_key);
725+
for (zend_hash_internal_pointer_reset_ex(oauth_args, &pos);
726+
(curval = zend_hash_get_current_data_ex(oauth_args, &pos)) != NULL;
727+
zend_hash_move_forward_ex(oauth_args, &pos)) {
728+
zend_hash_get_current_key_ex(oauth_args, &cur_key, &num_key, &pos);
721729

722730
if (prepend_comma) {
723731
smart_string_appendc(&sheader, ',');
@@ -744,6 +752,7 @@ void oauth_add_signature_header(HashTable *request_headers, HashTable *oauth_arg
744752
}
745753
smart_string_free(&sheader);
746754
}
755+
/* }}} */
747756

748757
#define HTTP_RESPONSE_CAAS(zvalp, header, storkey) { \
749758
if (0==strncasecmp(Z_STRVAL_P(zvalp),header,sizeof(header)-1)) { \
@@ -782,8 +791,8 @@ static long make_req_streams(php_so_object *soo, const char *url, const smart_st
782791
sc = php_stream_context_alloc();
783792

784793
if (payload->len) {
785-
smart_string_0(payload);
786794
ZVAL_STRINGL(&zpayload, payload->c, payload->len);
795+
Z_STRVAL(zpayload)[Z_STRLEN(zpayload)] = '\0';
787796
php_stream_context_set_option(sc, "http", "content", &zpayload);
788797
zval_ptr_dtor(&zpayload);
789798
/**
@@ -988,7 +997,7 @@ int oauth_debug_handler(CURL *ch, curl_infotype type, char *data, size_t data_le
988997
}
989998
/* }}} */
990999

991-
static size_t soo_read_header(void *ptr, size_t size, size_t nmemb, void *ctx)
1000+
static size_t soo_read_header(void *ptr, size_t size, size_t nmemb, void *ctx) /* {{{ */
9921001
{
9931002
char *header;
9941003
size_t hlen, vpos = sizeof("Location:") - 1;
@@ -1024,6 +1033,7 @@ static size_t soo_read_header(void *ptr, size_t size, size_t nmemb, void *ctx)
10241033
}
10251034
return hlen;
10261035
}
1036+
/* }}} */
10271037

10281038
long make_req_curl(php_so_object *soo, const char *url, const smart_string *payload, const char *http_method, HashTable *request_headers) /* {{{ */
10291039
{
@@ -1038,6 +1048,7 @@ long make_req_curl(php_so_object *soo, const char *url, const smart_string *payl
10381048
ulong num_key;
10391049
smart_string sheader = {0};
10401050
zend_string *cur_key;
1051+
HashPosition pos;
10411052

10421053
zca_info = soo_get_property(soo, OAUTH_ATTR_CA_INFO);
10431054
zca_path = soo_get_property(soo, OAUTH_ATTR_CA_PATH);
@@ -1046,11 +1057,11 @@ long make_req_curl(php_so_object *soo, const char *url, const smart_string *payl
10461057
curl = curl_easy_init();
10471058

10481059
if (request_headers) {
1049-
for (zend_hash_internal_pointer_reset(request_headers);
1050-
(cur_val = zend_hash_get_current_data(request_headers)) != NULL;
1051-
zend_hash_move_forward(request_headers)) {
1060+
for (zend_hash_internal_pointer_reset_ex(request_headers, &pos);
1061+
(cur_val = zend_hash_get_current_data_ex(request_headers, &pos)) != NULL;
1062+
zend_hash_move_forward_ex(request_headers, &pos)) {
10521063
/* check if a string based key is used */
1053-
switch (zend_hash_get_current_key(request_headers, &cur_key, &num_key)) {
1064+
switch (zend_hash_get_current_key_ex(request_headers, &cur_key, &num_key, &pos)) {
10541065
case HASH_KEY_IS_STRING:
10551066
smart_string_appendl(&sheader, ZSTR_VAL(cur_key), ZSTR_LEN(cur_key));
10561067
break;
@@ -1440,7 +1451,7 @@ static long oauth_fetch(php_so_object *soo, const char *url, const char *method,
14401451
}
14411452

14421453
/* additional http headers can be passed */
1443-
if (!request_headers) {
1454+
if (!request_headers || !zend_hash_num_elements(Z_ARRVAL_P(request_headers))) {
14441455
ALLOC_HASHTABLE(rheaders);
14451456
zend_hash_init(rheaders, 0, NULL, ZVAL_PTR_DTOR, 0);
14461457
need_to_free_rheaders = 1;
@@ -1655,6 +1666,8 @@ static long oauth_fetch(php_so_object *soo, const char *url, const char *method,
16551666
}
16561667
/* }}} */
16571668

1669+
/* {{{ proto bool setRSACertificate(string $cert)
1670+
Sets the RSA certificate */
16581671
SO_METHOD(setRSACertificate)
16591672
{
16601673
char *key;
@@ -1688,6 +1701,7 @@ SO_METHOD(setRSACertificate)
16881701
return;
16891702
}
16901703
}
1704+
/* }}} */
16911705

16921706
/* {{{ proto string oauth_urlencode(string uri)
16931707
URI encoding according to RFC 3986, note: is not utf8 capable until the underlying phpapi is */
@@ -1859,7 +1873,7 @@ SO_METHOD(__construct)
18591873
}
18601874
/* }}} */
18611875

1862-
void oauth_free_privatekey(zval *privatekey)
1876+
void oauth_free_privatekey(zval *privatekey) /* {{{ */
18631877
{
18641878
zval func, retval;
18651879
zval args[1];
@@ -1876,6 +1890,7 @@ void oauth_free_privatekey(zval *privatekey)
18761890

18771891
zval_ptr_dtor(privatekey);
18781892
}
1893+
/* }}} */
18791894

18801895
/* {{{ proto array OAuth::setCAPath(string ca_path, string ca_info)
18811896
Set the Certificate Authority information */
@@ -2109,7 +2124,6 @@ SO_METHOD(disableSSLChecks)
21092124
}
21102125
/* }}} */
21112126

2112-
21132127
/* {{{ proto bool OAuth::setSSLChecks(long sslcheck)
21142128
Tweak specific SSL checks for requests (be careful using this for production) */
21152129
SO_METHOD(setSSLChecks)
@@ -2134,7 +2148,6 @@ SO_METHOD(setSSLChecks)
21342148
}
21352149
/* }}} */
21362150

2137-
21382151
/* {{{ proto bool OAuth::setVersion(string version)
21392152
Set oauth_version for requests (default 1.0) */
21402153
SO_METHOD(setVersion)
@@ -2248,6 +2261,8 @@ SO_METHOD(setNonce)
22482261
}
22492262
/* }}} */
22502263

2264+
/* {{{ proto bool setTimestamp(string $timestamp)
2265+
Sets the OAuth timestamp for subsequent requests */
22512266
SO_METHOD(setTimestamp)
22522267
{
22532268
php_so_object *soo;
@@ -2272,6 +2287,7 @@ SO_METHOD(setTimestamp)
22722287

22732288
RETURN_TRUE;
22742289
}
2290+
/* }}} */
22752291

22762292
/* {{{ proto bool OAuth::setToken(string token, string token_secret)
22772293
Set a request or access token and token secret to be used in subsequent requests */
@@ -2487,6 +2503,8 @@ SO_METHOD(getLastResponse)
24872503
}
24882504
/* }}} */
24892505

2506+
/* {{{ proto string getLastResponseHeaders(void)
2507+
Get headers for last response */
24902508
SO_METHOD(getLastResponseHeaders)
24912509
{
24922510
php_so_object *soo;
@@ -2501,6 +2519,7 @@ SO_METHOD(getLastResponseHeaders)
25012519
}
25022520
RETURN_FALSE;
25032521
}
2522+
/* }}} */
25042523

25052524
/* {{{ proto string OAuth::getRequestHeader(string http_method, string url [, string|array extra_parameters ])
25062525
Generate OAuth header string signature based on the final HTTP method, URL and a string/array of parameters */
@@ -2801,7 +2820,6 @@ PHP_MINFO_FUNCTION(oauth)
28012820
#else
28022821
php_info_print_table_row(2, "Request engine support", "php_streams");
28032822
#endif
2804-
php_info_print_table_row(2, "source version", "$Id$");
28052823
php_info_print_table_row(2, "version", OAUTH_EXT_VER);
28062824
php_info_print_table_end();
28072825
}

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Requirements: ext/hash (now a part of PHP core)
5353
<license uri="http://www.opensource.org/licenses/bsd-license.php">BSD</license>
5454
<notes>
5555
* Bump version in header
56+
* fix php_pcre_match_impl call in 7.4+ (Remi)
5657
</notes>
5758
<contents>
5859
<dir name="/">

php_oauth.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
+----------------------------------------------------------------------+
99
*/
1010

11-
/* $Id$ */
12-
1311
#ifndef PHP_OAUTH_H
1412
#define PHP_OAUTH_H
1513

@@ -55,7 +53,6 @@
5553
#endif
5654

5755
#define PHP_OAUTH_VERSION 2.0.4
58-
5956
#define __stringify_1(x) #x
6057
#define __stringify(x) __stringify_1(x)
6158
#define __OAUTH_EXT_VER PHP_OAUTH_VERSION

0 commit comments

Comments
 (0)