3 * Purple is the legal property of its developers, whose names are too numerous
4 * to list here. Please refer to the COPYRIGHT file distributed with this
7 * Code adapted from libgadu (C) 2008 Wojtek Kaniewski <wojtekka@irc.pl>
8 * (http://toxygen.net/libgadu/) during Google Summer of Code 2012
9 * by Tomek Wasilczyk (http://www.wasilczyk.pl).
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
26 #include "oauth-parameter.h"
28 struct gg_oauth_parameter
{
31 struct gg_oauth_parameter
*next
;
34 int gg_oauth_parameter_set(gg_oauth_parameter_t
**list
, const char *key
, const char *value
)
36 gg_oauth_parameter_t
*p
, *new_p
;
46 new_key
= g_strdup(key
);
51 new_value
= g_strdup(value
);
53 if (new_value
== NULL
) {
58 new_p
= g_new0(gg_oauth_parameter_t
, 1);
66 memset(new_p
, 0, sizeof(gg_oauth_parameter_t
));
68 new_p
->value
= new_value
;
73 while (p
!= NULL
&& p
->next
!= NULL
)
84 char *gg_oauth_parameter_join(gg_oauth_parameter_t
*list
, int header
)
86 gg_oauth_parameter_t
*p
;
91 len
+= strlen("OAuth ");
93 for (p
= list
; p
; p
= p
->next
) {
95 len
+= strlen(p
->key
);
97 len
+= (header
) ? 3 : 1;
99 escaped
= g_uri_escape_string(p
->value
, NULL
, FALSE
);
100 len
+= strlen(escaped
);
107 res
= g_malloc(len
+ 1);
117 strcpy(out
, "OAuth ");
121 for (p
= list
; p
; p
= p
->next
) {
124 out
+= strlen(p
->key
);
131 escaped
= g_uri_escape_string(p
->value
, NULL
, FALSE
);
132 strcpy(out
, escaped
);
133 out
+= strlen(escaped
);
140 strcpy(out
++, (header
) ? "," : "&");
146 void gg_oauth_parameter_free(gg_oauth_parameter_t
*list
)
148 while (list
!= NULL
) {
149 gg_oauth_parameter_t
*next
;