loudmouth/lm-message.c
author Jayson Vantuyl <jvantuyl@engineyard.com>
Wed, 25 Mar 2009 11:28:18 -0700
changeset 596 9096d2549372
parent 583 dfe3688d71c9
child 607 e2bd14357c9a
permissions -rw-r--r--
Removed Dangerous Instructions
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
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    16
 * License along with this program; if not, write to the
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    17
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    18
 * Boston, MA 02111-1307, USA.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    19
 */
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    20
417
364c17252e5f Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents: 331
diff changeset
    21
/**
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
    22
 * SECTION:lm-message
421
2a91651d22de Added Title to the inlined documentation
Mikael Hallendal <micke@imendio.com>
parents: 420
diff changeset
    23
 * @Title: LmMessage
417
364c17252e5f Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents: 331
diff changeset
    24
 * @Short_description: A message is built up like a tree of message nodes.
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
 * 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
    27
 */
364c17252e5f Added inlined documentation from generated through the Gtk-doc migration script.
Mikael Hallendal <micke@imendio.com>
parents: 331
diff changeset
    28
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    29
#include <config.h>
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    30
#include <string.h>
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    31
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    32
#include "lm-internals.h"
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    33
#include "lm-message.h"
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    34
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    35
#define PRIV(o) ((LmMessage *)o)->priv
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    36
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    37
static struct TypeNames 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    38
{
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
    39
    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
    40
    const gchar   *name;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    41
} 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
    42
    { 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
    43
    { 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
    44
    { 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
    45
    { 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
    46
    { 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
    47
    { 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
    48
    { 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
    49
    { 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
    50
    { 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
    51
    { 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
    52
    { 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
    53
    { 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
    54
    { 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
    55
    { LM_MESSAGE_TYPE_UNKNOWN,         NULL              }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    56
};
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    57
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    58
static struct SubTypeNames 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    59
{
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
    60
    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
    61
    const gchar      *name;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    62
} 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
    63
    { 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
    64
    { 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
    65
    { 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
    66
    { 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
    67
    { 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
    68
    { 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
    69
    { 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
    70
    { 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
    71
    { 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
    72
    { 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
    73
    { 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
    74
    { LM_MESSAGE_SUB_TYPE_SET,             "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
    75
    { LM_MESSAGE_SUB_TYPE_RESULT,          "result"        }, 
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    76
    { LM_MESSAGE_SUB_TYPE_ERROR,           "error"         }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    77
};
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    78
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    79
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
    80
    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
    81
    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
    82
    gint             ref_count;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    83
};
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    84
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    85
static LmMessageType
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    86
message_type_from_string (const gchar *type_str)
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
    gint i;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    89
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
    90
    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
    91
        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
    92
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
    93
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
    94
    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
    95
         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
    96
         ++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
    97
        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
    98
            return type_names[i].type;
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
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   101
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
   102
    return LM_MESSAGE_TYPE_UNKNOWN;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   103
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   104
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   105
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   106
const gchar *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   107
_lm_message_type_to_string (LmMessageType type)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   108
{
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
   109
    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
   110
        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
   111
        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
   112
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   113
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
   114
    return type_names[type].name;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   115
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   116
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   117
static LmMessageSubType
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   118
message_sub_type_from_string (const gchar *type_str)
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
    gint i;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   121
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
   122
    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
   123
        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
   124
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   125
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
   126
    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
   127
         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
   128
         ++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
   129
        if (g_ascii_strcasecmp (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
   130
                                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
   131
            return i;
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
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   134
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
   135
    return LM_MESSAGE_SUB_TYPE_NOT_SET;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   136
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   137
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   138
const gchar *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   139
_lm_message_sub_type_to_string (LmMessageSubType type)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   140
{
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
   141
    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
   142
        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
   143
        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
   144
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   145
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
   146
    return sub_type_names[type].name;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   147
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   148
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   149
static LmMessageSubType
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   150
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
   151
    LmMessageSubType sub_type = LM_MESSAGE_SUB_TYPE_NORMAL;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   152
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
   153
    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
   154
    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
   155
        /* 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
   156
         * 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
   157
         * 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
   158
         */
cdd6a0c5b439 Went 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
        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
   160
        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
   161
    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
   162
        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
   163
        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
   164
    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
   165
        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
   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
    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
   168
        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
   169
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   170
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
   171
    return sub_type;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   172
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   173
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   174
LmMessage *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   175
_lm_message_new_from_node (LmMessageNode *node)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   176
{
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
   177
    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
   178
    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
   179
    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
   180
    const gchar      *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
   181
    
cdd6a0c5b439 Went 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
    type = message_type_from_string (node->name);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   183
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
   184
    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
   185
        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
   186
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   187
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
   188
    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
   189
    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
   190
        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
   191
    } 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
   192
        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
   193
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   194
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
   195
    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
   196
    m->priv = g_new0 (LmMessagePriv, 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
    
cdd6a0c5b439 Went 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)->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
   199
    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
   200
    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
   201
    
cdd6a0c5b439 Went 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
    m->node = lm_message_node_ref (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
   203
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   204
    return m;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   205
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   206
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   207
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   208
 * lm_message_new:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   209
 * @to: receipient jid
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   210
 * @type: message type
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   211
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   212
 * Creates a new #LmMessage which can be sent with lm_connection_send() or 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   213
 * lm_connection_send_with_reply(). If @to is %NULL the message is sent to the
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   214
 * server. The returned message should be unreferenced with lm_message_unref() 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   215
 * when caller is finished with it.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   216
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   217
 * Return value: a newly created #LmMessage
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   218
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   219
LmMessage *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   220
lm_message_new (const gchar *to, LmMessageType type)
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   221
{
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
   222
    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
   223
    gchar     *id;
79
63971f168ce6 2004-01-29 Richard Hult <richard@imendio.com>
rhult <rhult>
parents: 57
diff changeset
   224
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
   225
    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
   226
    m->priv = g_new0 (LmMessagePriv, 1);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   227
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
   228
    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
   229
    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
   230
    PRIV(m)->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
   231
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   232
    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
   233
558
e5b7f24779c9 Don't append the 'id'-tag in opening stream headers. [#30]
Will Thompson <will.thompson@collabora.co.uk>
parents: 518
diff changeset
   234
    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
   235
        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
   236
        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
   237
        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
   238
    }
e5b7f24779c9 Don't append the 'id'-tag in opening stream headers. [#30]
Will Thompson <will.thompson@collabora.co.uk>
parents: 518
diff changeset
   239
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
   240
    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
   241
        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
   242
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   243
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
   244
    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
   245
        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
   246
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   247
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   248
    return m;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   249
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   250
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   251
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   252
 * lm_message_new_with_sub_type:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   253
 * @to: receipient jid
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   254
 * @type: message type
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   255
 * @sub_type: message sub type
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   256
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   257
 * Creates a new #LmMessage with sub type set. See lm_message_new() for more 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   258
 * information.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   259
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   260
 * Return value: a newly created #LmMessage
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   261
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   262
LmMessage *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   263
lm_message_new_with_sub_type (const gchar      *to,
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
   264
                              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
   265
                              LmMessageSubType  sub_type)
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   266
{
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
   267
    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
   268
    const gchar *type_str;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
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
    m = lm_message_new (to, type);
79
63971f168ce6 2004-01-29 Richard Hult <richard@imendio.com>
rhult <rhult>
parents: 57
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
    type_str = _lm_message_sub_type_to_string (sub_type);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   273
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
   274
    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
   275
        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
   276
                                        "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
   277
        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
   278
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   279
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
   280
    return m;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   281
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   282
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   283
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   284
 * lm_message_get_type:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   285
 * @message: an #LmMessage
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   286
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   287
 * Fetches the type of @message.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   288
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   289
 * Return value: the message type
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   290
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   291
LmMessageType
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   292
lm_message_get_type (LmMessage *message)
50e230cf7818 Initial revision
hallski <hallski>
parents:
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
    g_return_val_if_fail (message != NULL, 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
   295
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   296
    return PRIV(message)->type;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   297
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   298
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   299
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   300
 * lm_message_get_sub_type:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   301
 * @message: 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   302
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   303
 * Fetches the sub type of @message.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   304
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   305
 * Return value: the message sub type
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   306
 **/
8
33d64cf345be 2003-06-15 Mikael Hallendal <micke@imendio.com>
hallski <hallski>
parents: 7
diff changeset
   307
LmMessageSubType
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   308
lm_message_get_sub_type (LmMessage *message)
50e230cf7818 Initial revision
hallski <hallski>
parents:
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
    g_return_val_if_fail (message != NULL, 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
   311
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   312
    return PRIV(message)->sub_type;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   313
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   314
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   315
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   316
 * lm_message_get_node:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   317
 * @message: an #LmMessage
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   318
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   319
 * Retrieves the root node from @message.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   320
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   321
 * Return value: an #LmMessageNode
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   322
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   323
LmMessageNode *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   324
lm_message_get_node (LmMessage *message)
50e230cf7818 Initial revision
hallski <hallski>
parents:
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
    g_return_val_if_fail (message != NULL, 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
   327
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   328
    return message->node;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   329
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   330
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   331
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   332
 * lm_message_ref:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   333
 * @message: an #LmMessage
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   334
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   335
 * Adds a reference to @message.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   336
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   337
 * Return value: the message
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   338
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   339
LmMessage *
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   340
lm_message_ref (LmMessage *message)
50e230cf7818 Initial revision
hallski <hallski>
parents:
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
    g_return_val_if_fail (message != NULL, 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
   343
    
cdd6a0c5b439 Went 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
    PRIV(message)->ref_count++;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   345
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   346
    return message;
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   347
}
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   348
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   349
/**
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   350
 * lm_message_unref:
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   351
 * @message: an #LmMessage
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   352
 * 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   353
 * Removes a reference from @message. When no more references are present the 
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   354
 * message is freed.
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   355
 **/
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   356
void
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   357
lm_message_unref (LmMessage *message)
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
    g_return_if_fail (message != NULL);
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
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
    PRIV(message)->ref_count--;
cdd6a0c5b439 Went 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
    
cdd6a0c5b439 Went 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
    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
   364
        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
   365
        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
   366
        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
   367
    }
1
50e230cf7818 Initial revision
hallski <hallski>
parents:
diff changeset
   368
}