Skip to content

Commit a68a77f

Browse files
committed
return status code from HTTP callouts
Signed-off-by: Hans Zandbelt <hans.zandbelt@zmartzone.eu>
1 parent 831c4a2 commit a68a77f

File tree

10 files changed

+85
-58
lines changed

10 files changed

+85
-58
lines changed

.project

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
<projects>
66
</projects>
77
<buildSpec>
8-
<buildCommand>
9-
<name>org.eclipse.cdt.autotools.core.genmakebuilderV2</name>
10-
<arguments>
11-
</arguments>
12-
</buildCommand>
138
<buildCommand>
149
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
1510
<triggers>clean,full,incremental,</triggers>
@@ -28,6 +23,5 @@
2823
<nature>org.eclipse.cdt.core.ccnature</nature>
2924
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
3025
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
31-
<nature>org.eclipse.cdt.autotools.core.autotoolsNatureV2</nature>
3226
</natures>
3327
</projectDescription>

.settings/language.settings.xml

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,52 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
22
<project>
3-
<configuration id="org.eclipse.linuxtools.cdt.autotools.core.configuration.build.1562680719" name="Build (GNU)">
4-
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
5-
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
6-
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
7-
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
8-
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuildCommandParser" id="org.eclipse.cdt.autotools.core.LibtoolGCCBuildCommandParser" keep-relative-paths="false" name="CDT Libtool GCC Build Output Parser" parameter="(libtool:\s+compile:\s+)?((g?cc)|([gc]\+\+)|(clang))" prefer-non-shared="true"/>
9-
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="451379389561615664" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
10-
<language-scope id="org.eclipse.cdt.core.gcc"/>
11-
<language-scope id="org.eclipse.cdt.core.g++"/>
12-
</provider>
13-
</extension>
14-
</configuration>
15-
<configuration id="org.eclipse.linuxtools.cdt.autotools.core.configuration.build.debug.1551656597" name="Debug (GNU)">
16-
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
17-
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
18-
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
19-
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
20-
<provider copy-of="extension" id="org.eclipse.cdt.autotools.core.LibtoolGCCBuildCommandParser"/>
21-
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-1658631031518196606" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
22-
<language-scope id="org.eclipse.cdt.core.gcc"/>
23-
<language-scope id="org.eclipse.cdt.core.g++"/>
24-
</provider>
25-
</extension>
26-
</configuration>
3+
4+
<configuration id="org.eclipse.linuxtools.cdt.autotools.core.configuration.build.1562680719" name="Build (GNU)">
5+
6+
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
7+
8+
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
9+
10+
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
11+
12+
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
13+
14+
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuildCommandParser" id="org.eclipse.cdt.autotools.core.LibtoolGCCBuildCommandParser" keep-relative-paths="false" name="CDT Libtool GCC Build Output Parser" parameter="(libtool:\s+compile:\s+)?((g?cc)|([gc]\+\+)|(clang))" prefer-non-shared="true"/>
15+
16+
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="451778127238853664" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
17+
18+
<language-scope id="org.eclipse.cdt.core.gcc"/>
19+
20+
<language-scope id="org.eclipse.cdt.core.g++"/>
21+
22+
</provider>
23+
24+
</extension>
25+
26+
</configuration>
27+
28+
<configuration id="org.eclipse.linuxtools.cdt.autotools.core.configuration.build.debug.1551656597" name="Debug (GNU)">
29+
30+
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
31+
32+
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
33+
34+
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
35+
36+
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
37+
38+
<provider copy-of="extension" id="org.eclipse.cdt.autotools.core.LibtoolGCCBuildCommandParser"/>
39+
40+
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-1658232293840958606" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
41+
42+
<language-scope id="org.eclipse.cdt.core.gcc"/>
43+
44+
<language-scope id="org.eclipse.cdt.core.g++"/>
45+
46+
</provider>
47+
48+
</extension>
49+
50+
</configuration>
51+
2752
</project>

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
07/03/2019
2+
- return status code from HTTP callouts

configure.ac

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
AC_INIT([liboauth2-sts],[1.0.0],[hans.zandbelt@zmartzone.eu])
1+
AC_INIT([liboauth2-sts],[0.0.0],[hans.zandbelt@zmartzone.eu])
22

33
AM_INIT_AUTOMAKE([foreign no-define subdir-objects])
44
AC_CONFIG_MACRO_DIRS([m4])
@@ -13,7 +13,7 @@ PKG_CHECK_MODULES(XML, libxml-2.0 >= 2.4)
1313
AC_SUBST(XML_CFLAGS)
1414
AC_SUBST(XML_LIBS)
1515

16-
PKG_CHECK_MODULES(OAUTH2, liboauth2)
16+
PKG_CHECK_MODULES(OAUTH2, liboauth2 >= 1.1.1)
1717
AC_SUBST(OAUTH2_CFLAGS)
1818
AC_SUBST(OAUTH2_LIBS)
1919

