1 #include "system.h"
2 #include "lj.h"
3 #include "hash.h"
4 #include "util.h"
5 #include "net.h"
6
7 #include <stdlib.h>
8 #include <string.h>
9
10 /*****************************************************************************
11 * This function generates the body of the HTTP request, we make the headers in
12 * lj_challenge. This is mostly done so that we can just use strlen() to calculate
13 * the Content Length.
14 */
15
16 int
lj_getchallenge(const lj_server * const serverinfo,const lj_user * const user,lj_challengeinfo * challengeinfo)17 lj_getchallenge(const lj_server * const serverinfo, const lj_user * const user, lj_challengeinfo *challengeinfo)
18 {
19 int ret = 0;
20 hashtable *lj_hash = NULL;
21 char *value = NULL;
22
23 /* First we send our request */
24 create_hash(&lj_hash);
25 lj_send_request(serverinfo, user, "mode=getchallenge", lj_hash);
26
27 /* were we a success? */
28 challengeinfo->success = 1;
29 get(lj_hash, &value, "success");
30 if (!value || strcmp(value, "OK"))
31 {
32 /* we failed */
33 challengeinfo->success = 0;
34 ret = 1;
35 }
36 free(value);
37
38 /* next we look for an errmsg */
39 get(lj_hash, &challengeinfo->errmsg, "errmsg");
40
41 /* now we challenge details */
42 getp(lj_hash, &challengeinfo->auth_sceme, "auth_sceme");
43 getp(lj_hash, &challengeinfo->challenge, "challenge");
44 geti(lj_hash, &challengeinfo->expire_time, "expire_time");
45 geti(lj_hash, &challengeinfo->server_time, "server_time");
46
47 lj_debug(1, "success: [%s]\n", challengeinfo->success ? "OK" : "FAIL");
48 if (challengeinfo->errmsg)
49 lj_debug(1, "errmsg: [%s]\n", challengeinfo->errmsg);
50
51 /* Then we close the connection and return our success / failure code */
52 delete_hash(lj_hash);
53 return ret;
54 }
55