X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/ddf5b0259b7246c0d3207ceb22ea72379ae64e89..2b60a54adb3b0bf5a9b927708085492b816a6015:/sbr/oauth.c diff --git a/sbr/oauth.c b/sbr/oauth.c index 3becfdef..8e3d6b05 100755 --- a/sbr/oauth.c +++ b/sbr/oauth.c @@ -24,6 +24,7 @@ #include #include +#include "lock_file.h" #define JSON_TYPE "application/json" @@ -139,7 +140,8 @@ mh_oauth_do_xoauth(const char *user, const char *svc, unsigned char **oauth_res, FILE *fp; char *client_res; - if (!mh_oauth_new (&ctx, svc)) adios(NULL, mh_oauth_get_err_string(ctx)); + if (!mh_oauth_new (&ctx, svc)) + adios(NULL, "%s", mh_oauth_get_err_string(ctx)); if (log != NULL) mh_oauth_log_to(stderr, ctx); @@ -156,7 +158,7 @@ mh_oauth_do_xoauth(const char *user, const char *svc, unsigned char **oauth_res, } if ((cred = mh_oauth_cred_load(fp, ctx, user)) == NULL) { - adios(NULL, mh_oauth_get_err_string(ctx)); + adios(NULL, "%s", mh_oauth_get_err_string(ctx)); } if (!mh_oauth_access_token_valid(time(NULL), cred)) { @@ -168,12 +170,12 @@ mh_oauth_do_xoauth(const char *user, const char *svc, unsigned char **oauth_res, adios(NULL, "credentials rejected -- run mhlogin -saslmech xoauth2 -authservice %s", svc); } inform("error refreshing OAuth2 token"); - adios(NULL, mh_oauth_get_err_string(ctx)); + adios(NULL, "%s", mh_oauth_get_err_string(ctx)); } fseek(fp, 0, SEEK_SET); if (!mh_oauth_cred_save(fp, cred, user)) { - adios(NULL, mh_oauth_get_err_string(ctx)); + adios(NULL, "%s", mh_oauth_get_err_string(ctx)); } } @@ -240,7 +242,7 @@ set_err_http(mh_oauth_ctx *ctx, const struct curl_ctx *curl_ctx) } static char * -make_user_agent() +make_user_agent(void) { const char *curl = curl_version_info(CURLVERSION_NOW)->version; return concat(user_agent, " libcurl/", curl, NULL); @@ -614,7 +616,7 @@ load_creds(struct user_creds **result, FILE *fp, mh_oauth_ctx *ctx) boolean success = FALSE; char name[NAMESZ], value_buf[BUFSIZ]; int state; - m_getfld_state_t getfld_ctx = 0; + m_getfld_state_t getfld_ctx; struct user_creds *user_creds; NEW(user_creds); @@ -622,9 +624,10 @@ load_creds(struct user_creds **result, FILE *fp, mh_oauth_ctx *ctx) user_creds->len = 0; user_creds->creds = mh_xmalloc(user_creds->alloc * sizeof *user_creds->creds); + getfld_ctx = m_getfld_state_init(fp); for (;;) { int size = sizeof value_buf; - switch (state = m_getfld(&getfld_ctx, name, value_buf, &size, fp)) { + switch (state = m_getfld2(&getfld_ctx, name, value_buf, &size)) { case FLD: case FLDPLUS: { char **save, *expire; @@ -656,7 +659,7 @@ load_creds(struct user_creds **result, FILE *fp, mh_oauth_ctx *ctx) char *tmp = getcpy(value_buf); while (state == FLDPLUS) { size = sizeof value_buf; - state = m_getfld(&getfld_ctx, name, value_buf, &size, fp); + state = m_getfld2(&getfld_ctx, name, value_buf, &size); tmp = add(value_buf, tmp); } *save = trimcpy(tmp); @@ -682,7 +685,7 @@ load_creds(struct user_creds **result, FILE *fp, mh_oauth_ctx *ctx) break; default: - /* Not adding details for LENERR/FMTERR because m_getfld already + /* Not adding details for LENERR/FMTERR because m_getfld2 already * wrote advise message to stderr. */ set_err(ctx, MH_OAUTH_CRED_FILE); break; @@ -878,7 +881,7 @@ make_query_url(char *s, size_t size, CURL *curl, const char *base_url, ...) } static int -debug_callback(const CURL *handle, curl_infotype type, const char *data, +debug_callback(CURL *handle, curl_infotype type, char *data, size_t size, void *userptr) { FILE *fp = userptr;