include/oauth2/sts.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ const char *sts_get_pass_target_token_in_hdr_name(oauth2_sts_cfg_t *cfg);
117117
bool sts_request_handler(oauth2_log_t *log, oauth2_sts_cfg_t *cfg,
118118
oauth2_http_request_t *request, char **source_token,
119119
oauth2_cfg_server_callback_funcs_t *srv_cb,
120-
void *srv_cb_ctx);
120+
void *srv_cb_ctx,
121+
oauth2_http_status_code_t *status_code);
121122
bool sts_handler(oauth2_log_t *log, oauth2_sts_cfg_t *cfg, char *source_token,
122-
char **target_token);
123+
char **target_token, oauth2_http_status_code_t *status_code);
123124

124125
#endif /* _OAUTH2_STS_H_ */

src/otx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static const char *sts_otx_get_client_id(oauth2_cfg_sts_t *cfg)
6464
}
6565

6666
bool sts_otx_exec(oauth2_log_t *log, oauth2_cfg_sts_t *cfg, const char *token,
67-
char **rtoken)
67+
char **rtoken, oauth2_uint_t *status_code)
6868
{
6969

7070
bool rc = false;
@@ -100,7 +100,7 @@ bool sts_otx_exec(oauth2_log_t *log, oauth2_cfg_sts_t *cfg, const char *token,
100100
goto end;
101101

102102
rc = sts_util_oauth_call(log, cfg, ctx, sts_otx_get_endpoint(cfg),
103-
params, rtoken);
103+
params, rtoken, status_code);
104104

105105
end:
106106

src/ropc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static const char *sts_ropc_get_username(oauth2_cfg_sts_t *cfg)
7171
}
7272

