1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
|
From 696702c57c3ca47ebe139284d7140f21dd335be3 Mon Sep 17 00:00:00 2001
From: Remi Collet <remi@php.net>
Date: Thu, 10 Sep 2020 11:35:13 +0200
Subject: [PATCH 1/3] work for PHP 8
---
oauth.c | 87 +++++++++++++++++++++++++--------------
php_oauth.h | 20 +++++----
provider.c | 44 ++++++++++----------
provider.h | 4 +-
tests/oauth_sbs.phpt | 10 +++--
tests/oauth_standard.phpt | 6 +--
tests/sbs.phpt | 10 +++--
7 files changed, 109 insertions(+), 72 deletions(-)
diff --git a/oauth.c b/oauth.c
index b731216..5f92194 100644
--- a/oauth.c
+++ b/oauth.c
@@ -33,9 +33,15 @@ static zend_object* php_so_object_new(zend_class_entry *ce) /* {{{ */
}
/* }}} */
+#if PHP_VERSION_ID < 80000
static zend_object *oauth_clone_obj(zval *this_ptr) /* {{{ */
{
php_so_object *old_obj = Z_SOO_P(this_ptr);
+#else
+static zend_object *oauth_clone_obj(zend_object *this_ptr) /* {{{ */
+{
+ php_so_object *old_obj = so_object_from_obj(this_ptr);
+#endif
php_so_object *new_obj = so_object_from_obj(php_so_object_new(old_obj->zo.ce));
zend_objects_clone_members(&new_obj->zo, &old_obj->zo);
@@ -176,20 +182,20 @@ void soo_handle_error(php_so_object *soo, long errorCode, char *msg, char *respo
if (!errorCode) {
php_error(E_WARNING, "caller did not pass an errorcode!");
} else {
- zend_update_property_long(dex, &ex, "code", sizeof("code")-1, errorCode);
+ zend_update_property_long(dex, OBJ_FOR_PROP(&ex), "code", sizeof("code")-1, errorCode);
}
if (response) {
- zend_update_property_string(dex, &ex, "lastResponse", sizeof("lastResponse")-1, response);
+ zend_update_property_string(dex, OBJ_FOR_PROP(&ex), "lastResponse", sizeof("lastResponse")-1, response);
}
if(soo && soo->debug && Z_TYPE(soo->debugArr) != IS_UNDEF) {
- zend_update_property(dex, &ex, "debugInfo", sizeof("debugInfo") - 1, &soo->debugArr);
+ zend_update_property(dex, OBJ_FOR_PROP(&ex), "debugInfo", sizeof("debugInfo") - 1, &soo->debugArr);
}
if(additional_info) {
- zend_update_property_string(dex, &ex, "additionalInfo", sizeof("additionalInfo")-1, additional_info);
+ zend_update_property_string(dex, OBJ_FOR_PROP(&ex), "additionalInfo", sizeof("additionalInfo")-1, additional_info);
}
- zend_update_property_string(dex, &ex, "message", sizeof("message")-1, msg);
+ zend_update_property_string(dex, OBJ_FOR_PROP(&ex), "message", sizeof("message")-1, msg);
zend_throw_exception_object(&ex);
}
/* }}} */
@@ -249,7 +255,7 @@ zend_string *soo_sign_rsa(php_so_object *soo, char *message, const oauth_sig_con
ZVAL_NULL(&args[1]);
ZVAL_DUP(&args[2], &ctx->privatekey);
- call_user_function_ex(EG(function_table), NULL, &func, &retval, 3, args, 0, NULL);
+ call_user_function(EG(function_table), NULL, &func, &retval, 3, args);
if (Z_TYPE(retval) == IS_TRUE || Z_TYPE(retval) == IS_FALSE) {
result = php_base64_encode((unsigned char *) Z_STRVAL_P(Z_REFVAL(args[1])), Z_STRLEN_P(Z_REFVAL(args[1])));
@@ -373,23 +379,31 @@ static int oauth_strcmp(zval *first, zval *second) /* {{{ */
}
/* }}} */
+#if PHP_VERSION_ID < 80000
static int oauth_compare_value(const void *a, const void *b) /* {{{ */
{
Bucket *f, *s;
f = (Bucket *)a;
s = (Bucket *)b;
+#else
+static int oauth_compare_value(Bucket *f, Bucket *s) /* {{{ */
+{
+#endif
return oauth_strcmp(&f->val, &s->val);
}
/* }}} */
+#if PHP_VERSION_ID < 80000
static int oauth_compare_key(const void *a, const void *b) /* {{{ */
{
+ Bucket *f = (Bucket *)a, *s = (Bucket *)b;
+#else
+static int oauth_compare_key(Bucket *f, Bucket *s) /* {{{ */
+{
+#endif
zval first, second;
int result;
- Bucket *f, *s;
- f = (Bucket *) a;
- s = (Bucket *) b;
if (f->key == NULL) {
ZVAL_LONG(&first, f->h);
@@ -691,7 +705,7 @@ static void oauth_set_debug_info(php_so_object *soo) /* {{{ */
ADD_DEBUG_INFO(debugInfo, "body_recv", soo->debug_info->body_in, 0);
ADD_DEBUG_INFO(debugInfo, "info", soo->debug_info->curl_info, 0);
- zend_update_property(soo_class_entry, soo->this_ptr, "debugInfo", sizeof("debugInfo") - 1, debugInfo);
+ zend_update_property(soo_class_entry, OBJ_FOR_PROP(soo->this_ptr), "debugInfo", sizeof("debugInfo") - 1, debugInfo);
} else {
ZVAL_UNDEF(&soo->debugArr);
}
@@ -815,7 +829,7 @@ static long make_req_streams(php_so_object *soo, const char *url, const smart_st
zend_hash_move_forward_ex(request_headers, &pos)) {
/* check if a string based key is used */
smart_string sheaderline = {0};
- switch (zend_hash_get_current_key_ex(request_headers, &cur_key, &num_key, &pos)) {
+ switch ((int)zend_hash_get_current_key_ex(request_headers, &cur_key, &num_key, &pos)) {
case HASH_KEY_IS_STRING:
smart_string_appendl(&sheaderline, ZSTR_VAL(cur_key), ZSTR_LEN(cur_key));
break;
@@ -1061,7 +1075,7 @@ long make_req_curl(php_so_object *soo, const char *url, const smart_string *payl
(cur_val = zend_hash_get_current_data_ex(request_headers, &pos)) != NULL;
zend_hash_move_forward_ex(request_headers, &pos)) {
/* check if a string based key is used */
- switch (zend_hash_get_current_key_ex(request_headers, &cur_key, &num_key, &pos)) {
+ switch ((int)zend_hash_get_current_key_ex(request_headers, &cur_key, &num_key, &pos)) {
case HASH_KEY_IS_STRING:
smart_string_appendl(&sheader, ZSTR_VAL(cur_key), ZSTR_LEN(cur_key));
break;
@@ -1797,11 +1811,13 @@ SO_METHOD(__construct)
INIT_smart_string(soo->headers_in);
/* set default class members */
- zend_update_property_null(soo_class_entry, obj, "debugInfo", sizeof("debugInfo") - 1);
- zend_update_property_bool(soo_class_entry, obj, "debug", sizeof("debug") - 1, soo->debug);
- zend_update_property_long(soo_class_entry, obj, "sslChecks", sizeof("sslChecks") - 1, soo->sslcheck);
+ zend_update_property_null(soo_class_entry, OBJ_FOR_PROP(obj), "debugInfo", sizeof("debugInfo") - 1);
+ zend_update_property_bool(soo_class_entry, OBJ_FOR_PROP(obj), "debug", sizeof("debug") - 1, soo->debug);
+ zend_update_property_long(soo_class_entry, OBJ_FOR_PROP(obj), "sslChecks", sizeof("sslChecks") - 1, soo->sslcheck);
+#if PHP_VERSION_ID < 80000
TSRMLS_SET_CTX(soo->thread_ctx);
+#endif
if (!sig_method_len) {
sig_method = OAUTH_SIG_METHOD_HMACSHA1;
@@ -2046,7 +2062,7 @@ SO_METHOD(disableDebug)
}
soo->debug = 0;
- zend_update_property_bool(soo_class_entry, obj, "debug", sizeof("debug") - 1, 0);
+ zend_update_property_bool(soo_class_entry, OBJ_FOR_PROP(obj), "debug", sizeof("debug") - 1, 0);
RETURN_TRUE;
}
@@ -2067,7 +2083,7 @@ SO_METHOD(enableDebug)
}
soo->debug = 1;
- zend_update_property_bool(soo_class_entry, obj, "debug", sizeof("debug") - 1, 1);
+ zend_update_property_bool(soo_class_entry, OBJ_FOR_PROP(obj), "debug", sizeof("debug") - 1, 1);
RETURN_TRUE;
}
@@ -2088,7 +2104,7 @@ SO_METHOD(enableSSLChecks)
}
soo->sslcheck = OAUTH_SSLCHECK_BOTH;
- zend_update_property_long(soo_class_entry, obj, "sslChecks", sizeof("sslChecks") - 1, 1);
+ zend_update_property_long(soo_class_entry, OBJ_FOR_PROP(obj), "sslChecks", sizeof("sslChecks") - 1, 1);
RETURN_TRUE;
}
@@ -2109,7 +2125,7 @@ SO_METHOD(disableSSLChecks)
}
soo->sslcheck = OAUTH_SSLCHECK_NONE;
- zend_update_property_long(soo_class_entry, obj, "sslChecks", sizeof("sslChecks") - 1, 0);
+ zend_update_property_long(soo_class_entry, OBJ_FOR_PROP(obj), "sslChecks", sizeof("sslChecks") - 1, 0);
RETURN_TRUE;
}
@@ -2132,7 +2148,7 @@ SO_METHOD(setSSLChecks)
soo->sslcheck = sslcheck & OAUTH_SSLCHECK_BOTH;
- zend_update_property_long(soo_class_entry, obj, "sslChecks", sizeof("sslChecks") - 1,
+ zend_update_property_long(soo_class_entry, OBJ_FOR_PROP(obj), "sslChecks", sizeof("sslChecks") - 1,
soo->sslcheck);
RETURN_TRUE;
@@ -2671,24 +2687,32 @@ static zend_function_entry so_functions[] = { /* {{{ */
/* }}} */
+#if PHP_VERSION_ID < 80000
zval *oauth_read_member(zval *obj, zval *mem, int type, void **cache_slot, zval *rv) /* {{{ */
{
+ php_so_object *soo = Z_SOO_P(obj);
+ char *name = Z_STRVAL_P(mem);
+#else
+zval *oauth_read_member(zend_object *obj, zend_string *mem, int type, void **cache_slot, zval *rv) /* {{{ */
+{
+ php_so_object *soo = so_object_from_obj(obj);
+ char *name = ZSTR_VAL(mem);
+#endif
zval *return_value = NULL;
- php_so_object *soo;
-
- soo = Z_SOO_P(obj);
return_value = std_object_handlers.read_property(obj, mem, type, cache_slot, rv);
- if(!strcasecmp(Z_STRVAL_P(mem),"debug")) {
+ if(!strcasecmp(name, "debug")) {
convert_to_boolean(return_value);
ZVAL_BOOL(return_value, soo->debug);
- } else if(!strcasecmp(Z_STRVAL_P(mem),"sslChecks")) {
+ } else if(!strcasecmp(name, "sslChecks")) {
ZVAL_LONG(return_value, soo->sslcheck);
}
return return_value;
} /* }}} */
+
+#if PHP_VERSION_ID < 80000
static
#if PHP_VERSION_ID >= 70400
zval *
@@ -2697,11 +2721,14 @@ void
#endif
oauth_write_member(zval *obj, zval *mem, zval *value, void **cache_slot) /* {{{ */
{
- char *property;
- php_so_object *soo;
-
- property = Z_STRVAL_P(mem);
- soo = Z_SOO_P(obj);
+ php_so_object *soo = Z_SOO_P(obj);
+ char *property = Z_STRVAL_P(mem);
+#else
+static zval *oauth_write_member(zend_object *obj, zend_string *mem, zval *value, void **cache_slot) /* {{{ */
+{
+ php_so_object *soo = so_object_from_obj(obj);
+ char *property = ZSTR_VAL(mem);
+#endif
if(!strcmp(property,"debug")) {
soo->debug = Z_TYPE_P(value) == IS_TRUE ? 1 : 0;
diff --git a/php_oauth.h b/php_oauth.h
index d5614c4..e472a26 100644
--- a/php_oauth.h
+++ b/php_oauth.h
@@ -251,11 +251,11 @@ static inline php_so_object *Z_SOO_P(zval *zv) /* {{{ */ {
#ifndef zend_parse_parameters_none
#define zend_parse_parameters_none() \
- zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "")
+ zend_parse_parameters(ZEND_NUM_ARGS(), "")
#endif
-void soo_handle_error(php_so_object *soo, long errorCode, char *msg, char *response, char *additional_info TSRMLS_DC);
-zend_string *oauth_generate_sig_base(php_so_object *soo, const char *http_method, const char *uri, HashTable *post_args, HashTable *extra_args TSRMLS_DC);
+void soo_handle_error(php_so_object *soo, long errorCode, char *msg, char *response, char *additional_info);
+zend_string *oauth_generate_sig_base(php_so_object *soo, const char *http_method, const char *uri, HashTable *post_args, HashTable *extra_args);
#ifndef zend_hash_quick_del
#define HASH_DEL_KEY_QUICK 2
@@ -318,15 +318,15 @@ zend_string *oauth_generate_sig_base(php_so_object *soo, const char *http_method
#define OAUTH_OK SUCCESS
#if OAUTH_USE_CURL
-long make_req_curl(php_so_object *soo, const char *url, const smart_string *payload, const char *http_method, HashTable *request_headers TSRMLS_DC);
+long make_req_curl(php_so_object *soo, const char *url, const smart_string *payload, const char *http_method, HashTable *request_headers);
#if LIBCURL_VERSION_NUM >= 0x071304
#define OAUTH_PROTOCOLS_ALLOWED CURLPROTO_HTTP | CURLPROTO_HTTPS
#endif
#endif
-void oauth_free_privatekey(zval *privatekey TSRMLS_DC);
-zend_string *soo_sign(php_so_object *soo, char *message, zval *cs, zval *ts, const oauth_sig_context *ctx TSRMLS_DC);
+void oauth_free_privatekey(zval *privatekey);
+zend_string *soo_sign(php_so_object *soo, char *message, zval *cs, zval *ts, const oauth_sig_context *ctx);
oauth_sig_context *oauth_create_sig_context(const char *sigmethod);
zend_string *oauth_url_encode(char *url, int url_len);
@@ -340,6 +340,12 @@ zend_string *oauth_url_encode(char *url, int url_len);
#define OAUTH_URL_LEN(a) ZSTR_LEN(a)
#endif
+#if PHP_VERSION_ID < 80000
+#define OBJ_FOR_PROP(zv) (zv)
+#else
+#define OBJ_FOR_PROP(zv) Z_OBJ_P(zv)
+#endif
+
#endif
/**
@@ -350,4 +356,4 @@ zend_string *oauth_url_encode(char *url, int url_len);
* End:
* vim600: fdm=marker
* vim: noet sw=4 ts=4 noexpandtab
- */
\ No newline at end of file
+ */
diff --git a/provider.c b/provider.c
index 5e88f5c..e870bae 100644
--- a/provider.c
+++ b/provider.c
@@ -24,7 +24,7 @@ static zend_class_entry *oauthprovider;
static inline void oauth_provider_set_param_member(zval *provider_obj, char *prop_name, zval *prop) /* {{{ */
{
- zend_update_property(Z_OBJCE_P(provider_obj), provider_obj, prop_name, strlen(prop_name), prop);
+ zend_update_property(Z_OBJCE_P(provider_obj), OBJ_FOR_PROP(provider_obj), prop_name, strlen(prop_name), prop);
}
/* }}} */
@@ -117,7 +117,7 @@ static int oauth_provider_token_required(zval *provider_obj, char* uri)
{
zval *is_req_token_api, rv;
- is_req_token_api = zend_read_property(Z_OBJCE_P(provider_obj), provider_obj, "request_token_endpoint", sizeof("request_token_endpoint") - 1, 1, &rv);
+ is_req_token_api = zend_read_property(Z_OBJCE_P(provider_obj), OBJ_FOR_PROP(provider_obj), "request_token_endpoint", sizeof("request_token_endpoint") - 1, 1, &rv);
if (Z_TYPE_P(is_req_token_api) == IS_FALSE) {
php_oauth_provider *sop;
@@ -374,7 +374,7 @@ static zval *oauth_provider_call_cb(INTERNAL_FUNCTION_PARAMETERS, int type) /* {
}
if (zend_fcall_info_call(cb->fcall_info, &cb->fcall_info_cache, return_value, &args)!=SUCCESS) {
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Failed calling callback %s", Z_STRVAL(cb->fcall_info->function_name));
+ php_error_docref(NULL, E_ERROR, "Failed calling callback %s", Z_STRVAL(cb->fcall_info->function_name));
}
zval_ptr_dtor(&args);
@@ -490,17 +490,17 @@ SOP_METHOD(__construct)
oauth_provider_set_default_required_params(sop->required_params);
- zend_update_property_null(Z_OBJCE_P(pthis), pthis, OAUTH_PROVIDER_CONSUMER_KEY, sizeof(OAUTH_PROVIDER_CONSUMER_KEY)-1);
- zend_update_property_null(Z_OBJCE_P(pthis), pthis, OAUTH_PROVIDER_CONSUMER_SECRET, sizeof(OAUTH_PROVIDER_CONSUMER_SECRET)-1);
- zend_update_property_null(Z_OBJCE_P(pthis), pthis, OAUTH_PROVIDER_NONCE, sizeof(OAUTH_PROVIDER_NONCE)-1);
- zend_update_property_null(Z_OBJCE_P(pthis), pthis, OAUTH_PROVIDER_TOKEN, sizeof(OAUTH_PROVIDER_TOKEN)-1);
- zend_update_property_null(Z_OBJCE_P(pthis), pthis, OAUTH_PROVIDER_TOKEN_SECRET, sizeof(OAUTH_PROVIDER_TOKEN_SECRET)-1);
- zend_update_property_null(Z_OBJCE_P(pthis), pthis, OAUTH_PROVIDER_TIMESTAMP, sizeof(OAUTH_PROVIDER_TIMESTAMP)-1);
- zend_update_property_null(Z_OBJCE_P(pthis), pthis, OAUTH_PROVIDER_VERSION, sizeof(OAUTH_PROVIDER_VERSION)-1);
- zend_update_property_null(Z_OBJCE_P(pthis), pthis, OAUTH_PROVIDER_SIGNATURE_METHOD, sizeof(OAUTH_PROVIDER_SIGNATURE_METHOD)-1);
- zend_update_property_null(Z_OBJCE_P(pthis), pthis, OAUTH_PROVIDER_CALLBACK, sizeof(OAUTH_PROVIDER_CALLBACK)-1);
+ zend_update_property_null(Z_OBJCE_P(pthis), OBJ_FOR_PROP(pthis), OAUTH_PROVIDER_CONSUMER_KEY, sizeof(OAUTH_PROVIDER_CONSUMER_KEY)-1);
+ zend_update_property_null(Z_OBJCE_P(pthis), OBJ_FOR_PROP(pthis), OAUTH_PROVIDER_CONSUMER_SECRET, sizeof(OAUTH_PROVIDER_CONSUMER_SECRET)-1);
+ zend_update_property_null(Z_OBJCE_P(pthis), OBJ_FOR_PROP(pthis), OAUTH_PROVIDER_NONCE, sizeof(OAUTH_PROVIDER_NONCE)-1);
+ zend_update_property_null(Z_OBJCE_P(pthis), OBJ_FOR_PROP(pthis), OAUTH_PROVIDER_TOKEN, sizeof(OAUTH_PROVIDER_TOKEN)-1);
+ zend_update_property_null(Z_OBJCE_P(pthis), OBJ_FOR_PROP(pthis), OAUTH_PROVIDER_TOKEN_SECRET, sizeof(OAUTH_PROVIDER_TOKEN_SECRET)-1);
+ zend_update_property_null(Z_OBJCE_P(pthis), OBJ_FOR_PROP(pthis), OAUTH_PROVIDER_TIMESTAMP, sizeof(OAUTH_PROVIDER_TIMESTAMP)-1);
+ zend_update_property_null(Z_OBJCE_P(pthis), OBJ_FOR_PROP(pthis), OAUTH_PROVIDER_VERSION, sizeof(OAUTH_PROVIDER_VERSION)-1);
+ zend_update_property_null(Z_OBJCE_P(pthis), OBJ_FOR_PROP(pthis), OAUTH_PROVIDER_SIGNATURE_METHOD, sizeof(OAUTH_PROVIDER_SIGNATURE_METHOD)-1);
+ zend_update_property_null(Z_OBJCE_P(pthis), OBJ_FOR_PROP(pthis), OAUTH_PROVIDER_CALLBACK, sizeof(OAUTH_PROVIDER_CALLBACK)-1);
- zend_update_property_bool(Z_OBJCE_P(pthis), pthis, "request_token_endpoint", sizeof("request_token_endpoint")-1, 0);
+ zend_update_property_bool(Z_OBJCE_P(pthis), OBJ_FOR_PROP(pthis), "request_token_endpoint", sizeof("request_token_endpoint")-1, 0);
if(!param_count) {
/* TODO: support NSAPI */
@@ -632,7 +632,7 @@ SOP_METHOD(isRequestTokenEndpoint)
return;
}
- zend_update_property_bool(Z_OBJCE_P(pthis), pthis, "request_token_endpoint", sizeof("request_token_endpoint") - 1, req_api);
+ zend_update_property_bool(Z_OBJCE_P(pthis), OBJ_FOR_PROP(pthis), "request_token_endpoint", sizeof("request_token_endpoint") - 1, req_api);
}
/* }}} */
@@ -734,7 +734,7 @@ SOP_METHOD(checkOAuthRequest)
return;
}
- sig_method = zend_read_property(Z_OBJCE_P(pthis), pthis, OAUTH_PROVIDER_SIGNATURE_METHOD, sizeof(OAUTH_PROVIDER_SIGNATURE_METHOD) - 1, 1, &rv);
+ sig_method = zend_read_property(Z_OBJCE_P(pthis), OBJ_FOR_PROP(pthis), OAUTH_PROVIDER_SIGNATURE_METHOD, sizeof(OAUTH_PROVIDER_SIGNATURE_METHOD) - 1, 1, &rv);
do {
if (sig_method && (Z_TYPE_P(sig_method) == IS_STRING) && Z_STRLEN_P(sig_method)) {
sig_ctx = oauth_create_sig_context(Z_STRVAL_P(sig_method));
@@ -803,16 +803,16 @@ SOP_METHOD(checkOAuthRequest)
sbs = oauth_generate_sig_base(NULL, http_verb, uri, sbs_vars, NULL);
if (sbs) {
- consumer_secret = zend_read_property(Z_OBJCE_P(pthis), pthis, OAUTH_PROVIDER_CONSUMER_SECRET, sizeof(OAUTH_PROVIDER_CONSUMER_SECRET) - 1, 1, &rv);
+ consumer_secret = zend_read_property(Z_OBJCE_P(pthis), OBJ_FOR_PROP(pthis), OAUTH_PROVIDER_CONSUMER_SECRET, sizeof(OAUTH_PROVIDER_CONSUMER_SECRET) - 1, 1, &rv);
convert_to_string_ex(consumer_secret);
if (is_token_required) {
- token_secret = zend_read_property(Z_OBJCE_P(pthis), pthis, OAUTH_PROVIDER_TOKEN_SECRET, sizeof(OAUTH_PROVIDER_TOKEN_SECRET) - 1, 1, &rv);
+ token_secret = zend_read_property(Z_OBJCE_P(pthis), OBJ_FOR_PROP(pthis), OAUTH_PROVIDER_TOKEN_SECRET, sizeof(OAUTH_PROVIDER_TOKEN_SECRET) - 1, 1, &rv);
convert_to_string_ex(token_secret);
}
signature = soo_sign(NULL, ZSTR_VAL(sbs), consumer_secret, token_secret, sig_ctx);
}
- req_signature = zend_read_property(Z_OBJCE_P(pthis), pthis, OAUTH_PROVIDER_SIGNATURE, sizeof(OAUTH_PROVIDER_SIGNATURE) - 1, 1, &rv);
+ req_signature = zend_read_property(Z_OBJCE_P(pthis), OBJ_FOR_PROP(pthis), OAUTH_PROVIDER_SIGNATURE, sizeof(OAUTH_PROVIDER_SIGNATURE) - 1, 1, &rv);
if (!signature || !Z_STRLEN_P(req_signature) || strcmp(ZSTR_VAL(signature), Z_STRVAL_P(req_signature))) {
soo_handle_error(NULL, OAUTH_INVALID_SIGNATURE, "Signatures do not match", NULL, sbs ? ZSTR_VAL(sbs) : NULL);
}
@@ -984,7 +984,7 @@ SOP_METHOD(reportProblem)
}
/* XXX good candidate for refactoring */
- code = zend_read_property(Z_OBJCE_P(exception), exception, "code", sizeof("code") - 1, 1, &rv);
+ code = zend_read_property(Z_OBJCE_P(exception), OBJ_FOR_PROP(exception), "code", sizeof("code") - 1, 1, &rv);
lcode = Z_LVAL_P(code);
switch(lcode) {
@@ -1018,7 +1018,7 @@ SOP_METHOD(reportProblem)
case OAUTH_INVALID_SIGNATURE:
http_code = OAUTH_ERR_BAD_AUTH;
out = "oauth_problem=signature_invalid";
- sbs = zend_read_property(Z_OBJCE_P(exception), exception, "additionalInfo", sizeof("additionalInfo") - 1, 1, &rv);
+ sbs = zend_read_property(Z_OBJCE_P(exception), OBJ_FOR_PROP(exception), "additionalInfo", sizeof("additionalInfo") - 1, 1, &rv);
if (sbs && IS_NULL!=Z_TYPE_P(sbs)) {
convert_to_string_ex(sbs);
if(Z_STRLEN_P(sbs)) {
@@ -1037,7 +1037,7 @@ SOP_METHOD(reportProblem)
case OAUTH_PARAMETER_ABSENT:
http_code = OAUTH_ERR_BAD_REQUEST;
out = "oauth_problem=parameter_absent";
- missing_params = zend_read_property(Z_OBJCE_P(exception), exception, "additionalInfo", sizeof("additionalInfo") - 1, 1, &rv);
+ missing_params = zend_read_property(Z_OBJCE_P(exception), OBJ_FOR_PROP(exception), "additionalInfo", sizeof("additionalInfo") - 1, 1, &rv);
if(missing_params) {
convert_to_string_ex(missing_params);
if(Z_STRLEN_P(missing_params)) {
@@ -1176,7 +1176,7 @@ static zend_function_entry oauth_provider_methods[] = { /* {{{ */
{NULL, NULL, NULL}
};
-extern int oauth_provider_register_class() /* {{{ */
+extern int oauth_provider_register_class(void) /* {{{ */
{
zend_class_entry osce;
diff --git a/provider.h b/provider.h
index aa9d61b..90ec01a 100644
--- a/provider.h
+++ b/provider.h
@@ -47,7 +47,7 @@
} \
#define OAUTH_PROVIDER_CHECK_PARAMS(s, r) \
- if(oauth_provider_check_sapi(s, TRUE TSRMLS_CC)) { \
+ if(oauth_provider_check_sapi(s, TRUE)) { \
if(r) {\
RETURN_FALSE\
} \
@@ -110,7 +110,7 @@ static inline php_oauth_provider *sop_object_from_obj(zend_object *obj) /* {{{ *
#define Z_SOP_P(zv) sop_object_from_obj(Z_OBJ_P((zv)))
-extern int oauth_provider_register_class(TSRMLS_D);
+extern int oauth_provider_register_class(void);
#define SOP_METHOD(func) PHP_METHOD(oauthprovider, func)
#define SOP_ME(func, arg_info, flags) PHP_ME(oauthprovider, func, arg_info, flags)
diff --git a/tests/oauth_sbs.phpt b/tests/oauth_sbs.phpt
index 4e9269e..6d9bb4c 100644
--- a/tests/oauth_sbs.phpt
+++ b/tests/oauth_sbs.phpt
@@ -8,7 +8,11 @@ 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";
+try {
+ echo oauth_get_sbs('GET', 'http://127.0.0.1:12342/',''),"\n";
+} catch (TypeError $e) {
+ echo $e->getMessage()."\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";
@@ -31,9 +35,7 @@ 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
-
+%Astring given%A
-- using numeric keys masked as a string --
GET&http%3A%2F%2F127.0.0.1%3A12342%2F&1%3Dhello
-- using string keys --
diff --git a/tests/oauth_standard.phpt b/tests/oauth_standard.phpt
index 0342f8a..5eb2d57 100644
--- a/tests/oauth_standard.phpt
+++ b/tests/oauth_standard.phpt
@@ -61,6 +61,8 @@ try {
var_dump($x->setVersion());
} catch (Exception $e) {
echo "EXCEPTION {$e->getCode()}: {$e->getMessage()}\n";
+} catch (ArgumentCountError $e) {
+ echo "EXCEPTION {$e->getCode()}: {$e->getMessage()}\n";
}
try {
echo "-- set version with boolean --\n";
@@ -115,9 +117,7 @@ OAuth[debug=1,sslChecks=3,debugInfo=]
-- disable debug --
OAuth[debug=0,sslChecks=3,debugInfo=]
-- set version without parameters --
-
-Warning: OAuth::setVersion() expects exactly 1 parameter, 0 given %s
-NULL
+%A expects exactly 1 parameter, %A
-- set version with boolean --
bool(true)
-- set version with empty string --
diff --git a/tests/sbs.phpt b/tests/sbs.phpt
index 1333607..2e8e13b 100644
--- a/tests/sbs.phpt
+++ b/tests/sbs.phpt
@@ -8,7 +8,11 @@ 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";
+try {
+ echo oauth_get_sbs('GET', 'http://127.0.0.1:12342/',''),"\n";
+} catch (TypeError $e) {
+ echo $e->getMessage()."\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";
@@ -29,9 +33,7 @@ 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,%sstring given in %s
-
+%Astring given%A
-- using numeric keys masked as a string --
GET&http%3A%2F%2F127.0.0.1%3A12342%2F&1%3Dhello
-- using string keys --
From 2e304d2702eed50e68b0b52850aabda8531833d1 Mon Sep 17 00:00:00 2001
From: Michael Wallner <mike@php.net>
Date: Fri, 18 Sep 2020 08:21:27 +0200
Subject: [PATCH 2/3] fix test expectations for PHP 8
---
tests/oauth_standard.phpt | 2 +-
tests/plaintext.phpt | 2 +-
tests/plaintext2.phpt | 4 ++--
tests/rsa.phpt | 2 +-
tests/skip.inc | 5 +++--
5 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/tests/oauth_standard.phpt b/tests/oauth_standard.phpt
index 5eb2d57..a267d73 100644
--- a/tests/oauth_standard.phpt
+++ b/tests/oauth_standard.phpt
@@ -117,7 +117,7 @@ OAuth[debug=1,sslChecks=3,debugInfo=]
-- disable debug --
OAuth[debug=0,sslChecks=3,debugInfo=]
-- set version without parameters --
-%A expects exactly 1 parameter, %A
+%A expects exactly 1 %A
-- set version with boolean --
bool(true)
-- set version with empty string --
diff --git a/tests/plaintext.phpt b/tests/plaintext.phpt
index 0f72ba5..0d3589e 100644
--- a/tests/plaintext.phpt
+++ b/tests/plaintext.phpt
@@ -35,7 +35,7 @@ array(2) {
["oauth_token_secret"]=>
string(4) "4567"
}
-string(%d) "POST /test?oauth_consumer_key=conskey&oauth_signature_method=PLAINTEXT&oauth_nonce=testing&oauth_timestamp=12345&oauth_version=1.0&oauth_signature=conssecret%26 HTTP/1.0
+string(%d) "POST /test?oauth_consumer_key=conskey&oauth_signature_method=PLAINTEXT&oauth_nonce=testing&oauth_timestamp=12345&oauth_version=1.0&oauth_signature=conssecret%26 HTTP/1.%d
Host: 127.0.0.1:12342
Connection: close
diff --git a/tests/plaintext2.phpt b/tests/plaintext2.phpt
index 702e73c..99982b0 100644
--- a/tests/plaintext2.phpt
+++ b/tests/plaintext2.phpt
@@ -44,11 +44,11 @@ array(2) {
["oauth_token_secret"]=>
string(4) "8901"
}
-string(%d) "POST /test?oauth_consumer_key=conskey&oauth_signature_method=PLAINTEXT&oauth_nonce=testing&oauth_timestamp=12345&oauth_version=1.0&oauth_token=key&oauth_signature=conssecret%26secret HTTP/1.0
+string(%d) "POST /test?oauth_consumer_key=conskey&oauth_signature_method=PLAINTEXT&oauth_nonce=testing&oauth_timestamp=12345&oauth_version=1.0&oauth_token=key&oauth_signature=conssecret%26secret HTTP/1.%d
Host: 127.0.0.1:12342
Connection: close
-GET /test?oauth_consumer_key=conskey&oauth_signature_method=PLAINTEXT&oauth_nonce=testing&oauth_timestamp=12345&oauth_version=1.0&oauth_token=key&oauth_signature=conssecret%26secret HTTP/1.0
+GET /test?oauth_consumer_key=conskey&oauth_signature_method=PLAINTEXT&oauth_nonce=testing&oauth_timestamp=12345&oauth_version=1.0&oauth_token=key&oauth_signature=conssecret%26secret HTTP/1.%d
Host: 127.0.0.1:12342
Connection: close
diff --git a/tests/rsa.phpt b/tests/rsa.phpt
index 7ef8441..49442fb 100644
--- a/tests/rsa.phpt
+++ b/tests/rsa.phpt
@@ -38,7 +38,7 @@ array(2) {
["oauth_token_secret"]=>
string(4) "4567"
}
-string(%d) "POST /test?oauth_consumer_key=1234&oauth_signature_method=RSA-SHA1&oauth_nonce=testing&oauth_timestamp=12345&oauth_version=1.0&oauth_signature=AxTdf9nwR0Z54JCKIKAne%2BXKmNtuKerXchcK8axD792sk7cphqMBvNqbPVoJmKYcm0vAkq2ICto0NVz4%2F6WxqA%3D%3D HTTP/1.0
+string(%d) "POST /test?oauth_consumer_key=1234&oauth_signature_method=RSA-SHA1&oauth_nonce=testing&oauth_timestamp=12345&oauth_version=1.0&oauth_signature=AxTdf9nwR0Z54JCKIKAne%2BXKmNtuKerXchcK8axD792sk7cphqMBvNqbPVoJmKYcm0vAkq2ICto0NVz4%2F6WxqA%3D%3D HTTP/1.%d
Host: 127.0.0.1:12342
Connection: close
diff --git a/tests/skip.inc b/tests/skip.inc
index bca4142..3fac34b 100644
--- a/tests/skip.inc
+++ b/tests/skip.inc
@@ -47,7 +47,8 @@ function has_bug($bugid)
switch ($bugid) {
case '44603':
// >= 5.1.0 && < 5.2.6
- return (PHP_MINOR_VERSION==1 || (PHP_MINOR_VERSION==2 && PHP_RELEASE_VERSION<6));
+ return (PHP_MAJOR_VERSION==5)
+ && (PHP_MINOR_VERSION==1 || (PHP_MINOR_VERSION==2 && PHP_RELEASE_VERSION<6));
}
return false;
}
@@ -66,4 +67,4 @@ function skip_with_bug($bugid)
}
}
-?>
+?>
\ No newline at end of file
From fa5add1e4e290468214be71df5db738d9aef7105 Mon Sep 17 00:00:00 2001
From: Michael Wallner <mike@php.net>
Date: Fri, 18 Sep 2020 08:22:35 +0200
Subject: [PATCH 3/3] PHP 8 fixes
- ext/openssl's private key is an object now
- pass-by-ref args must be prepared manually
---
oauth.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/oauth.c b/oauth.c
index 5f92194..f845893 100644
--- a/oauth.c
+++ b/oauth.c
@@ -253,12 +253,15 @@ zend_string *soo_sign_rsa(php_so_object *soo, char *message, const oauth_sig_con
ZVAL_STRING(&args[0], message);
ZVAL_NULL(&args[1]);
+ ZVAL_MAKE_REF(&args[1]);
ZVAL_DUP(&args[2], &ctx->privatekey);
call_user_function(EG(function_table), NULL, &func, &retval, 3, args);
if (Z_TYPE(retval) == IS_TRUE || Z_TYPE(retval) == IS_FALSE) {
- result = php_base64_encode((unsigned char *) Z_STRVAL_P(Z_REFVAL(args[1])), Z_STRLEN_P(Z_REFVAL(args[1])));
+ zend_string *sig_str = zval_get_string(&args[1]);
+ result = php_base64_encode((unsigned char *) sig_str->val, sig_str->len);
+ zend_string_release(sig_str);
zval_ptr_dtor(&args[1]);
} else {
result = NULL;
@@ -1697,10 +1700,13 @@ SO_METHOD(setRSACertificate)
zval_ptr_dtor(&args[0]);
zval_ptr_dtor(&func);
- if (Z_TYPE(retval) == IS_RESOURCE) {
+ switch (Z_TYPE(retval)) {
+ case IS_RESOURCE:
+ case IS_OBJECT:
OAUTH_SIGCTX_SET_PRIVATEKEY(soo->sig_ctx, retval);
RETURN_TRUE;
- } else {
+ break;
+ default:
zval_ptr_dtor(&retval);
soo_handle_error(soo, OAUTH_ERR_INTERNAL_ERROR, "Could not parse RSA certificate", NULL, NULL);
return;
|