From 8e311c221c8cae673745481405bd698bb9d50a9e Mon Sep 17 00:00:00 2001 From: oupson Date: Tue, 2 Nov 2021 09:45:05 +0100 Subject: [PATCH] Add moving operation and fix prototype problem --- include/auth_univ_orleans/auth_univ_orleans.h | 2 +- include/auth_univ_orleans/cookie_iterator.h | 4 ++-- include/auth_univ_orleans/result.h | 5 +++-- src/cookie_iterator.c | 4 ++-- src/result.c | 10 +++++++--- src/test.c | 5 ++--- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/include/auth_univ_orleans/auth_univ_orleans.h b/include/auth_univ_orleans/auth_univ_orleans.h index 12aea38..5e1a426 100644 --- a/include/auth_univ_orleans/auth_univ_orleans.h +++ b/include/auth_univ_orleans/auth_univ_orleans.h @@ -5,6 +5,6 @@ #include #include -result_t* auth_univ_get_session_token(char *username, char *password); +result_t *auth_univ_get_session_token(char *username, char *password); int auth_univ_orleans_login(CURL *handle, char *username, char *password); #endif \ No newline at end of file diff --git a/include/auth_univ_orleans/cookie_iterator.h b/include/auth_univ_orleans/cookie_iterator.h index 6f54731..26aa543 100644 --- a/include/auth_univ_orleans/cookie_iterator.h +++ b/include/auth_univ_orleans/cookie_iterator.h @@ -31,9 +31,9 @@ char *cookie_hostname(cookie_t *cookie); bool cookie_include_subdomains(cookie_t *cookie); char *cookie_path(cookie_t *cookie); bool cookie_secure(cookie_t *cookie); -int cookie_expire(cookie_t *cookie); +long cookie_expire(cookie_t *cookie); char *cookie_name(cookie_t *cookie); char *cookie_value(cookie_t *cookie); void cookie_free(cookie_t *cookie); -#endif \ No newline at end of file +#endif diff --git a/include/auth_univ_orleans/result.h b/include/auth_univ_orleans/result.h index 75b0a1d..4d32b4f 100644 --- a/include/auth_univ_orleans/result.h +++ b/include/auth_univ_orleans/result.h @@ -1,6 +1,7 @@ #ifndef ERROR_H #define ERROR_H +#include "auth_univ_orleans/cookie_iterator.h" typedef struct result result_t; #include @@ -20,9 +21,9 @@ struct result { union inner_result inner; }; - enum result_type get_result_type(result_t *result); cookie_iterator_t *get_result_ok(result_t *result); +cookie_iterator_t *move_result_ok(result_t *result); const char *get_result_err(result_t *result); void result_free(result_t *result); -#endif \ No newline at end of file +#endif diff --git a/src/cookie_iterator.c b/src/cookie_iterator.c index eee50da..787aecd 100644 --- a/src/cookie_iterator.c +++ b/src/cookie_iterator.c @@ -144,8 +144,8 @@ bool cookie_include_subdomains(cookie_t *cookie) { } char *cookie_path(cookie_t *cookie) { return cookie->path; } bool cookie_secure(cookie_t *cookie) { return cookie->secure; } -int cookie_expire(cookie_t *cookie) { return cookie->expire; } +long cookie_expire(cookie_t *cookie) { return cookie->expire; } char *cookie_name(cookie_t *cookie) { return cookie->name; } char *cookie_value(cookie_t *cookie) { return cookie->value; } -void cookie_free(cookie_t *cookie) { free(cookie); } \ No newline at end of file +void cookie_free(cookie_t *cookie) { free(cookie); } diff --git a/src/result.c b/src/result.c index 2772640..6fde217 100644 --- a/src/result.c +++ b/src/result.c @@ -6,10 +6,14 @@ enum result_type get_result_type(result_t *result) { return result->type; } cookie_iterator_t *get_result_ok(result_t *result) { return result->inner.ok; } -const char *get_result_err(result_t *result) { - return result->inner.error; +cookie_iterator_t *move_result_ok(result_t *result) { + cookie_iterator_t *res = result->inner.ok; + result->inner.ok = NULL; + return res; } +const char *get_result_err(result_t *result) { return result->inner.error; } + void result_free(result_t *result) { if (result->type == OK) { if (result->inner.ok != NULL) { @@ -21,4 +25,4 @@ void result_free(result_t *result) { result->inner.error = NULL; } free(result); -} \ No newline at end of file +} diff --git a/src/test.c b/src/test.c index 55f46b3..011a20b 100644 --- a/src/test.c +++ b/src/test.c @@ -24,7 +24,7 @@ int main(void) { "\tinclude subdomains : %d\n" "\tpath : %s\n" "\tsecure : %d\n" - "\texpire : %d\n" + "\texpire : %ld\n" "\tvalue: %s\n", cookie_name(cookie), cookie_hostname(cookie), cookie_include_subdomains(cookie), cookie_path(cookie), @@ -32,10 +32,9 @@ int main(void) { cookie_value(cookie)); } - } else { fprintf(stderr, "error : %s\n", get_result_err(res)); } result_free(res); -} \ No newline at end of file +}