libpurple/protocols/gg/oauth/oauth.c

Sat, 15 Jun 2013 14:28:31 +0530

author
Ankit Vani <a@nevitus.org>
date
Sat, 15 Jun 2013 14:28:31 +0530
branch
soc.2013.gobjectification
changeset 34556
087db73b115d
parent 33909
773899cbd05a
child 34567
ea5103f66b0e
permissions
-rw-r--r--

Refactored protocols bonjour, gg, jabber to use the GObject-based PurpleCipher

33349
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
1 /* purple
33329
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
2 *
33349
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
3 * Purple is the legal property of its developers, whose names are too numerous
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
4 * to list here. Please refer to the COPYRIGHT file distributed with this
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
5 * source distribution.
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
6 *
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
7 * Code adapted from libgadu (C) 2008 Wojtek Kaniewski <wojtekka@irc.pl>
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
8 * (http://toxygen.net/libgadu/) during Google Summer of Code 2012
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
9 * by Tomek Wasilczyk (http://www.wasilczyk.pl).
33329
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
10 *
33349
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
11 * This program is free software; you can redistribute it and/or modify
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
12 * it under the terms of the GNU General Public License as published by
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
13 * the Free Software Foundation; either version 2 of the License, or
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
14 * (at your option) any later version.
33329
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
15 *
33349
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
16 * This program is distributed in the hope that it will be useful,
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
19 * GNU General Public License for more details.
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
20 *
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
21 * You should have received a copy of the GNU General Public License
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
22 * along with this program; if not, write to the Free Software
d4a017428f4d Gadu-Gadu: missing copyright notes
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33346
diff changeset
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
33329
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
24 */
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
25
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
26 #include "oauth.h"
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
27
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
28 #include "oauth-parameter.h"
34556
087db73b115d Refactored protocols bonjour, gg, jabber to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents: 33909
diff changeset
29 #include "ciphers/hmac.h"
087db73b115d Refactored protocols bonjour, gg, jabber to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents: 33909
diff changeset
30 #include "ciphers/sha1.h"
33329
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
31
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
32 char *gg_oauth_static_nonce; /* dla unit testów */
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
33 char *gg_oauth_static_timestamp; /* dla unit testów */
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
34
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
35 static void gg_oauth_generate_nonce(char *buf, int len)
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
36 {
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
37 const char charset[] = "0123456789";
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
38
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
39 if (buf == NULL || len < 1)
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
40 return;
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
41
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
42 while (len > 1) {
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
43 *buf++ = charset[(unsigned) (((float) sizeof(charset) - 1.0) * rand() / (RAND_MAX + 1.0))];
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
44 len--;
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
45 }
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
46
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
47 *buf = 0;
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
48 }
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
49
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
50 static gchar *gg_hmac_sha1(const char *key, const char *message)
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
51 {
34556
087db73b115d Refactored protocols bonjour, gg, jabber to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents: 33909
diff changeset
52 PurpleCipher *cipher, *hash;
33329
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
53 guchar digest[20];
34556
087db73b115d Refactored protocols bonjour, gg, jabber to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents: 33909
diff changeset
54
087db73b115d Refactored protocols bonjour, gg, jabber to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents: 33909
diff changeset
55 hash = purple_sha1_cipher_new();
087db73b115d Refactored protocols bonjour, gg, jabber to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents: 33909
diff changeset
56 cipher = purple_hmac_cipher_new(hash);
087db73b115d Refactored protocols bonjour, gg, jabber to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents: 33909
diff changeset
57
087db73b115d Refactored protocols bonjour, gg, jabber to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents: 33909
diff changeset
58 purple_cipher_set_key(cipher, (guchar *)key, strlen(key));
087db73b115d Refactored protocols bonjour, gg, jabber to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents: 33909
diff changeset
59 purple_cipher_append(cipher, (guchar *)message, strlen(message));
087db73b115d Refactored protocols bonjour, gg, jabber to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents: 33909
diff changeset
60 purple_cipher_digest(cipher, digest, sizeof(digest));
087db73b115d Refactored protocols bonjour, gg, jabber to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents: 33909
diff changeset
61
087db73b115d Refactored protocols bonjour, gg, jabber to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents: 33909
diff changeset
62 g_object_unref(cipher);
087db73b115d Refactored protocols bonjour, gg, jabber to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents: 33909
diff changeset
63 g_object_unref(hash);
33329
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
64
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
65 return purple_base64_encode(digest, sizeof(digest));
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
66 }
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
67
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
68 static char *gg_oauth_generate_signature(const char *method, const char *url, const char *request, const char *consumer_secret, const char *token_secret)
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
69 {
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
70 char *text, *key, *res;
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
71 gchar *url_e, *request_e, *consumer_secret_e, *token_secret_e;
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
72
33346
3b4cbb0e10d6 Gadu-Gadu: public directory search with gg10.5 api
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33343
diff changeset
73 url_e = g_uri_escape_string(url, "?", FALSE);
3b4cbb0e10d6 Gadu-Gadu: public directory search with gg10.5 api
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33343
diff changeset
74 g_strdelimit(url_e, "?", '\0');
33329
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
75 request_e = g_uri_escape_string(request, NULL, FALSE);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
76 text = g_strdup_printf("%s&%s&%s", method, url_e, request_e);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
77 g_free(url_e);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
78 g_free(request_e);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
79
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
80 consumer_secret_e = g_uri_escape_string(consumer_secret, NULL, FALSE);
33343
09f740724036 Gadu-Gadu: extended OAuth support, initial support for gg10.5 public directory
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33329
diff changeset
81 token_secret_e = token_secret ? g_uri_escape_string(token_secret, NULL, FALSE) : NULL;
09f740724036 Gadu-Gadu: extended OAuth support, initial support for gg10.5 public directory
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33329
diff changeset
82 key = g_strdup_printf("%s&%s", consumer_secret_e, token_secret ? token_secret_e : "");
33329
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
83 g_free(consumer_secret_e);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
84 g_free(token_secret_e);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
85
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
86 res = gg_hmac_sha1(key, text);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
87
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
88 free(key);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
89 free(text);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
90
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
91 return res;
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
92 }
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
93
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
94 char *gg_oauth_generate_header(const char *method, const char *url, const const char *consumer_key, const char *consumer_secret, const char *token, const char *token_secret)
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
95 {
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
96 char *request, *signature, *res;
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
97 char nonce[80], timestamp[16];
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
98 gg_oauth_parameter_t *params = NULL;
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
99
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
100 if (gg_oauth_static_nonce == NULL)
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
101 gg_oauth_generate_nonce(nonce, sizeof(nonce));
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
102 else {
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
103 strncpy(nonce, gg_oauth_static_nonce, sizeof(nonce) - 1);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
104 nonce[sizeof(nonce) - 1] = 0;
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
105 }
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
106
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
107 if (gg_oauth_static_timestamp == NULL)
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
108 snprintf(timestamp, sizeof(timestamp), "%ld", time(NULL));
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
109 else {
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
110 strncpy(timestamp, gg_oauth_static_timestamp, sizeof(timestamp) - 1);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
111 timestamp[sizeof(timestamp) - 1] = 0;
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
112 }
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
113
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
114 gg_oauth_parameter_set(&params, "oauth_consumer_key", consumer_key);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
115 gg_oauth_parameter_set(&params, "oauth_nonce", nonce);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
116 gg_oauth_parameter_set(&params, "oauth_signature_method", "HMAC-SHA1");
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
117 gg_oauth_parameter_set(&params, "oauth_timestamp", timestamp);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
118 gg_oauth_parameter_set(&params, "oauth_token", token);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
119 gg_oauth_parameter_set(&params, "oauth_version", "1.0");
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
120
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
121 request = gg_oauth_parameter_join(params, 0);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
122
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
123 signature = gg_oauth_generate_signature(method, url, request, consumer_secret, token_secret);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
124
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
125 free(request);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
126
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
127 gg_oauth_parameter_free(params);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
128 params = NULL;
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
129
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
130 if (signature == NULL)
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
131 return NULL;
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
132
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
133 gg_oauth_parameter_set(&params, "oauth_version", "1.0");
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
134 gg_oauth_parameter_set(&params, "oauth_nonce", nonce);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
135 gg_oauth_parameter_set(&params, "oauth_timestamp", timestamp);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
136 gg_oauth_parameter_set(&params, "oauth_consumer_key", consumer_key);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
137 gg_oauth_parameter_set(&params, "oauth_token", token);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
138 gg_oauth_parameter_set(&params, "oauth_signature_method", "HMAC-SHA1");
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
139 gg_oauth_parameter_set(&params, "oauth_signature", signature);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
140
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
141 free(signature);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
142
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
143 res = gg_oauth_parameter_join(params, 1);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
144
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
145 gg_oauth_parameter_free(params);
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
146
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
147 return res;
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
148 }
cf23e0f1861a Gadu-Gadu: OAuth support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
149

mercurial