Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-lb committed Oct 25, 2024
1 parent 257b7ad commit 7b74988
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
13 changes: 12 additions & 1 deletion rdkafka.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ PHP_METHOD(RdKafka, setLogLevel)
/* }}} */

#ifdef HAS_RD_KAFKA_OAUTHBEARER
/* {{{ proto void RdKafka::oauthbearerSetToken(string $token_value, int|float $lifetime_ms, string $principal_name, array $extensions = [])
/* {{{ proto void RdKafka::oauthbearerSetToken(string $token_value, int|float|string $lifetime_ms, string $principal_name, array $extensions = [])
* Set SASL/OAUTHBEARER token and metadata
*
* The SASL/OAUTHBEARER token refresh callback or event handler should cause
Expand Down Expand Up @@ -462,13 +462,24 @@ PHP_METHOD(RdKafka, oauthbearerSetToken)
return;
}

/* On 32-bits, it might be required to pass $lifetime_ms as a float or a
* string */
switch (Z_TYPE_P(zlifetime_ms)) {
case IS_LONG:
lifetime_ms = (int64_t) Z_LVAL_P(zlifetime_ms);
break;
case IS_DOUBLE:
lifetime_ms = (int64_t) Z_DVAL_P(zlifetime_ms);
break;
case IS_STRING:
char *str = Z_STRVAL_P(zlifetime_ms);
char *end;
lifetime_ms = (int64_t) strtoll(str, &end, 10);
if (end != str + Z_STRLEN_P(zlifetime_ms)) {
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Argument #2 ($lifetime_ms) must be a valid integer");
return;
}
break;
EMPTY_SWITCH_DEFAULT_CASE();
}

Expand Down
2 changes: 1 addition & 1 deletion rdkafka.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function resumePartitions(array $topic_partitions): array {}

#ifdef HAS_RD_KAFKA_OAUTHBEARER
/** @tentative-return-type */
public function oauthbearerSetToken(string $token_value, int|float $lifetime_ms, string $principal_name, array $extensions = []): void {}
public function oauthbearerSetToken(string $token_value, int|float|string $lifetime_ms, string $principal_name, array $extensions = []): void {}

/** @tentative-return-type */
public function oauthbearerSetTokenFailure(string $error): void {}
Expand Down
4 changes: 2 additions & 2 deletions rdkafka_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: ac271309a726a9656d3ede7e687a6635d037d966 */
* Stub hash: 44a34fe532e7450e431d2772ce89df92d2d966b6 */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RdKafka___construct, 0, 0, 0)
ZEND_END_ARG_INFO()
Expand Down Expand Up @@ -126,7 +126,7 @@ ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_RdKafka_oauthbea
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RdKafka_oauthbearerSetToken, 0, 0, 3)
#endif
ZEND_ARG_TYPE_INFO(0, token_value, IS_STRING, 0)
ZEND_ARG_TYPE_MASK(0, lifetime_ms, MAY_BE_LONG|MAY_BE_DOUBLE, NULL)
ZEND_ARG_TYPE_MASK(0, lifetime_ms, MAY_BE_LONG|MAY_BE_DOUBLE|MAY_BE_STRING, NULL)
ZEND_ARG_TYPE_INFO(0, principal_name, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, extensions, IS_ARRAY, 0, "[]")
ZEND_END_ARG_INFO()
Expand Down
2 changes: 1 addition & 1 deletion rdkafka_legacy_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: ac271309a726a9656d3ede7e687a6635d037d966 */
* Stub hash: 44a34fe532e7450e431d2772ce89df92d2d966b6 */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RdKafka___construct, 0, 0, 0)
ZEND_END_ARG_INFO()
Expand Down
2 changes: 1 addition & 1 deletion tests/oauthbearer_integration.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ $conf->setErrorCb(function ($producer, $err, $errstr) {
$conf->setOauthbearerTokenRefreshCb(function ($producer) {
echo "Refreshing token and succeeding\n";
$token = generateJws();
$producer->oauthbearerSetToken($token['value'], $token['expiryMs'], $token['principal']);
$producer->oauthbearerSetToken($token['value'], (string) $token['expiryMs'], $token['principal']);
});
$producer = new \RdKafka\Producer($conf);
$producer->poll(0);
Expand Down

0 comments on commit 7b74988

Please sign in to comment.