aboutsummaryrefslogtreecommitdiffstats
path: root/lib/oauth.h
blob: 50adc95c42a0429175ea7034a4e8849618295688 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/***************************************************************************\
*                                                                           *
*  BitlBee - An IRC to IM gateway                                           *
*  Simple OAuth client (consumer) implementation.                           *
*                                                                           *
*  Copyright 2010 Wilmer van der Gaast <wilmer@gaast.net>                   *
*                                                                           *
*  This program is free software; you can redistribute it and/or modify     *
*  it under the terms of the GNU General Public License as published by     *
*  the Free Software Foundation; either version 2 of the License, or        *
*  (at your option) any later version.                                      *
*                                                                           *
*  This program is distributed in the hope that it will be useful,          *
*  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
*  GNU General Public License for more details.                             *
*                                                                           *
*  You should have received a copy of the GNU General Public License along  *
*  with this program; if not, write to the Free Software Foundation, Inc.,  *
*  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.              *
*                                                                           *
\***************************************************************************/

/* http://oauth.net/core/1.0a/ */

struct oauth_info;

/* Callback function called twice during the access token request process.
   Return FALSE if something broke and the process must be aborted. */
typedef gboolean (*oauth_cb)( struct oauth_info * );

typedef enum
{
	OAUTH_INIT,
	OAUTH_REQUEST_TOKEN,
	OAUTH_ACCESS_TOKEN,
} oauth_stage_t;

struct oauth_info
{
	oauth_stage_t stage;
	const struct oauth_service *sp;
	
	oauth_cb func;
	void *data;
	
	struct http_request *http;
	
	char *auth_url;
	char *request_token;
	
	char *token;
	char *token_secret;
	GSList *params;
};

struct oauth_service
{
	char *url_request_token;
	char *url_access_token;
	char *url_authorize;
	
	char *consumer_key;
	char *consumer_secret;
};

/* http://oauth.net/core/1.0a/#auth_step1 (section 6.1) 
   Request an initial anonymous token which can be used to construct an
   authorization URL for the user. This is passed to the callback function
   in a struct oauth_info. */
struct oauth_info *oauth_request_token( const struct oauth_service *sp, oauth_cb func, void *data );

/* http://oauth.net/core/1.0a/#auth_step3 (section 6.3)
   The user gets a PIN or so which we now exchange for the final access
   token. This is passed to the callback function in the same
   struct oauth_info. */
gboolean oauth_access_token( const char *pin, struct oauth_info *st );

/* http://oauth.net/core/1.0a/#anchor12 (section 7)
   Generate an OAuth Authorization: HTTP header. access_token should be
   saved/fetched using the functions above. args can be a string with
   whatever's going to be in the POST body of the request. GET args will
   automatically be grabbed from url. */
char *oauth_http_header( struct oauth_info *oi, const char *method, const char *url, char *args );

/* Shouldn't normally be required unless the process is aborted by the user. */
void oauth_info_free( struct oauth_info *info );

/* Convert to and back from strings, for easier saving. */
char *oauth_to_string( struct oauth_info *oi );
struct oauth_info *oauth_from_string( char *in, const struct oauth_service *sp );

/* For reading misc. data. */
void oauth_params_add( GSList **params, const char *key, const char *value );
void oauth_params_parse( GSList **params, char *in );
void oauth_params_free( GSList **params );
char *oauth_params_string( GSList *params );
void oauth_params_set( GSList **params, const char *key, const char *value );
const char *oauth_params_get( GSList **params, const char *key );
class="nt">> * _b_</xsl:text><xsl:value-of select="@name"/><xsl:text>_b_ - </xsl:text><xsl:value-of select="short-description"/><xsl:text>&#10;</xsl:text> </xsl:for-each> <xsl:text>&#10;</xsl:text> </xsl:template> <xsl:template match="preface|chapter|sect1|sect2"> <xsl:call-template name="subject"> <xsl:with-param name="id" select="@id"/> </xsl:call-template> </xsl:template> <xsl:template match="emphasis"> <xsl:text>_b_</xsl:text> <xsl:apply-templates/> <xsl:text>_b_</xsl:text> </xsl:template> <xsl:template match="book"> <xsl:apply-templates/> </xsl:template> <xsl:template match="variablelist"> <xsl:for-each select="varlistentry"> <xsl:text> _b_</xsl:text><xsl:value-of select="term"/><xsl:text>_b_ - </xsl:text><xsl:value-of select="listitem/para"/><xsl:text>&#10;</xsl:text> </xsl:for-each> <xsl:text>&#10;</xsl:text> </xsl:template> <xsl:template match="simplelist"> <xsl:for-each select="member"> <xsl:text> - </xsl:text><xsl:apply-templates/><xsl:text>&#10;</xsl:text> </xsl:for-each> <xsl:text>&#10;</xsl:text> </xsl:template> <xsl:template match="ircline"> <xsl:text>_b_&lt;</xsl:text><xsl:value-of select="@nick"/><xsl:text>&gt;_b_ </xsl:text><xsl:value-of select="."/><xsl:text>&#10;</xsl:text> </xsl:template> <xsl:template match="ircaction"> <xsl:text>_b_* </xsl:text><xsl:value-of select="@nick"/><xsl:text>_b_ </xsl:text><xsl:value-of select="."/><xsl:text>&#10;</xsl:text> </xsl:template> <xsl:template match="ircexample"> <xsl:apply-templates/> <xsl:text>&#10;</xsl:text> </xsl:template> <xsl:template name="cmd"> <xsl:param name="prefix"/> <xsl:variable name="thiscmd"><xsl:value-of select="$prefix"/><xsl:value-of select="@name"/></xsl:variable> <xsl:message><xsl:text>Processing command '</xsl:text><xsl:value-of select="$thiscmd"/><xsl:text>'</xsl:text></xsl:message> <xsl:text>?</xsl:text><xsl:value-of select="$thiscmd"/><xsl:text>&#10;</xsl:text> <xsl:for-each select="syntax"> <xsl:text>_b_Syntax:_b_ </xsl:text><xsl:value-of select="."/><xsl:text>&#10;</xsl:text> </xsl:for-each> <xsl:text>&#10;</xsl:text> <xsl:apply-templates select="description"/> <xsl:for-each select="ircexample"> <xsl:text>_b_Example:_b_&#10;</xsl:text> <xsl:apply-templates select="."/> </xsl:for-each> <!-- <xsl:if test="bitlbee-command != ''"> <xsl:text>Subcommands: </xsl:text> <xsl:for-each select="bitlbee-command"> <xsl:value-of select="@name"/><xsl:text>, </xsl:text> </xsl:for-each> <xsl:text>&#10;</xsl:text> </xsl:if> --> <xsl:text>%&#10;</xsl:text> <xsl:for-each select="bitlbee-command"> <xsl:call-template name="cmd"> <xsl:with-param name="prefix"><xsl:value-of select="$thiscmd"/><xsl:text> </xsl:text></xsl:with-param> </xsl:call-template> </xsl:for-each> </xsl:template> </xsl:stylesheet>