Coverage Report

Created: 2025-08-28 06:24

/src/pidgin/libpurple/protocols/jabber/ping.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * purple - Jabber Protocol Plugin
3
 *
4
 * Purple is the legal property of its developers, whose names are too numerous
5
 * to list here.  Please refer to the COPYRIGHT file distributed with this
6
 * source distribution.
7
 *
8
 * This program is free software; you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation; either version 2 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 *
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
22
 *
23
 */
24
25
#include "internal.h"
26
27
#include "debug.h"
28
29
#include "jabber.h"
30
#include "ping.h"
31
#include "iq.h"
32
33
static void jabber_keepalive_pong_cb(JabberStream *js, const char *from,
34
                                     JabberIqType type, const char *id,
35
                                     xmlnode *packet, gpointer data)
36
0
{
37
0
  if (js->keepalive_timeout != 0) {
38
0
    purple_timeout_remove(js->keepalive_timeout);
39
0
    js->keepalive_timeout = 0;
40
0
  }
41
0
}
42
43
void
44
jabber_ping_parse(JabberStream *js, const char *from,
45
                  JabberIqType type, const char *id, xmlnode *ping)
46
0
{
47
0
  if (type == JABBER_IQ_GET) {
48
0
    JabberIq *iq = jabber_iq_new(js, JABBER_IQ_RESULT);
49
50
0
    if (from)
51
0
      xmlnode_set_attrib(iq->node, "to", from);
52
0
    xmlnode_set_attrib(iq->node, "id", id);
53
54
0
    jabber_iq_send(iq);
55
0
  } else if (type == JABBER_IQ_SET) {
56
    /* XXX: error */
57
0
  }
58
0
}
59
60
static void jabber_ping_result_cb(JabberStream *js, const char *from,
61
                                  JabberIqType type, const char *id,
62
                                  xmlnode *packet, gpointer data)
63
0
{
64
0
  if (type == JABBER_IQ_RESULT)
65
0
    purple_debug_info("jabber", "PONG!\n");
66
0
  else
67
0
    purple_debug_info("jabber", "ping not supported\n");
68
0
}
69
70
void jabber_keepalive_ping(JabberStream *js)
71
0
{
72
0
  JabberIq *iq;
73
0
  xmlnode *ping;
74
75
0
  iq = jabber_iq_new(js, JABBER_IQ_GET);
76
0
  ping = xmlnode_new_child(iq->node, "ping");
77
0
  xmlnode_set_namespace(ping, NS_PING);
78
79
0
  jabber_iq_set_callback(iq, jabber_keepalive_pong_cb, NULL);
80
0
  jabber_iq_send(iq);
81
0
}
82
83
gboolean jabber_ping_jid(JabberStream *js, const char *jid)
84
0
{
85
0
  JabberIq *iq;
86
0
  xmlnode *ping;
87
88
0
  iq = jabber_iq_new(js, JABBER_IQ_GET);
89
0
  if (jid)
90
0
    xmlnode_set_attrib(iq->node, "to", jid);
91
92
0
  ping = xmlnode_new_child(iq->node, "ping");
93
0
  xmlnode_set_namespace(ping, NS_PING);
94
95
0
  jabber_iq_set_callback(iq, jabber_ping_result_cb, NULL);
96
0
  jabber_iq_send(iq);
97
98
0
  return TRUE;
99
0
}