source: lib/oauth.h @ ad54149

Last change on this file since ad54149 was 5ebff60, checked in by dequis <dx@…>, at 2015-02-20T22:50:54Z

Reindent everything to K&R style with tabs

Used uncrustify, with the configuration file in ./doc/uncrustify.cfg

Commit author set to "Indent <please@…>" so that it's easier to
skip while doing git blame.

  • Property mode set to 100644
File size: 4.1 KB
RevLine 
[be28fe7]1/***************************************************************************\
2*                                                                           *
3*  BitlBee - An IRC to IM gateway                                           *
4*  Simple OAuth client (consumer) implementation.                           *
5*                                                                           *
6*  Copyright 2010 Wilmer van der Gaast <wilmer@gaast.net>                   *
7*                                                                           *
8*  This program is free software; you can redistribute it and/or modify     *
9*  it under the terms of the GNU General Public License as published by     *
10*  the Free Software Foundation; either version 2 of the License, or        *
11*  (at your option) any later version.                                      *
12*                                                                           *
13*  This program is distributed in the hope that it will be useful,          *
14*  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
15*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
16*  GNU General Public License for more details.                             *
17*                                                                           *
18*  You should have received a copy of the GNU General Public License along  *
19*  with this program; if not, write to the Free Software Foundation, Inc.,  *
20*  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.              *
21*                                                                           *
22\***************************************************************************/
[508c340]23
[acba168]24/* http://oauth.net/core/1.0a/ */
25
26struct oauth_info;
[18dbb20]27
28/* Callback function called twice during the access token request process.
29   Return FALSE if something broke and the process must be aborted. */
[5ebff60]30typedef gboolean (*oauth_cb)(struct oauth_info *);
[acba168]31
[5ebff60]32typedef enum {
[c42e8b9]33        OAUTH_INIT,
34        OAUTH_REQUEST_TOKEN,
35        OAUTH_ACCESS_TOKEN,
36} oauth_stage_t;
37
[5ebff60]38struct oauth_info {
[c42e8b9]39        oauth_stage_t stage;
[3b878a1]40        const struct oauth_service *sp;
[5ebff60]41
[acba168]42        oauth_cb func;
43        void *data;
[5ebff60]44
[acba168]45        struct http_request *http;
[5ebff60]46
[c2ecadc]47        char *auth_url;
[713d611]48        char *request_token;
[5ebff60]49
[c2ecadc]50        char *token;
51        char *token_secret;
[93cc86f]52        GSList *params;
[c2ecadc]53};
54
[5ebff60]55struct oauth_service {
[c2ecadc]56        char *url_request_token;
57        char *url_access_token;
58        char *url_authorize;
[5ebff60]59
[c2ecadc]60        char *consumer_key;
61        char *consumer_secret;
[acba168]62};
63
[5ebff60]64/* http://oauth.net/core/1.0a/#auth_step1 (section 6.1)
[acba168]65   Request an initial anonymous token which can be used to construct an
66   authorization URL for the user. This is passed to the callback function
67   in a struct oauth_info. */
[5ebff60]68struct oauth_info *oauth_request_token(const struct oauth_service *sp, oauth_cb func, void *data);
[acba168]69
70/* http://oauth.net/core/1.0a/#auth_step3 (section 6.3)
71   The user gets a PIN or so which we now exchange for the final access
72   token. This is passed to the callback function in the same
73   struct oauth_info. */
[5ebff60]74gboolean oauth_access_token(const char *pin, struct oauth_info *st);
[acba168]75
76/* http://oauth.net/core/1.0a/#anchor12 (section 7)
77   Generate an OAuth Authorization: HTTP header. access_token should be
78   saved/fetched using the functions above. args can be a string with
79   whatever's going to be in the POST body of the request. GET args will
80   automatically be grabbed from url. */
[5ebff60]81char *oauth_http_header(struct oauth_info *oi, const char *method, const char *url, char *args);
[18dbb20]82
83/* Shouldn't normally be required unless the process is aborted by the user. */
[5ebff60]84void oauth_info_free(struct oauth_info *info);
[f4b0911]85
86/* Convert to and back from strings, for easier saving. */
[5ebff60]87char *oauth_to_string(struct oauth_info *oi);
88struct oauth_info *oauth_from_string(char *in, const struct oauth_service *sp);
[93cc86f]89
90/* For reading misc. data. */
[5ebff60]91void oauth_params_add(GSList **params, const char *key, const char *value);
92void oauth_params_parse(GSList **params, char *in);
93void oauth_params_free(GSList **params);
94char *oauth_params_string(GSList *params);
95void oauth_params_set(GSList **params, const char *key, const char *value);
96const char *oauth_params_get(GSList **params, const char *key);
Note: See TracBrowser for help on using the repository browser.