7373
bool sts_ropc_exec(oauth2_log_t *log, oauth2_cfg_sts_t *cfg, const char *token,
74-
char **rtoken)
74+
char **rtoken, oauth2_uint_t *status_code)
7575
{
7676

7777
bool rc = false;
@@ -106,7 +106,7 @@ bool sts_ropc_exec(oauth2_log_t *log, oauth2_cfg_sts_t *cfg, const char *token,
106106
goto end;
107107

108108
rc = sts_util_oauth_call(log, cfg, ctx, sts_ropc_get_endpoint(cfg),
109-
params, rtoken);
109+
params, rtoken, status_code);
110110

111111
end:
112112

src/sts.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -715,13 +715,13 @@ void sts_merge_request_parameters(oauth2_log_t *log, oauth2_sts_cfg_t *cfg,
715715
bool sts_util_oauth_call(oauth2_log_t *log, oauth2_sts_cfg_t *cfg,
716716
oauth2_http_call_ctx_t *ctx,
717717
const char *token_endpoint,
718-
const oauth2_nv_list_t *params, char **rtoken)
718+
const oauth2_nv_list_t *params, char **rtoken,
719+
oauth2_uint_t *status_code)
719720
{
720721
bool rc = false;
721722
char *response = NULL;
722723
json_t *result = NULL;
723724
char *tkn = NULL;
724-
oauth2_uint_t status_code = 0;
725725

726726
oauth2_http_call_ctx_ssl_verify_set(
727727
log, ctx, sts_cfg_get_ssl_validation(cfg) != 0);
@@ -730,10 +730,10 @@ bool sts_util_oauth_call(oauth2_log_t *log, oauth2_sts_cfg_t *cfg,
730730
// oauth2_http_call_ctx_outgoing_proxy_set(log, ctx, outgoing_proxy);
731731

732732
if (oauth2_http_post_form(log, token_endpoint, params, ctx, &response,
733-
&status_code) == false)
733+
status_code) == false)
734734
goto end;
735735

736-
if ((status_code < 200) || (status_code >= 300))
736+
if ((*status_code < 200) || (*status_code >= 300))
737737
goto end;
738738

739739
if (oauth2_json_decode_check_error(log, response, &result) == false)
@@ -789,19 +789,20 @@ bool sts_util_oauth_call(oauth2_log_t *log, oauth2_sts_cfg_t *cfg,
789789
}
790790

791791
static bool sts_token_exchange_exec(oauth2_log_t *log, oauth2_sts_cfg_t *cfg,
792-
const char *token, char **rtoken)
792+
const char *token, char **rtoken,
793+
oauth2_http_status_code_t *status_code)
793794
{
794795
bool rc = false;
795796

796797
switch (sts_cfg_get_type(cfg)) {
797798
case STS_TYPE_WSTRUST:
798-
rc = sts_wstrust_exec(log, cfg, token, rtoken);
799+
rc = sts_wstrust_exec(log, cfg, token, rtoken, status_code);
799800
break;
800801
case STS_TYPE_ROPC:
801-
rc = sts_ropc_exec(log, cfg, token, rtoken);
802+
rc = sts_ropc_exec(log, cfg, token, rtoken, status_code);
802803
break;
803804
case STS_TYPE_OTX:
804-
rc = sts_otx_exec(log, cfg, token, rtoken);
805+
rc = sts_otx_exec(log, cfg, token, rtoken, status_code);
805806
break;
806807
case STS_TYPE_DISABLED:
807808
break;
@@ -814,7 +815,7 @@ static bool sts_token_exchange_exec(oauth2_log_t *log, oauth2_sts_cfg_t *cfg,
814815
}
815816

816817
bool sts_handler(oauth2_log_t *log, oauth2_sts_cfg_t *cfg, char *source_token,
817-
char **target_token)
818+
char **target_token, oauth2_http_status_code_t *status_code)
818819
{
819820
bool rc = false;
820821
char *cache_key = NULL;
@@ -828,7 +829,8 @@ bool sts_handler(oauth2_log_t *log, oauth2_sts_cfg_t *cfg, char *source_token,
828829

829830
if (*target_token == NULL) {
830831
if (sts_token_exchange_exec(log, cfg, source_token,
831-
target_token) == false) {
832+
target_token,
833+
status_code) == false) {
832834
oauth2_error(log, "sts_util_token_exchange failed");
833835
goto end;
834836
}
@@ -860,7 +862,8 @@ oauth2_cfg_source_token_t *sts_accept_source_token_in_get(oauth2_log_t *log,
860862
bool sts_request_handler(oauth2_log_t *log, oauth2_sts_cfg_t *cfg,
861863
oauth2_http_request_t *request, char **source_token,
862864
oauth2_cfg_server_callback_funcs_t *srv_cb,
863-
void *srv_cb_ctx)
865+
void *srv_cb_ctx,
866+
oauth2_http_status_code_t *status_code)
864867
{
865868
bool rc = false;
866869
char *target_token = NULL;
@@ -873,7 +876,7 @@ bool sts_request_handler(oauth2_log_t *log, oauth2_sts_cfg_t *cfg,
873876
if (*source_token == NULL)
874877
goto end;
875878

876-
rc = sts_handler(log, cfg, *source_token, &target_token);
879+
rc = sts_handler(log, cfg, *source_token, &target_token, status_code);
877880
if (rc == false)
878881
goto end;
879882

src/sts_int.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,15 @@ void sts_merge_request_parameters(oauth2_log_t *log, oauth2_cfg_sts_t *cfg,
7070
bool sts_util_oauth_call(oauth2_log_t *log, oauth2_cfg_sts_t *cfg,
7171
oauth2_http_call_ctx_t *ctx,
7272
const char *token_endpoint,
73-
const oauth2_nv_list_t *params, char **rtoken);
73+
const oauth2_nv_list_t *params, char **rtoken,
74+
oauth2_uint_t *status_code);
7475

7576
bool sts_wstrust_exec(oauth2_log_t *log, oauth2_cfg_sts_t *cfg,
76-
const char *token, char **rtoken);
77+
const char *token, char **rtoken,
78+
oauth2_uint_t *status_code);
7779
bool sts_ropc_exec(oauth2_log_t *log, oauth2_cfg_sts_t *cfg, const char *token,
78-
char **rtoken);
80+
char **rtoken, oauth2_uint_t *status_code);
7981
bool sts_otx_exec(oauth2_log_t *log, oauth2_cfg_sts_t *cfg, const char *token,
80-
char **rtoken);
82+
char **rtoken, oauth2_uint_t *status_code);
8183

8284
#endif /* _OAUTH2_STS_INT_H_ */

src/wstrust.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,8 @@ static int sts_wstrust_parse_token(oauth2_log_t *log, oauth2_cfg_sts_t *cfg,
385385
#define STS_WSTRUST_REQ_SIZE_MAX 32768
386386

387387
bool sts_wstrust_exec(oauth2_log_t *log, oauth2_cfg_sts_t *cfg,
388-
const char *token, char **rtoken)
388+
const char *token, char **rtoken,
389+
oauth2_uint_t *status_code)
389390
{
390391
char *response = NULL, *rst = NULL;
391392
const char *id1 = "_0";
@@ -397,7 +398,6 @@ bool sts_wstrust_exec(oauth2_log_t *log, oauth2_cfg_sts_t *cfg,
397398
bool rc = false;
398399
oauth2_http_call_ctx_t *ctx = NULL;
399400
char data[STS_WSTRUST_REQ_SIZE_MAX];
400-
oauth2_uint_t status_code = 0;
401401

402402
oauth2_debug(log, "enter");
403403

@@ -437,10 +437,10 @@ bool sts_wstrust_exec(oauth2_log_t *log, oauth2_cfg_sts_t *cfg,
437437
sts_cfg_wstrust_get_endpoint(cfg));
438438

439439
if (oauth2_http_call(log, sts_cfg_wstrust_get_endpoint(cfg), data, ctx,
440-
&response, &status_code) == false)
440+
&response, status_code) == false)
441441
goto end;
442442

443-
if ((status_code < 200) || (status_code >= 300))
443+
if ((*status_code < 200) || (*status_code >= 300))
444444
goto end;
445445

446446
rc = sts_wstrust_parse_token(log, cfg, response, token_type, rtoken);

0 commit comments

Comments
 (0)