Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/oauth2.c

    r1a81c83 r5535a47  
    4242#include "oauth2.h"
    4343#include "oauth.h"
    44 #include "parson.h"
     44#include "json.h"
     45#include "json_util.h"
    4546#include "url.h"
    46 
    47 #define JSON_O_FOREACH(o, k, v) \
    48     const char *k; const JSON_Value *v; int __i; \
    49     for (__i = 0; json_object_get_tuple(o, __i, &k, &v); __i++)
    5047
    5148char *oauth2_url(const struct oauth2_service *sp)
     
    116113}
    117114
    118 static char* oauth2_parse_error(const JSON_Value *e)
     115static char* oauth2_parse_error(json_value *e)
    119116{
    120117        /* This does a reasonable job with some of the flavours of error
    121118           responses I've seen. Because apparently it's not standardised. */
    122119
    123         if (json_type(e) == JSONObject) {
     120        if (e->type == json_object) {
    124121                /* Facebook style */
    125                 const char *msg = json_object_get_string(json_object(e), "message");
    126                 const char *type = json_object_get_string(json_object(e), "type");
    127                 JSON_Value *code_o = json_object_get_value(json_object(e), "code");
    128                 int code = json_value_get_integer(code_o);
     122                const char *msg = json_o_str(e, "message");
     123                const char *type = json_o_str(e, "type");
     124                json_value *code_o = json_o_get(e, "code");
     125                int code = 0;
     126
     127                if (code_o && code_o->type == json_integer) {
     128                        code = code_o->u.integer;
     129                }
     130
    129131                return g_strdup_printf("Error %d: %s", code, msg ? msg : type ? type : "Unknown error");
    130         } else if (json_type(e) == JSONString) {
    131                 return g_strdup(json_string(e));
     132        } else if (e->type == json_string) {
     133                return g_strdup(e->u.string.ptr);
    132134        }
    133135        return NULL;
     
    138140        struct oauth2_access_token_data *cb_data = req->data;
    139141        char *atoken = NULL, *rtoken = NULL, *error = NULL;
    140         char *content_type;
     142        char *content_type = NULL;
    141143
    142         if (getenv("BITLBEE_DEBUG") && req->reply_body) {
     144        if (req->status_code <= 0 && !req->reply_body) {
     145                cb_data->func(cb_data->data, NULL, NULL, req->status_string);
     146                g_free(cb_data);
     147                return;
     148        }
     149
     150        if (getenv("BITLBEE_DEBUG")) {
    143151                printf("%s\n", req->reply_body);
    144152        }
     
    148156        if (content_type && (strstr(content_type, "application/json") ||
    149157                             strstr(content_type, "text/javascript"))) {
    150                 JSON_Value *js = json_parse_string(req->reply_body);
    151                 if (js && json_type(js) == JSONObject) {
    152                         JSON_O_FOREACH(json_object(js), k, v){
     158                json_value *js = json_parse(req->reply_body, req->body_size);
     159                if (js && js->type == json_object) {
     160                        JSON_O_FOREACH(js, k, v){
    153161                                if (strcmp(k, "error") == 0) {
    154162                                        error = oauth2_parse_error(v);
    155163                                }
    156                                 if (json_type(v) != JSONString) {
     164                                if (v->type != json_string) {
    157165                                        continue;
    158166                                }
    159167                                if (strcmp(k, "access_token") == 0) {
    160                                         atoken = g_strdup(json_string(v));
     168                                        atoken = g_strdup(v->u.string.ptr);
    161169                                }
    162170                                if (strcmp(k, "refresh_token") == 0) {
    163                                         rtoken = g_strdup(json_string(v));
     171                                        rtoken = g_strdup(v->u.string.ptr);
    164172                                }
    165173                        }
Note: See TracChangeset for help on using the changeset viewer.