MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / stream_node_callback

Function stream_node_callback

modules/xmpp/xmpp_component.c:54–119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52}
53
54static void stream_node_callback(int type, xode node, void *arg)
55{
56 struct xmpp_private_data *priv = (struct xmpp_private_data *) arg;
57 char *id, *hash, *tag;
58 char buf[4096];
59 xode x;
60
61 LM_DBG("stream callback: %d: %s\n", type, node ? xode_get_name(node) : "n/a");
62 switch (type) {
63 case XODE_STREAM_ROOT:
64 id = xode_get_attrib(node, "id");
65 snprintf(buf, sizeof(buf), "%s%s", id, xmpp_password);
66 hash = shahash(buf);
67
68 x = xode_new_tag("handshake");
69 xode_insert_cdata(x, hash, -1);
70 xode_send(priv->fd, x);
71 xode_free(x);
72 break;
73 case XODE_STREAM_NODE:
74 tag = xode_get_name(node);
75 if (!strcmp(tag, "handshake")) {
76 LM_DBG("handshake succeeded\n");
77 } else if (!strcmp(tag, "message")) {
78 LM_DBG("XMPP IM received\n");
79 char *from = xode_get_attrib(node, "from");
80 char *to = xode_get_attrib(node, "to");
81 char *type = xode_get_attrib(node, "type");
82 xode body = xode_get_tag(node, "body");
83 char *msg;
84
85 if (!type)
86 type = "chat";
87 if (!strcmp(type, "error")) {
88 LM_DBG("received message error stanza\n");
89 goto out;
90 }
91
92 if (!from || !to || !body) {
93 LM_DBG("invalid <message/> attributes\n");
94 goto out;
95 }
96
97 if (!(msg = xode_get_data(body)))
98 msg = "";
99 xmpp_send_sip_msg(from, to, msg);
100 } else if (!strcmp(tag, "presence")) {
101 /* call presence callbacks */
102 LM_DBG("XMPP Presence received\n");
103 run_xmpp_callbacks(XMPP_RCV_PRESENCE, xode_to_str(node));
104 }else if (!strcmp(tag, "iq")) {
105 /* call presence callbacks */
106 LM_DBG("XMPP IQ received\n");
107 run_xmpp_callbacks(XMPP_RCV_IQ, xode_to_str(node));
108 }
109 break;
110 case XODE_STREAM_ERROR:
111 LM_ERR("stream error\n");

Callers

nothing calls this directly

Calls 12

xmpp_send_sip_msgFunction · 0.85
run_xmpp_callbacksFunction · 0.85
xode_get_nameFunction · 0.70
xode_get_attribFunction · 0.70
shahashFunction · 0.70
xode_new_tagFunction · 0.70
xode_insert_cdataFunction · 0.70
xode_sendFunction · 0.70
xode_freeFunction · 0.70
xode_get_tagFunction · 0.70
xode_get_dataFunction · 0.70
xode_to_strFunction · 0.70

Tested by

no test coverage detected