Changeset 5fbf815


Ignore:
Timestamp:
2015-04-11T19:36:13Z (9 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
951aefd
Parents:
002fede
Message:

msn: rename all old 'handler' variables to 'md' for consistency

I avoided doing this before to keep the diff small. But meh.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/msn/ns.c

    r002fede r5fbf815  
    3838static void msn_ns_send_adl_start(struct im_connection *ic);
    3939static void msn_ns_send_adl(struct im_connection *ic);
    40 static void msn_ns_structured_message(struct msn_data *handler, char *msg, int msglen, char **cmd);
    41 static void msn_ns_sdg(struct msn_data *handler, char *who, char **parts, char *action);
    42 static void msn_ns_nfy(struct msn_data *handler, char *who, char **parts, char *action, gboolean is_put);
     40static void msn_ns_structured_message(struct msn_data *md, char *msg, int msglen, char **cmd);
     41static void msn_ns_sdg(struct msn_data *md, char *who, char **parts, char *action);
     42static void msn_ns_nfy(struct msn_data *md, char *who, char **parts, char *action, gboolean is_put);
    4343
    4444int msn_ns_write(struct im_connection *ic, int fd, const char *fmt, ...)
     
    8383gboolean msn_ns_connect(struct im_connection *ic, const char *host, int port)
    8484{
    85         struct msn_data *handler = ic->proto_data;
    86 
    87         if (handler->fd >= 0) {
    88                 closesocket(handler->fd);
    89         }
    90 
    91         if (handler->is_http) {
    92                 handler->gw = msn_gw_new(handler);
    93                 handler->gw->callback = msn_ns_callback;
    94                 msn_ns_connected(handler, -1, B_EV_IO_READ);
     85        struct msn_data *md = ic->proto_data;
     86
     87        if (md->fd >= 0) {
     88                closesocket(md->fd);
     89        }
     90
     91        if (md->is_http) {
     92                md->gw = msn_gw_new(md);
     93                md->gw->callback = msn_ns_callback;
     94                msn_ns_connected(md, -1, B_EV_IO_READ);
    9595        } else {
    96                 handler->fd = proxy_connect(host, port, msn_ns_connected, handler);
    97                 if (handler->fd < 0) {
     96                md->fd = proxy_connect(host, port, msn_ns_connected, md);
     97                if (md->fd < 0) {
    9898                        imcb_error(ic, "Could not connect to server");
    9999                        imc_logout(ic, TRUE);
     
    108108{
    109109        struct msn_data *md = data;
    110         struct msn_data *handler = md;
    111110        struct im_connection *ic = md->ic;
    112111
     
    117116        }
    118117
    119         g_free(handler->rxq);
    120         handler->rxlen = 0;
    121         handler->rxq = g_new0(char, 1);
     118        g_free(md->rxq);
     119        md->rxlen = 0;
     120        md->rxq = g_new0(char, 1);
    122121
    123122        if (md->uuid == NULL) {
     
    137136
    138137        if (msn_ns_write(ic, source, "VER %d %s CVR0\r\n", ++md->trId, MSNP_VER)) {
    139                 if (!handler->is_http) {
    140                         handler->inpa = b_input_add(handler->fd, B_EV_IO_READ, msn_ns_callback, handler);
     138                if (!md->is_http) {
     139                        md->inpa = b_input_add(md->fd, B_EV_IO_READ, msn_ns_callback, md);
    141140                }
    142141                imcb_log(ic, "Connected to server, waiting for reply");
     
    146145}
    147146
    148 void msn_ns_close(struct msn_data *handler)
    149 {
    150         if (handler->gw) {
    151                 if (handler->gw->waiting) {
     147void msn_ns_close(struct msn_data *md)
     148{
     149        if (md->gw) {
     150                if (md->gw->waiting) {
    152151                        /* mark it as closed, let the request callback clean it */
    153                         handler->gw->open = FALSE;
     152                        md->gw->open = FALSE;
    154153                } else {
    155                         msn_gw_free(handler->gw);
    156                 }
    157         }
    158         if (handler->fd >= 0) {
    159                 closesocket(handler->fd);
    160                 b_event_remove(handler->inpa);
    161         }
    162 
    163         handler->fd = handler->inpa = -1;
    164         g_free(handler->rxq);
    165         g_free(handler->cmd_text);
    166 
    167         handler->rxlen = 0;
    168         handler->rxq = NULL;
    169         handler->cmd_text = NULL;
     154                        msn_gw_free(md->gw);
     155                }
     156        }
     157        if (md->fd >= 0) {
     158                closesocket(md->fd);
     159                b_event_remove(md->inpa);
     160        }
     161
     162        md->fd = md->inpa = -1;
     163        g_free(md->rxq);
     164        g_free(md->cmd_text);
     165
     166        md->rxlen = 0;
     167        md->rxq = NULL;
     168        md->cmd_text = NULL;
    170169}
    171170
    172171static gboolean msn_ns_callback(gpointer data, gint source, b_input_condition cond)
    173172{
    174         struct msn_data *handler = data;
    175         struct im_connection *ic = handler->ic;
     173        struct msn_data *md = data;
     174        struct im_connection *ic = md->ic;
    176175        char *bytes;
    177176        int st;
    178177
    179         if (handler->is_http) {
    180                 st = msn_gw_read(handler->gw, &bytes);
     178        if (md->is_http) {
     179                st = msn_gw_read(md->gw, &bytes);
    181180        } else {
    182181                bytes = g_malloc(1024);
    183                 st = read(handler->fd, bytes, 1024);
     182                st = read(md->fd, bytes, 1024);
    184183        }
    185184
     
    190189        }
    191190
    192         msn_queue_feed(handler, bytes, st);
     191        msn_queue_feed(md, bytes, st);
    193192
    194193        g_free(bytes);
    195194
    196195        /* Ignore ret == 0, it's already disconnected then. */
    197         msn_handler(handler);
     196        msn_handler(md);
    198197
    199198        return TRUE;
     
    201200}
    202201
    203 int msn_ns_command(struct msn_data *handler, char **cmd, int num_parts)
    204 {
    205         struct im_connection *ic = handler->ic;
    206         struct msn_data *md = handler;
     202int msn_ns_command(struct msn_data *md, char **cmd, int num_parts)
     203{
     204        struct im_connection *ic = md->ic;
    207205
    208206        if (num_parts == 0) {
     
    218216                }
    219217
    220                 return(msn_ns_write(ic, handler->fd, "CVR %d 0x0409 mac 10.2.0 ppc macmsgs 3.5.1 macmsgs %s VmVyc2lvbjogMQ0KWGZyQ291bnQ6IDINClhmclNlbnRVVENUaW1lOiA2MzU2MTQ3OTU5NzgzOTAwMDANCklzR2VvWGZyOiB0cnVlDQo=\r\n",
     218                return(msn_ns_write(ic, md->fd, "CVR %d 0x0409 mac 10.2.0 ppc macmsgs 3.5.1 macmsgs %s VmVyc2lvbjogMQ0KWGZyQ291bnQ6IDINClhmclNlbnRVVENUaW1lOiA2MzU2MTQ3OTU5NzgzOTAwMDANCklzR2VvWGZyOiB0cnVlDQo=\r\n",
    221219                                    ++md->trId, ic->acc->user));
    222220        } else if (strcmp(cmd[0], "CVR") == 0) {
    223221                /* We don't give a damn about the information we just received */
    224                 return msn_ns_write(ic, handler->fd, "USR %d SSO I %s\r\n", ++md->trId, ic->acc->user);
     222                return msn_ns_write(ic, md->fd, "USR %d SSO I %s\r\n", ++md->trId, ic->acc->user);
    225223        } else if (strcmp(cmd[0], "XFR") == 0) {
    226224                char *server;
     
    228226
    229227                if (num_parts >= 6 && strcmp(cmd[2], "NS") == 0) {
    230                         b_event_remove(handler->inpa);
    231                         handler->inpa = -1;
     228                        b_event_remove(md->inpa);
     229                        md->inpa = -1;
    232230
    233231                        server = strchr(cmd[3], ':');
     
    276274                }
    277275
    278                 handler->msglen = atoi(cmd[3]);
    279 
    280                 if (handler->msglen <= 0) {
     276                md->msglen = atoi(cmd[3]);
     277
     278                if (md->msglen <= 0) {
    281279                        imcb_error(ic, "Syntax error");
    282280                        imc_logout(ic, TRUE);
     
    288286                        return msn_ns_finish_login(ic);
    289287                } else if (num_parts >= 3) {
    290                         handler->msglen = atoi(cmd[2]);
     288                        md->msglen = atoi(cmd[2]);
    291289                }
    292290        } else if (strcmp(cmd[0], "CHL") == 0) {
     
    327325                /* Coming up is cmd[2] bytes of stuff we're supposed to
    328326                   censore. Meh. */
    329                 handler->msglen = atoi(cmd[2]);
     327                md->msglen = atoi(cmd[2]);
    330328        } else if ((strcmp(cmd[0], "NFY") == 0) || (strcmp(cmd[0], "SDG") == 0)) {
    331329                if (num_parts >= 3) {
    332                         handler->msglen = atoi(cmd[2]);
     330                        md->msglen = atoi(cmd[2]);
    333331                }
    334332        } else if (strcmp(cmd[0], "PUT") == 0) {
    335333                if (num_parts >= 4) {
    336                         handler->msglen = atoi(cmd[3]);
     334                        md->msglen = atoi(cmd[3]);
    337335                }
    338336        } else if (strcmp(cmd[0], "NOT") == 0) {
    339337                if (num_parts >= 2) {
    340                         handler->msglen = atoi(cmd[1]);
     338                        md->msglen = atoi(cmd[1]);
    341339                }
    342340        } else if (strcmp(cmd[0], "QNG") == 0) {
     
    355353                /* Oh yes, errors can have payloads too now. Discard them for now. */
    356354                if (num_parts >= 3) {
    357                         handler->msglen = atoi(cmd[2]);
     355                        md->msglen = atoi(cmd[2]);
    358356                }
    359357        } else {
     
    364362}
    365363
    366 int msn_ns_message(struct msn_data *handler, char *msg, int msglen, char **cmd, int num_parts)
    367 {
    368         struct im_connection *ic = handler->ic;
     364int msn_ns_message(struct msn_data *md, char *msg, int msglen, char **cmd, int num_parts)
     365{
     366        struct im_connection *ic = md->ic;
    369367        char *body;
    370368        int blen = 0;
     
    493491                }
    494492        } else if ((strcmp(cmd[0], "SDG") == 0) || (strcmp(cmd[0], "NFY") == 0)) {
    495                 msn_ns_structured_message(handler, msg, msglen, cmd);
     493                msn_ns_structured_message(md, msg, msglen, cmd);
    496494        }
    497495
     
    499497}
    500498
    501 static void msn_ns_structured_message(struct msn_data *handler, char *msg, int msglen, char **cmd)
     499static void msn_ns_structured_message(struct msn_data *md, char *msg, int msglen, char **cmd)
    502500{
    503501        char **parts = NULL;
     
    519517
    520518        if ((strcmp(cmd[0], "SDG") == 0) && (action = get_rfc822_header(parts[2], "Message-Type", 0))) {
    521                 msn_ns_sdg(handler, who, parts, action);
     519                msn_ns_sdg(md, who, parts, action);
    522520
    523521        } else if ((strcmp(cmd[0], "NFY") == 0) && (action = get_rfc822_header(parts[2], "Uri", 0))) {
    524522                gboolean is_put = (strcmp(cmd[1], "PUT") == 0);
    525                 msn_ns_nfy(handler, who, parts, action, is_put);
     523                msn_ns_nfy(md, who, parts, action, is_put);
    526524        }
    527525
     
    533531}
    534532
    535 static void msn_ns_sdg(struct msn_data *handler, char *who, char **parts, char *action)
    536 {
    537         struct im_connection *ic = handler->ic;
     533static void msn_ns_sdg(struct msn_data *md, char *who, char **parts, char *action)
     534{
     535        struct im_connection *ic = md->ic;
    538536
    539537        if (strcmp(action, "Control/Typing") == 0) {
     
    544542}
    545543
    546 static void msn_ns_nfy(struct msn_data *handler, char *who, char **parts, char *action, gboolean is_put)
    547 {
    548         struct im_connection *ic = handler->ic;
     544static void msn_ns_nfy(struct msn_data *md, char *who, char **parts, char *action, gboolean is_put)
     545{
     546        struct im_connection *ic = md->ic;
    549547        struct xt_node *body = NULL;
    550548        struct xt_node *s = NULL;
Note: See TracChangeset for help on using the changeset viewer.