Changeset 951aefd for protocols/msn


Ignore:
Timestamp:
2015-04-12T15:27:31Z (9 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
2fe8297
Parents:
5fbf815
Message:

msn/gw.c: ensure that the im_connection still exists in callbacks

Location:
protocols/msn
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • protocols/msn/gw.c

    r5fbf815 r951aefd  
    1515static gboolean msn_gw_poll_timeout(gpointer data, gint source, b_input_condition cond);
    1616
    17 struct msn_gw *msn_gw_new(struct msn_data *md)
     17struct msn_gw *msn_gw_new(struct im_connection *ic)
    1818{
    1919        struct msn_gw *gw = g_new0(struct msn_gw, 1);
     
    2222        gw->ssl = (GATEWAY_PORT == 443);
    2323        gw->poll_timeout = -1;
    24         gw->data = md;
     24        gw->ic = ic;
     25        gw->md = ic->proto_data;
    2526        gw->in = g_byte_array_new();
    2627        gw->out = g_byte_array_new();
     
    3839        g_free(gw->last_host);
    3940        g_free(gw);
     41}
     42
     43static struct msn_gw *msn_gw_from_ic(struct im_connection *ic)
     44{
     45        if (g_slist_find(msn_connections, ic) == NULL) {
     46                return NULL;
     47        } else {
     48                struct msn_data *md = ic->proto_data;
     49                return md->gw;
     50        }
    4051}
    4152
     
    6677void msn_gw_callback(struct http_request *req)
    6778{
     79        struct msn_gw *gw;
    6880        char *value;
    69         struct msn_gw *gw = req->data;
     81
     82        if (!(gw = msn_gw_from_ic(req->data))) {
     83                return;
     84        }
    7085
    7186        gw->waiting = FALSE;
    7287        gw->polling = FALSE;
    73 
    74         if (!gw->open) {
    75                 /* the user tried to logout while the request was pending
    76                  * see msn_ns_close() */
    77                 msn_gw_free(gw);
    78                 return;
    79         }
    8088
    8189        if (getenv("BITLBEE_DEBUG")) {
     
    8593
    8694        if (req->status_code != 200) {
    87                 gw->callback(gw->data, -1, B_EV_IO_READ);
     95                gw->callback(gw->md, -1, B_EV_IO_READ);
    8896                return;
    8997        }
     
    9199        if ((value = get_rfc822_header(req->reply_headers, "X-MSN-Messenger", 0))) {
    92100                if (!msn_gw_parse_session_header(gw, value)) {
    93                         gw->callback(gw->data, -1, B_EV_IO_READ);
     101                        gw->callback(gw->md, -1, B_EV_IO_READ);
    94102                        g_free(value);
    95103                        return;
     
    105113        if (req->body_size) {
    106114                g_byte_array_append(gw->in, (const guint8 *) req->reply_body, req->body_size);
    107                 gw->callback(gw->data, -1, B_EV_IO_READ);
     115                gw->callback(gw->md, -1, B_EV_IO_READ);
    108116        }
    109117
     
    111119                b_event_remove(gw->poll_timeout);
    112120        }
    113         gw->poll_timeout = b_timeout_add(500, msn_gw_poll_timeout, gw);
     121        gw->poll_timeout = b_timeout_add(500, msn_gw_poll_timeout, gw->ic);
    114122
    115123}
     
    136144                gw->session_id ? : "", args ? : "", gw->last_host, bodylen, body ? : "");
    137145
    138         http_dorequest(gw->last_host, gw->port, gw->ssl, request, msn_gw_callback, gw);
     146        http_dorequest(gw->last_host, gw->port, gw->ssl, request, msn_gw_callback, gw->ic);
    139147        gw->open = TRUE;
    140148        gw->waiting = TRUE;
     
    151159static gboolean msn_gw_poll_timeout(gpointer data, gint source, b_input_condition cond)
    152160{
    153         struct msn_gw *gw = data;
     161        struct msn_gw *gw;
     162
     163        if (!(gw = msn_gw_from_ic(data))) {
     164                return FALSE;
     165        }
     166
    154167        gw->poll_timeout = -1;
    155168        if (!gw->waiting) {
  • protocols/msn/msn.h

    r5fbf815 r951aefd  
    137137
    138138        b_event_handler callback;
    139         gpointer data;
     139
     140        struct im_connection *ic;
     141        struct msn_data *md;
    140142
    141143        gboolean open;
     
    265267
    266268/* gw.c */
    267 struct msn_gw *msn_gw_new(struct msn_data *md);
     269struct msn_gw *msn_gw_new(struct im_connection *ic);
    268270void msn_gw_free(struct msn_gw *gw);
    269271void msn_gw_open(struct msn_gw *gw);
  • protocols/msn/ns.c

    r5fbf815 r951aefd  
    9090
    9191        if (md->is_http) {
    92                 md->gw = msn_gw_new(md);
     92                md->gw = msn_gw_new(ic);
    9393                md->gw->callback = msn_ns_callback;
    9494                msn_ns_connected(md, -1, B_EV_IO_READ);
     
    148148{
    149149        if (md->gw) {
    150                 if (md->gw->waiting) {
    151                         /* mark it as closed, let the request callback clean it */
    152                         md->gw->open = FALSE;
    153                 } else {
    154                         msn_gw_free(md->gw);
    155                 }
     150                msn_gw_free(md->gw);
    156151        }
    157152        if (md->fd >= 0) {
Note: See TracChangeset for help on using the changeset viewer.