~ubuntu-branches/ubuntu/trusty/irssi-plugin-xmpp/trusty-proposed

« back to all changes in this revision

Viewing changes to src/core/rosters.c

  • Committer: Package Import Robot
  • Author(s): Florian Schlichting, Florian Schlichting
  • Date: 2014-01-03 00:25:20 UTC
  • mfrom: (1.3.6)
  • Revision ID: package-import@ubuntu.com-20140103002520-zc3sfydzt1wp03i0
Tags: 0.52+git20140102-1
[ Florian Schlichting ]
* Import Upstream version 0.52+git20140102
* Add VCS-* fields for collab-maint on alioth
* Add upstream git URL to Source field in debian/copyright
* Drop patches plucked from upstream CVS
* Refresh hardening.patch (offset, drop hunk fixed upstream)
* Provide xmpp-admin.pl script by Seth Difley
* Add GTalk-MUC-support.patch, plucked from github/freemandrew
* Add support for XMPP-PGP, plucked from github/singpolyma
* New useless-dependency-on-libidn.patch, to fix a lintian warning
* Declare compliance with Debian Policy 3.9.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * $Id: rosters.c,v 1.12 2013/02/25 16:16:35 cdidier Exp $
3
 
 *
4
2
 * Copyright (C) 2007 Colin DIDIER
5
3
 *
6
4
 * This program is free software; you can redistribute it and/or modify
139
137
        resource->show= XMPP_PRESENCE_UNAVAILABLE;
140
138
        resource->status = NULL;
141
139
        resource->composing_id = NULL;
 
140
        resource->pgp_keyid = NULL;
 
141
        resource->pgp_encrypt = 0;
142
142
        return resource;
143
143
}
144
144
 
153
153
        g_free(resource->name);
154
154
        g_free(resource->status);
155
155
        g_free(resource->composing_id);
 
156
        if(resource->pgp_keyid) free(resource->pgp_keyid);
156
157
        g_free(resource);
157
158
}
158
159
 
343
344
 
344
345
static void
345
346
update_user_presence(XMPP_SERVER_REC *server, const char *full_jid,
346
 
    const char *show_str, const char *status, const char *priority_str)
 
347
    const char *show_str, const char *status, const char *priority_str,
 
348
    char *pgp_keyid)
347
349
{
348
350
        XMPP_ROSTER_GROUP_REC *group;
349
351
        XMPP_ROSTER_USER_REC *user;
387
389
                resource->show = show;
388
390
                resource->status = g_strdup(status);
389
391
                resource->priority = priority;
 
392
                resource->pgp_keyid = pgp_keyid;
390
393
                if (!own) {
391
394
                        user->resources = g_slist_sort(
392
395
                            user->resources, func_sort_resource);
472
475
                            func_sort_user);
473
476
                signal_emit("xmpp presence changed", 4, server, full_jid,
474
477
                    XMPP_PRESENCE_ERROR, NULL);
475
 
        } else
 
478
        } else if (user != NULL)
476
479
                user->error = TRUE;
477
480
 
478
481
out:
485
488
sig_recv_presence(XMPP_SERVER_REC *server, LmMessage *lmsg, const int type,
486
489
    const char *id, const char *from, const char *to)
487
490
{
488
 
        LmMessageNode *node, *node_show, *node_priority;
489
 
        char *status;
 
491
        LmMessageNode *node, *node_show, *node_priority, *signature;
 
492
        char *status, *pgp_keyid = NULL;
490
493
 
491
494
        if (server->ischannel(SERVER(server), from))
492
495
                return;
496
499
                node = lm_message_node_get_child(lmsg->node, "status");
497
500
                status = node != NULL ? xmpp_recode_in(node->value) : NULL;
498
501
                node_priority = lm_message_node_get_child(lmsg->node, "priority");
 
502
                signature = lm_find_node(lmsg->node, "x", "xmlns", "jabber:x:signed");
 
503
                if(signature) {
 
504
                        char *send_to_gpg = malloc(sizeof( \
 
505
                                "-----BEGIN PGP SIGNATURE-----\n\n" \
 
506
                                "-----END PGP SIGNATURE-----\n")+ \
 
507
                                strlen(signature->value)+1 \
 
508
                        );
 
509
                        char *send_status = status ? status : "";
 
510
                        char *from_gpg;
 
511
 
 
512
                        send_to_gpg[0] = '\0';
 
513
                        strcat(send_to_gpg, "-----BEGIN PGP SIGNATURE-----\n\n");
 
514
                        strcat(send_to_gpg, signature->value);
 
515
                        strcat(send_to_gpg, "-----END PGP SIGNATURE-----\n");
 
516
 
 
517
                        from_gpg = call_gpg("--verify", send_to_gpg, send_status, 1, 0);
 
518
                        free(send_to_gpg);
 
519
 
 
520
                        /* If there is a good signature, grab the key ID */
 
521
                        if(from_gpg && strstr(from_gpg, "Good signature from")) {
 
522
                                char *s = strstr(from_gpg, "key ID ");
 
523
                                if(s) {
 
524
                                        pgp_keyid = malloc(sizeof(*pgp_keyid)*9);
 
525
                                        strncpy(pgp_keyid, s+7, 8);
 
526
                                        pgp_keyid[8] = '\0';
 
527
                                }
 
528
                        }
 
529
                        if(from_gpg) free(from_gpg);
 
530
                }
499
531
                update_user_presence(server, from,
500
532
                    node_show != NULL ? node_show->value : NULL, status,
501
 
                    node_priority != NULL ? node_priority->value : NULL);
 
533
                    node_priority != NULL ? node_priority->value : NULL,
 
534
                    pgp_keyid);
502
535
                g_free(status);
503
536
                break;
504
537
        case LM_MESSAGE_SUB_TYPE_UNAVAILABLE: