loudmouth/lm-message.c
author Mikael Berthe <mikael@lilotux.net>
Mon, 25 Jan 2021 20:59:00 +0100
changeset 740 f1bb5e7e9477
parent 713 ecfbb3961c19
permissions -rw-r--r--
Bump version to 1.5.4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
     2
/*
99
81e9d035de02 2004-10-05 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 84
diff changeset
     3
 * Copyright (C) 2003 Imendio AB
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
     4
 *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
     6
 * modify it under the terms of the GNU Lesser General Public License as
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
     7
 * published by the Free Software Foundation; either version 2 of the
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
     8
 * License, or (at your option) any later version.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
     9
 *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    13
 * Lesser General Public License for more details.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    14
 *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    17
 */
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    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
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
    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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    27
#include <config.h>
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    28
#include <string.h>
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    29
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    30
#include "lm-internals.h"
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    31
#include "lm-message.h"
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    32
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    33
#define PRIV(o) ((LmMessage *)o)->priv
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    34
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
    35
static struct TypeNames
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    54
};
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    55
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
    56
static struct SubTypeNames
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    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
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
    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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    75
};
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    76
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    81
};
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    82
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    83
static LmMessageType
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    84
message_type_from_string (const gchar *type_str)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   101
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   102
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   103
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   104
const gchar *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   105
_lm_message_type_to_string (LmMessageType type)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   113
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   114
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   115
static LmMessageSubType
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   116
message_sub_type_from_string (const gchar *type_str)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   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
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
   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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   134
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   135
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   136
const gchar *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   137
_lm_message_sub_type_to_string (LmMessageSubType type)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   145
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   146
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   147
static LmMessageSubType
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   170
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   171
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   172
LmMessage *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   173
_lm_message_new_from_node (LmMessageNode *node)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   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
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
   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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   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
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
   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
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
   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
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
   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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   203
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   204
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   205
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   206
 * lm_message_new:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   207
 * @to: receipient jid
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   208
 * @type: message type
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
   209
 *
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
   210
 * Creates a new #LmMessage which can be sent with lm_connection_send() or
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   211
 * lm_connection_send_with_reply(). If @to is %NULL the message is sent to the
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
   212
 * server. The returned message should be unreferenced with lm_message_unref()
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   213
 * when caller is finished with it.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
   214
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   215
 * Return value: a newly created #LmMessage
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   216
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   217
LmMessage *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   218
lm_message_new (const gchar *to, LmMessageType type)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   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
63971f168ce6 2004-01-29 Richard Hult <richard@imendio.com>
rhult <rhult>
parents: 57
diff changeset
   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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   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
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
   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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   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
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
   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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   247
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   248
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   249
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   250
 * lm_message_new_with_sub_type:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   251
 * @to: receipient jid
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   252
 * @type: message type
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   253
 * @sub_type: message sub type
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
   254
 *
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
   255
 * Creates a new #LmMessage with sub type set. See lm_message_new() for more
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   256
 * information.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
   257
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   258
 * Return value: a newly created #LmMessage
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   259
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   260
LmMessage *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   261
lm_message_new_with_sub_type (const gchar      *to,
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
   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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   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
63971f168ce6 2004-01-29 Richard Hult <richard@imendio.com>
rhult <rhult>
parents: 57
diff changeset
   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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   279
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   280
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   281
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   282
 * lm_message_get_type:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   283
 * @message: an #LmMessage
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
   284
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   285
 * Fetches the type of @message.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
   286
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   287
 * Return value: the message type
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   288
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   289
LmMessageType
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   290
lm_message_get_type (LmMessage *message)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   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
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
   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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   295
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   296
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   297
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   298
 * lm_message_get_sub_type:
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
   299
 * @message:
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
   300
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   301
 * Fetches the sub type of @message.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
   302
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   303
 * Return value: the message sub type
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   304
 **/
8
33d64cf345be 2003-06-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 7
diff changeset
   305
LmMessageSubType
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   306
lm_message_get_sub_type (LmMessage *message)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   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
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
   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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   311
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   312
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   313
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   314
 * lm_message_get_node:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   315
 * @message: an #LmMessage
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
   316
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   317
 * Retrieves the root node from @message.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
   318
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   319
 * Return value: an #LmMessageNode
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   320
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   321
LmMessageNode *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   322
lm_message_get_node (LmMessage *message)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   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
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
   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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   327
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   328
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   329
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   330
 * lm_message_ref:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   331
 * @message: an #LmMessage
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
   332
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   333
 * Adds a reference to @message.
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
   334
 *
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   335
 * Return value: the message
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   336
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   337
LmMessage *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   338
lm_message_ref (LmMessage *message)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   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
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
   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
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
   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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   345
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   346
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   347
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   348
 * lm_message_unref:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   349
 * @message: an #LmMessage
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
   350
 *
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
   351
 * Removes a reference from @message. When no more references are present the
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   352
 * message is freed.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   353
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   354
void
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   355
lm_message_unref (LmMessage *message)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   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
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 583
diff changeset
   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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   366
}