Skip to content

Commit d710061

Browse files
committed
jwt_io.c: reformat the whole file
I don't like tabs
1 parent 991e9fc commit d710061

File tree

1 file changed

+48
-57
lines changed

1 file changed

+48
-57
lines changed

src/jwt_io.c

Lines changed: 48 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
#include <strings.h>
66
#include <jwt.h>
77

8-
install_t install(void);
8+
install_t install(void);
99

10-
static void
11-
get_pl_arg_str(char *predicate_name, char *term_name, term_t term, char **out)
12-
{
10+
static void get_pl_arg_str(char *predicate_name, char *term_name, term_t term, char **out) {
1311
if (!PL_get_atom_chars(term, out)) {
1412
char *warning;
1513
asprintf(&warning, "%s: instantiation fault (%s)", predicate_name, term_name);
@@ -18,31 +16,28 @@ get_pl_arg_str(char *predicate_name, char *term_name, term_t term, char **out)
1816
}
1917
}
2018

21-
static foreign_t
22-
pl_jwt_encode(term_t in, term_t out, term_t key_term, term_t algorithm)
23-
{
24-
jwt_t *jwt;
25-
char *result, *grants, *alg_str, *key;
26-
int rval;
19+
static foreign_t pl_jwt_encode(term_t in, term_t out, term_t key_term, term_t algorithm) {
20+
jwt_t *jwt;
21+
char *result, *grants, *alg_str, *key;
22+
int rval;
2723

28-
get_pl_arg_str("jwt_encode_from_string/4", "in", in, &grants);
29-
get_pl_arg_str("jwt_encode_from_string/4", "key", key_term, &key);
30-
get_pl_arg_str("jwt_encode_from_string/4", "algorithm", algorithm, &alg_str);
31-
jwt_new(&jwt);
32-
jwt_add_grants_json(jwt, grants);
33-
jwt_set_alg(jwt, jwt_str_alg(alg_str), (const unsigned char *)key, strlen(key));
34-
result = jwt_encode_str(jwt);
35-
rval = PL_unify_atom_chars(out, result);
36-
free(result);
37-
jwt_free(jwt);
38-
return rval;
24+
get_pl_arg_str("jwt_encode_from_string/4", "in", in, &grants);
25+
get_pl_arg_str("jwt_encode_from_string/4", "key", key_term, &key);
26+
get_pl_arg_str("jwt_encode_from_string/4", "algorithm", algorithm, &alg_str);
27+
jwt_new(&jwt);
28+
jwt_add_grants_json(jwt, grants);
29+
jwt_set_alg(jwt, jwt_str_alg(alg_str), (const unsigned char *)key, strlen(key));
30+
result = jwt_encode_str(jwt);
31+
rval = PL_unify_atom_chars(out, result);
32+
free(result);
33+
jwt_free(jwt);
34+
return rval;
3935
}
4036

41-
static foreign_t
42-
pl_jwt_parse_head(term_t in, term_t head_term) {
43-
char *input, *head_payload;
44-
jwt_t *jwt;
45-
int jwt_result;
37+
static foreign_t pl_jwt_parse_head(term_t in, term_t head_term) {
38+
char *input, *head_payload;
39+
jwt_t *jwt;
40+
int jwt_result;
4641
get_pl_arg_str("jwt_encode_from_string/4", "in", in, &input);
4742

4843
jwt_result = jwt_decode(&jwt, input, NULL, 0);
@@ -57,38 +52,34 @@ pl_jwt_parse_head(term_t in, term_t head_term) {
5752
}
5853
}
5954

60-
static foreign_t
61-
pl_jwt_decode(term_t in, term_t out_payload, term_t out_algorithm, term_t in_key)
62-
{
63-
char *input, *key, *payload;
64-
const char *algorithm;
65-
int jwt_result;
66-
jwt_t *jwt;
55+
static foreign_t pl_jwt_decode(term_t in, term_t out_payload, term_t out_algorithm, term_t in_key) {
56+
char *input, *key, *payload;
57+
const char *algorithm;
58+
int jwt_result;
59+
jwt_t *jwt;
6760

68-
get_pl_arg_str("jwt_encode_from_string/4", "in", in, &input);
69-
get_pl_arg_str("jwt_encode_from_string/4", "key", in_key, &key);
70-
if (key == NULL || !strcmp("", key)) {
71-
jwt_result = jwt_decode(&jwt, input, NULL, 0);
72-
} else {
73-
jwt_result = jwt_decode(&jwt, input, (const unsigned char *)key, strlen(key));
74-
}
75-
if (!jwt_result) {
76-
payload = jwt_get_grants_json(jwt, NULL);
77-
algorithm = jwt_alg_str(jwt_get_alg(jwt));
78-
(void) PL_unify_atom_chars(out_payload, payload);
79-
(void) PL_unify_atom_chars(out_algorithm, algorithm);
80-
free(payload);
81-
jwt_free(jwt);
82-
PL_succeed;
83-
} else {
84-
PL_fail;
85-
}
61+
get_pl_arg_str("jwt_encode_from_string/4", "in", in, &input);
62+
get_pl_arg_str("jwt_encode_from_string/4", "key", in_key, &key);
63+
if (key == NULL || !strcmp("", key)) {
64+
jwt_result = jwt_decode(&jwt, input, NULL, 0);
65+
} else {
66+
jwt_result = jwt_decode(&jwt, input, (const unsigned char *)key, strlen(key));
67+
}
68+
if (!jwt_result) {
69+
payload = jwt_get_grants_json(jwt, NULL);
70+
algorithm = jwt_alg_str(jwt_get_alg(jwt));
71+
(void) PL_unify_atom_chars(out_payload, payload);
72+
(void) PL_unify_atom_chars(out_algorithm, algorithm);
73+
free(payload);
74+
jwt_free(jwt);
75+
PL_succeed;
76+
} else {
77+
PL_fail;
78+
}
8679
}
8780

88-
install_t
89-
install(void)
90-
{
91-
PL_register_foreign("jwt_parse_head", 2, pl_jwt_parse_head, 0);
92-
PL_register_foreign("jwt_encode_from_string", 4, pl_jwt_encode, 0);
93-
PL_register_foreign("jwt_decode_from_string", 4, pl_jwt_decode, 0);
81+
install_t install(void) {
82+
PL_register_foreign("jwt_parse_head", 2, pl_jwt_parse_head, 0);
83+
PL_register_foreign("jwt_encode_from_string", 4, pl_jwt_encode, 0);
84+
PL_register_foreign("jwt_decode_from_string", 4, pl_jwt_decode, 0);
9485
}

0 commit comments

Comments
 (0)