author | Mikael Berthe <mikael@lilotux.net> |
Mon, 25 Jan 2021 20:59:00 +0100 | |
changeset 740 | f1bb5e7e9477 |
parent 713 | ecfbb3961c19 |
permissions | -rw-r--r-- |
516
4dd3aa6b83e5
Change the tab width to 4 steps in the emacs headers
Mikael Hallendal <micke@imendio.com>
parents:
515
diff
changeset
|
1 |
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
1 | 2 |
/* |
99
81e9d035de02
2004-10-05 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
84
diff
changeset
|
3 |
* Copyright (C) 2003 Imendio AB |
1 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU Lesser General Public License as |
|
7 |
* published by the Free Software Foundation; either version 2 of the |
|
8 |
* License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 |
* Lesser General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU Lesser General Public |
|
690
7ccf2113ec5f
Update the postal address of the FSF
Frank Zschockelt <lm@freakysoft.de>
parents:
607
diff
changeset
|
16 |
* License along with this program; if not, see <https://www.gnu.org/licenses> |
1 | 17 |
*/ |
18 |
||
417
364c17252e5f
Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents:
331
diff
changeset
|
19 |
/** |
420
f40434cca022
Fixed the SECTION parts of the inlined docs so that gtk-doc finds them.
Mikael Hallendal <micke@imendio.com>
parents:
417
diff
changeset
|
20 |
* SECTION:lm-message |
421
2a91651d22de
Added Title to the inlined documentation
Mikael Hallendal <micke@imendio.com>
parents:
420
diff
changeset
|
21 |
* @Title: LmMessage |
417
364c17252e5f
Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents:
331
diff
changeset
|
22 |
* @Short_description: A message is built up like a tree of message nodes. |
607 | 23 |
* |
417
364c17252e5f
Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents:
331
diff
changeset
|
24 |
* Represents a message that can be sent with lm_connection_send(), lm_connection_send_with_reply() or lm_connection_send_with_reply_and_block(). Either use lm_message_new() or lm_message_new_with_subtype() to create a message. You need to call lm_message_unref() when are finished with it. |
364c17252e5f
Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents:
331
diff
changeset
|
25 |
*/ |
364c17252e5f
Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents:
331
diff
changeset
|
26 |
|
1 | 27 |
#include <config.h> |
28 |
#include <string.h> |
|
29 |
||
30 |
#include "lm-internals.h" |
|
31 |
#include "lm-message.h" |
|
32 |
||
33 |
#define PRIV(o) ((LmMessage *)o)->priv |
|
34 |
||
607 | 35 |
static struct TypeNames |
1 | 36 |
{ |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
37 |
LmMessageType type; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
38 |
const gchar *name; |
1 | 39 |
} type_names[] = { |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
40 |
{ LM_MESSAGE_TYPE_MESSAGE, "message" }, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
41 |
{ LM_MESSAGE_TYPE_PRESENCE, "presence" }, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
42 |
{ LM_MESSAGE_TYPE_IQ, "iq" }, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
43 |
{ LM_MESSAGE_TYPE_STREAM, "stream:stream" }, |
583
dfe3688d71c9
The order of enums in the lm-message.h and lm-message.c for the stream:error and stream:features message types was transposed, leading to inaccurate identification of those two types.
Kirk Haines <khaines@engineyard.com>
parents:
558
diff
changeset
|
44 |
{ LM_MESSAGE_TYPE_STREAM_ERROR, "stream:error" }, |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
45 |
{ LM_MESSAGE_TYPE_STREAM_FEATURES, "stream:features" }, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
46 |
{ LM_MESSAGE_TYPE_AUTH, "auth" }, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
47 |
{ LM_MESSAGE_TYPE_CHALLENGE, "challenge" }, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
48 |
{ LM_MESSAGE_TYPE_RESPONSE, "response" }, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
49 |
{ LM_MESSAGE_TYPE_SUCCESS, "success" }, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
50 |
{ LM_MESSAGE_TYPE_FAILURE, "failure" }, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
51 |
{ LM_MESSAGE_TYPE_PROCEED, "proceed" }, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
52 |
{ LM_MESSAGE_TYPE_STARTTLS, "starttls" }, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
53 |
{ LM_MESSAGE_TYPE_UNKNOWN, NULL } |
1 | 54 |
}; |
55 |
||
607 | 56 |
static struct SubTypeNames |
1 | 57 |
{ |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
58 |
LmMessageSubType type; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
59 |
const gchar *name; |
1 | 60 |
} sub_type_names[] = { |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
61 |
{ LM_MESSAGE_SUB_TYPE_NORMAL, "normal" }, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
62 |
{ LM_MESSAGE_SUB_TYPE_CHAT, "chat" }, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
63 |
{ LM_MESSAGE_SUB_TYPE_GROUPCHAT, "groupchat" }, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
64 |
{ LM_MESSAGE_SUB_TYPE_HEADLINE, "headline" }, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
65 |
{ LM_MESSAGE_SUB_TYPE_UNAVAILABLE, "unavailable" }, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
66 |
{ LM_MESSAGE_SUB_TYPE_PROBE, "probe" }, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
67 |
{ LM_MESSAGE_SUB_TYPE_SUBSCRIBE, "subscribe" }, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
68 |
{ LM_MESSAGE_SUB_TYPE_UNSUBSCRIBE, "unsubscribe" }, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
69 |
{ LM_MESSAGE_SUB_TYPE_SUBSCRIBED, "subscribed" }, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
70 |
{ LM_MESSAGE_SUB_TYPE_UNSUBSCRIBED, "unsubscribed" }, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
71 |
{ LM_MESSAGE_SUB_TYPE_GET, "get" }, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
72 |
{ LM_MESSAGE_SUB_TYPE_SET, "set" }, |
607 | 73 |
{ LM_MESSAGE_SUB_TYPE_RESULT, "result" }, |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
74 |
{ LM_MESSAGE_SUB_TYPE_ERROR, "error" } |
1 | 75 |
}; |
76 |
||
77 |
struct LmMessagePriv { |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
78 |
LmMessageType type; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
79 |
LmMessageSubType sub_type; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
80 |
gint ref_count; |
1 | 81 |
}; |
82 |
||
83 |
static LmMessageType |
|
84 |
message_type_from_string (const gchar *type_str) |
|
85 |
{ |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
86 |
gint i; |
1 | 87 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
88 |
if (!type_str) { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
89 |
return LM_MESSAGE_TYPE_UNKNOWN; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
90 |
} |
1 | 91 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
92 |
for (i = LM_MESSAGE_TYPE_MESSAGE; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
93 |
i < LM_MESSAGE_TYPE_UNKNOWN; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
94 |
++i) { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
95 |
if (strcmp (type_str, type_names[i].name) == 0) { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
96 |
return type_names[i].type; |
1 | 97 |
} |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
98 |
} |
1 | 99 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
100 |
return LM_MESSAGE_TYPE_UNKNOWN; |
1 | 101 |
} |
102 |
||
103 |
||
104 |
const gchar * |
|
105 |
_lm_message_type_to_string (LmMessageType type) |
|
106 |
{ |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
107 |
if (type < LM_MESSAGE_TYPE_MESSAGE || |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
108 |
type > LM_MESSAGE_TYPE_STARTTLS) { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
109 |
type = LM_MESSAGE_TYPE_UNKNOWN; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
110 |
} |
1 | 111 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
112 |
return type_names[type].name; |
1 | 113 |
} |
114 |
||
115 |
static LmMessageSubType |
|
116 |
message_sub_type_from_string (const gchar *type_str) |
|
117 |
{ |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
118 |
gint i; |
1 | 119 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
120 |
if (!type_str) { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
121 |
return LM_MESSAGE_SUB_TYPE_NOT_SET; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
122 |
} |
1 | 123 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
124 |
for (i = LM_MESSAGE_SUB_TYPE_NORMAL; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
125 |
i <= LM_MESSAGE_SUB_TYPE_ERROR; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
126 |
++i) { |
607 | 127 |
if (g_ascii_strcasecmp (type_str, |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
128 |
sub_type_names[i].name) == 0) { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
129 |
return i; |
1 | 130 |
} |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
131 |
} |
1 | 132 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
133 |
return LM_MESSAGE_SUB_TYPE_NOT_SET; |
1 | 134 |
} |
135 |
||
136 |
const gchar * |
|
137 |
_lm_message_sub_type_to_string (LmMessageSubType type) |
|
138 |
{ |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
139 |
if (type < LM_MESSAGE_SUB_TYPE_NORMAL || |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
140 |
type > LM_MESSAGE_SUB_TYPE_ERROR) { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
141 |
return NULL; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
142 |
} |
1 | 143 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
144 |
return sub_type_names[type].name; |
1 | 145 |
} |
146 |
||
147 |
static LmMessageSubType |
|
148 |
message_sub_type_when_unset (LmMessageType type) { |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
149 |
LmMessageSubType sub_type = LM_MESSAGE_SUB_TYPE_NORMAL; |
1 | 150 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
151 |
switch (type) { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
152 |
case LM_MESSAGE_TYPE_MESSAGE: |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
153 |
/* A message without type should be handled like a message with |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
154 |
* type=normal, but we won't set it to that since then the user |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
155 |
* will not know if it's set or not. |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
156 |
*/ |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
157 |
sub_type = LM_MESSAGE_SUB_TYPE_NOT_SET; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
158 |
break; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
159 |
case LM_MESSAGE_TYPE_PRESENCE: |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
160 |
sub_type = LM_MESSAGE_SUB_TYPE_AVAILABLE; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
161 |
break; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
162 |
case LM_MESSAGE_TYPE_IQ: |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
163 |
sub_type = LM_MESSAGE_SUB_TYPE_GET; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
164 |
break; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
165 |
default: |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
166 |
break; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
167 |
} |
1 | 168 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
169 |
return sub_type; |
1 | 170 |
} |
171 |
||
172 |
LmMessage * |
|
173 |
_lm_message_new_from_node (LmMessageNode *node) |
|
174 |
{ |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
175 |
LmMessage *m; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
176 |
LmMessageType type; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
177 |
LmMessageSubType sub_type; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
178 |
const gchar *sub_type_str; |
607 | 179 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
180 |
type = message_type_from_string (node->name); |
1 | 181 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
182 |
if (type == LM_MESSAGE_TYPE_UNKNOWN) { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
183 |
return NULL; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
184 |
} |
1 | 185 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
186 |
sub_type_str = lm_message_node_get_attribute (node, "type"); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
187 |
if (sub_type_str) { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
188 |
sub_type = message_sub_type_from_string (sub_type_str); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
189 |
} else { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
190 |
sub_type = message_sub_type_when_unset (type); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
191 |
} |
1 | 192 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
193 |
m = g_new0 (LmMessage, 1); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
194 |
m->priv = g_new0 (LmMessagePriv, 1); |
607 | 195 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
196 |
PRIV(m)->ref_count = 1; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
197 |
PRIV(m)->type = type; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
198 |
PRIV(m)->sub_type = sub_type; |
607 | 199 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
200 |
m->node = lm_message_node_ref (node); |
607 | 201 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
202 |
return m; |
1 | 203 |
} |
204 |
||
205 |
/** |
|
206 |
* lm_message_new: |
|
207 |
* @to: receipient jid |
|
208 |
* @type: message type |
|
607 | 209 |
* |
210 |
* Creates a new #LmMessage which can be sent with lm_connection_send() or |
|
1 | 211 |
* lm_connection_send_with_reply(). If @to is %NULL the message is sent to the |
607 | 212 |
* server. The returned message should be unreferenced with lm_message_unref() |
1 | 213 |
* when caller is finished with it. |
607 | 214 |
* |
1 | 215 |
* Return value: a newly created #LmMessage |
216 |
**/ |
|
217 |
LmMessage * |
|
218 |
lm_message_new (const gchar *to, LmMessageType type) |
|
219 |
{ |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
220 |
LmMessage *m; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
221 |
gchar *id; |
79 | 222 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
223 |
m = g_new0 (LmMessage, 1); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
224 |
m->priv = g_new0 (LmMessagePriv, 1); |
1 | 225 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
226 |
PRIV(m)->ref_count = 1; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
227 |
PRIV(m)->type = type; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
228 |
PRIV(m)->sub_type = message_sub_type_when_unset (type); |
607 | 229 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
230 |
m->node = _lm_message_node_new (_lm_message_type_to_string (type)); |
49
66fd32fc225e
2003-10-13 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
24
diff
changeset
|
231 |
|
558
e5b7f24779c9
Don't append the 'id'-tag in opening stream headers. [#30]
Will Thompson <will.thompson@collabora.co.uk>
parents:
518
diff
changeset
|
232 |
if (type != LM_MESSAGE_TYPE_STREAM) { |
e5b7f24779c9
Don't append the 'id'-tag in opening stream headers. [#30]
Will Thompson <will.thompson@collabora.co.uk>
parents:
518
diff
changeset
|
233 |
id = _lm_utils_generate_id (); |
e5b7f24779c9
Don't append the 'id'-tag in opening stream headers. [#30]
Will Thompson <will.thompson@collabora.co.uk>
parents:
518
diff
changeset
|
234 |
lm_message_node_set_attribute (m->node, "id", id); |
e5b7f24779c9
Don't append the 'id'-tag in opening stream headers. [#30]
Will Thompson <will.thompson@collabora.co.uk>
parents:
518
diff
changeset
|
235 |
g_free (id); |
e5b7f24779c9
Don't append the 'id'-tag in opening stream headers. [#30]
Will Thompson <will.thompson@collabora.co.uk>
parents:
518
diff
changeset
|
236 |
} |
e5b7f24779c9
Don't append the 'id'-tag in opening stream headers. [#30]
Will Thompson <will.thompson@collabora.co.uk>
parents:
518
diff
changeset
|
237 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
238 |
if (to) { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
239 |
lm_message_node_set_attribute (m->node, "to", to); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
240 |
} |
1 | 241 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
242 |
if (type == LM_MESSAGE_TYPE_IQ) { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
243 |
lm_message_node_set_attribute (m->node, "type", "get"); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
244 |
} |
607 | 245 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
246 |
return m; |
1 | 247 |
} |
248 |
||
249 |
/** |
|
250 |
* lm_message_new_with_sub_type: |
|
251 |
* @to: receipient jid |
|
252 |
* @type: message type |
|
253 |
* @sub_type: message sub type |
|
607 | 254 |
* |
255 |
* Creates a new #LmMessage with sub type set. See lm_message_new() for more |
|
1 | 256 |
* information. |
607 | 257 |
* |
1 | 258 |
* Return value: a newly created #LmMessage |
259 |
**/ |
|
260 |
LmMessage * |
|
261 |
lm_message_new_with_sub_type (const gchar *to, |
|
607 | 262 |
LmMessageType type, |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
263 |
LmMessageSubType sub_type) |
1 | 264 |
{ |
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
265 |
LmMessage *m; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
266 |
const gchar *type_str; |
1 | 267 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
268 |
m = lm_message_new (to, type); |
79 | 269 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
270 |
type_str = _lm_message_sub_type_to_string (sub_type); |
1 | 271 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
272 |
if (type_str) { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
273 |
lm_message_node_set_attributes (m->node, |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
274 |
"type", type_str, NULL); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
275 |
PRIV(m)->sub_type = sub_type; |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
276 |
} |
1 | 277 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
278 |
return m; |
1 | 279 |
} |
280 |
||
281 |
/** |
|
282 |
* lm_message_get_type: |
|
283 |
* @message: an #LmMessage |
|
607 | 284 |
* |
1 | 285 |
* Fetches the type of @message. |
607 | 286 |
* |
1 | 287 |
* Return value: the message type |
288 |
**/ |
|
289 |
LmMessageType |
|
290 |
lm_message_get_type (LmMessage *message) |
|
291 |
{ |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
292 |
g_return_val_if_fail (message != NULL, LM_MESSAGE_TYPE_UNKNOWN); |
607 | 293 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
294 |
return PRIV(message)->type; |
1 | 295 |
} |
296 |
||
297 |
/** |
|
298 |
* lm_message_get_sub_type: |
|
607 | 299 |
* @message: |
300 |
* |
|
1 | 301 |
* Fetches the sub type of @message. |
607 | 302 |
* |
1 | 303 |
* Return value: the message sub type |
304 |
**/ |
|
8
33d64cf345be
2003-06-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents:
7
diff
changeset
|
305 |
LmMessageSubType |
1 | 306 |
lm_message_get_sub_type (LmMessage *message) |
307 |
{ |
|
713
ecfbb3961c19
Return the correct enum lm_message_get_sub_type
Frank Zschockelt <lm@freakysoft.de>
parents:
690
diff
changeset
|
308 |
g_return_val_if_fail (message != NULL, LM_MESSAGE_SUB_TYPE_NOT_SET); |
607 | 309 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
310 |
return PRIV(message)->sub_type; |
1 | 311 |
} |
312 |
||
313 |
/** |
|
314 |
* lm_message_get_node: |
|
315 |
* @message: an #LmMessage |
|
607 | 316 |
* |
1 | 317 |
* Retrieves the root node from @message. |
607 | 318 |
* |
1 | 319 |
* Return value: an #LmMessageNode |
320 |
**/ |
|
321 |
LmMessageNode * |
|
322 |
lm_message_get_node (LmMessage *message) |
|
323 |
{ |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
324 |
g_return_val_if_fail (message != NULL, NULL); |
607 | 325 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
326 |
return message->node; |
1 | 327 |
} |
328 |
||
329 |
/** |
|
330 |
* lm_message_ref: |
|
331 |
* @message: an #LmMessage |
|
607 | 332 |
* |
1 | 333 |
* Adds a reference to @message. |
607 | 334 |
* |
1 | 335 |
* Return value: the message |
336 |
**/ |
|
337 |
LmMessage * |
|
338 |
lm_message_ref (LmMessage *message) |
|
339 |
{ |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
340 |
g_return_val_if_fail (message != NULL, NULL); |
607 | 341 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
342 |
PRIV(message)->ref_count++; |
607 | 343 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
344 |
return message; |
1 | 345 |
} |
346 |
||
347 |
/** |
|
348 |
* lm_message_unref: |
|
349 |
* @message: an #LmMessage |
|
607 | 350 |
* |
351 |
* Removes a reference from @message. When no more references are present the |
|
1 | 352 |
* message is freed. |
353 |
**/ |
|
354 |
void |
|
355 |
lm_message_unref (LmMessage *message) |
|
356 |
{ |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
357 |
g_return_if_fail (message != NULL); |
1 | 358 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
359 |
PRIV(message)->ref_count--; |
607 | 360 |
|
518
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
361 |
if (PRIV(message)->ref_count == 0) { |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
362 |
lm_message_node_unref (message->node); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
363 |
g_free (message->priv); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
364 |
g_free (message); |
cdd6a0c5b439
Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents:
516
diff
changeset
|
365 |
} |
1 | 366 |
} |