public
Description: Library to access lastfm via it's 2.0 api
Homepage: https://launchpad.net/liblastfm
Clone URL: git://github.com/LCID-Fire/liblastfm.git
Click here to lend your support to: liblastfm and make a donation at www.pledgie.com !
liblastfm / authentication.c
100644 68 lines (57 sloc) 1.563 kb
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
#include "include.h"
#include "communication.h"
#include "authentication.h"
#define TOKEN_NOT_GRANTED 8
 
const lfmmethod authentication_method_declarations[] =
{
//method name type parameter optional parameter specific errors
{"auth.getToken", GET_METHOD, {}, {}, {{TOKEN_NOT_GRANTED, "There was an error granting the request token. Please try again later."},{0, NULL}}}
};
 
//enum has to be index of declarations
//changing this will break other code!
enum authentication_methods
{
get_token
};
 
static const lfmget primary_methods[] =
{
{&authentication_method_declarations[get_token], {"token"}, DATA_UTF8}
};
 
enum primary_info
{
AUTHENTICATION_GET_TOKEN
};
 
void authentication_get_token(utf8_callback callback, gpointer user_data)
{
call_method_with_parameters(&primary_methods[AUTHENTICATION_GET_TOKEN], callback, user_data, NULL);
}
 
gchar* s_authentication_get_token(GError** error)
{
struct utf8_syncer syncer;
syncer.string = NULL;
syncer.error = NULL;
syncer.signal = g_cond_new();
authentication_get_token(utf8_sync, &syncer);
GMutex* mutex = g_mutex_new();
g_cond_wait(syncer.signal, mutex);
g_mutex_free(mutex);
if(syncer.error)
{
*error = syncer.error;
return NULL;
}
return syncer.string;
}
 
struct authenticate_data
{
boolean_callback callback;
gpointer user_data;
};
 
void get_authtoken(const gchar* token, gpointer user_data, GError* error)
{
token_request_authorization(token);
}
 
void authenticate(gpointer user_data)
{
authentication_get_token(get_authtoken, user_data);
}