Changeset devel,469

Show
Ignore:
Timestamp:
2009-10-03T22:25:36Z (10 months ago)
Author:
Wilmer van der Gaast <wilmer@…>
branch-nick:
devel
revision id:
wilmer@gaast.net-20091003222536-cvtqv59pd9fjxuup
Message:

Cleaned up Yahoo! fix: Error handling, and also not crashing when the
connection disappears again before authentication finishes.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • devel/protocols/yahoo/libyahoo2.c

    r468 r469  
    9292 
    9393static void yahoo_process_auth_response(struct http_request *req); 
    94  
    95 /* What's this used for actually? */ 
    96 static void _yahoo_http_connected(int id, int fd, int error, void *data); 
    9794 
    9895#ifdef USE_STRUCT_CALLBACKS 
     
    15331530                        break; 
    15341531                case 65: 
     1532                        g_free(cur_group); 
    15351533                        cur_group = strdup(pair->value); 
    15361534                        break; 
     
    15511549                } 
    15521550        } 
     1551         
     1552        g_free(cur_group); 
    15531553 
    15541554        /* we could be getting multiple packets here */ 
     
    15571557 
    15581558        YAHOO_CALLBACK(ext_yahoo_got_buddies)(yd->client_id, yd->buddies); 
    1559  
    15601559 
    15611560        /*** We login at the very end of the packet communication */ 
     
    16371636                        }  
    16381637 
    1639                         // if(yd->cookie_y && yd->cookie_t && yd->cookie_c) 
    16401638                        if(yd->cookie_y && yd->cookie_t) 
    16411639                                YAHOO_CALLBACK(ext_yahoo_got_cookies)(yd->client_id); 
     
    36453643} 
    36463644 
    3647 //#define LOG(x...) printf x 
     3645/* #define LOG(x...) printf x */ 
    36483646 
    36493647static void yahoo_process_auth_response(struct http_request *req) 
     
    36563654        int is_ymsgr = 0; 
    36573655 
    3658         struct yahoo_data *yd = NULL; 
    36593656        struct yahoo_input_data *yid = req->data; 
    36603657 
    3661         unsigned char crypt_hash[25]; 
     3658        char crypt_hash[25]; 
    36623659 
    36633660        md5_byte_t result[16]; 
    36643661        md5_state_t ctx; 
    36653662 
    3666         struct yahoo_packet *packet =NULL; 
     3663        struct yahoo_packet *packet = NULL; 
     3664         
     3665        if (y_list_find(inputs, yid) == NULL) 
     3666                return; 
     3667         
     3668        if (req->status_code != 200) { 
     3669                error_code = 3000 + req->status_code; 
     3670                goto FAIL; 
     3671        } 
    36673672 
    36683673        token = req->reply_body; 
     
    36723677                *line_end = '\0'; 
    36733678 
    3674                 line_end+=2; 
    3675         } 
    3676  
    3677         error_code = atoi((char *)token); 
     3679                line_end += 2; 
     3680        } 
     3681         
     3682        if (sscanf(token, "%d", &error_code) != 1) { 
     3683                error_code = 3000; 
     3684                goto FAIL; 
     3685        } 
    36783686 
    36793687        switch(error_code) { 
    36803688                case 0: 
    36813689                        /* successful */ 
    3682                         LOG(("successful\n")); 
    3683                         break; 
     3690                        break; 
     3691 
    36843692                case 1212: 
    3685                         /* Incorrect ID or password */ 
    36863693                        LOG(("Incorrect ID or password\n")); 
    3687  
    3688                         return; 
     3694                        error_code = YAHOO_LOGIN_PASSWD; 
     3695                        goto FAIL; 
     3696 
    36893697                case 1213: 
    3690                         /* Security lock from too many failed login attempts */ 
    36913698                        LOG(("Security lock from too many failed login attempts\n")); 
    3692  
    3693                         return; 
     3699                        error_code = YAHOO_LOGIN_LOCK; 
     3700                        goto FAIL; 
    36943701 
    36953702                case 1214: 
    3696                         /* Security lock */ 
    36973703                        LOG(("Security lock\n")); 
    3698  
    3699                         return; 
     3704                        goto FAIL; 
    37003705 
    37013706                case 1235: 
    3702                         /* User ID not taken yet */ 
    37033707                        LOG(("User ID not taken yet\n")); 
    3704  
    3705                         return; 
     3708                        error_code = YAHOO_LOGIN_UNAME; 
     3709                        goto FAIL; 
    37063710 
    37073711                case 1216: 
    3708                         /* Seems to be a lock, but shows the same generic User ID/Password failure */ 
    37093712                        LOG(("Seems to be a lock, but shows the same generic User ID/Password failure\n")); 
    3710  
    3711                         return; 
    3712                 case 100: 
    3713                         /* Username and password cannot be blank */ 
    3714                         LOG(("Username and password cannot be blank\n")); 
    3715  
    3716                         return; 
     3713                        goto FAIL; 
     3714 
    37173715                default: 
    37183716                        /* Unknown error code */ 
    37193717                        LOG(("Unknown Error\n")); 
    3720  
    3721                         return; 
     3718                        goto FAIL; 
    37223719        } 
    37233720 
     
    37283725                LOG(("Oops! There was no ymsgr=. Where do I get my token from now :(")); 
    37293726                LOG(("I got this:\n\n%s\n",line_end)); 
    3730                 return; 
    3731                 /* Error */ 
     3727                error_code = 2201; 
     3728                goto FAIL; 
    37323729        } 
    37333730 
     
    37383735        if(line_end) { 
    37393736                *line_end = '\0'; 
    3740                 line_end+=2; 
     3737                line_end += 2; 
    37413738        } 
    37423739 
     
    37483745                        "https://login.yahoo.com/config/pwtoken_login?" 
    37493746                        "src=ymsgr&ts=&token=%s", token); 
    3750                  
     3747 
    37513748                http_dorequest_url(url, yahoo_process_auth_response, yid); 
     3749 
    37523750                g_free(url); 
    37533751 
     
    37613759        } 
    37623760 
    3763         cookie = strstr(req->reply_headers, "Set-Cookie: Y="); 
    3764  
    3765         if(!cookie) { 
     3761        if((cookie = strstr(req->reply_headers, "Set-Cookie: Y=")) && 
     3762           (line_end = strstr(cookie + 14, "\r\n"))) { 
     3763                *line_end = '\0'; 
     3764                yid->yd->cookie_y = strdup(cookie + 14); 
     3765                *line_end = ';'; 
     3766        } else { 
    37663767                /* Cry. */ 
    37673768                LOG(("NO Y Cookie!")); 
    3768                 return; 
    3769         } 
    3770  
    3771         cookie+=14; 
    3772  
    3773         line_end = strstr(cookie, "\r\n"); 
    3774         *line_end = '\0'; 
    3775  
    3776         LOG(("Cookie length: %d", strlen(cookie))); 
    3777  
    3778         yid->yd->cookie_y = strdup(cookie); 
    3779         *line_end = ';'; 
    3780  
    3781         cookie = strstr(req->reply_headers, "Set-Cookie: T="); 
    3782         if(!cookie) { 
     3769                error_code = 2202; 
     3770                goto FAIL; 
     3771        } 
     3772 
     3773        if((cookie = strstr(req->reply_headers, "Set-Cookie: T=")) && 
     3774           (line_end = strstr(cookie + 14, "\r\n"))) { 
     3775                *line_end = '\0'; 
     3776                yid->yd->cookie_t = strdup(cookie + 14); 
     3777                *line_end = ';'; 
     3778        } else { 
     3779                /* Cry. */ 
    37833780                LOG(("NO T Cookie!")); 
    3784                 /* Cry. */ 
    3785                 return; 
    3786         } 
    3787  
    3788         cookie+=14; 
    3789  
    3790         line_end = strstr(cookie, "\r\n"); 
    3791         *line_end = '\0'; 
    3792  
    3793         yid->yd->cookie_t = strdup(cookie); 
    3794  
    3795         LOG(("My Cookies ::\n Y: %s\nT: %s\n\n", yid->yd->cookie_y, yid->yd->cookie_t)); 
     3781                error_code = 2203; 
     3782                goto FAIL; 
     3783        } 
    37963784 
    37973785        md5_init(&ctx); 
     
    38003788        md5_finish(&ctx, result); 
    38013789 
    3802         to_y64(crypt_hash, result, 16); 
    3803  
    3804         yd = yid->yd; 
    3805  
    3806         //yid = find_input_by_id_and_type(yd->client_id, YAHOO_CONNECTION_PAGER); 
    3807  
    3808         packet = yahoo_packet_new(YAHOO_SERVICE_AUTHRESP, yd->initial_status, yd->session_id); 
    3809         yahoo_packet_hash(packet, 1, yd->user); 
    3810         yahoo_packet_hash(packet, 0, yd->user); 
    3811         yahoo_packet_hash(packet, 277, yd->cookie_y); 
    3812         yahoo_packet_hash(packet, 278, yd->cookie_t); 
     3790        to_y64((unsigned char*)crypt_hash, result, 16); 
     3791 
     3792        packet = yahoo_packet_new(YAHOO_SERVICE_AUTHRESP, yid->yd->initial_status, yid->yd->session_id); 
     3793        yahoo_packet_hash(packet, 1, yid->yd->user); 
     3794        yahoo_packet_hash(packet, 0, yid->yd->user); 
     3795        yahoo_packet_hash(packet, 277, yid->yd->cookie_y); 
     3796        yahoo_packet_hash(packet, 278, yid->yd->cookie_t); 
    38133797        yahoo_packet_hash(packet, 307, crypt_hash); 
    38143798        yahoo_packet_hash(packet, 244, "2097087");      /* Rekkanoryo says this is the build number */ 
    3815         yahoo_packet_hash(packet, 2, yd->user); 
     3799        yahoo_packet_hash(packet, 2, yid->yd->user); 
    38163800        yahoo_packet_hash(packet, 2, "1"); 
    38173801        yahoo_packet_hash(packet, 98, "us");            /* TODO Put country code */ 
     
    38233807 
    38243808        /* We don't need this anymore */ 
    3825         free(yd->login_cookie); 
    3826         yd->login_cookie = NULL; 
     3809        free(yid->yd->login_cookie); 
     3810        yid->yd->login_cookie = NULL; 
     3811         
     3812        return; 
     3813 
     3814FAIL: 
     3815        YAHOO_CALLBACK(ext_yahoo_login_response)(yid->yd->client_id, error_code, NULL); 
    38273816} 
    38283817