dbus-marshal-header.h 7 KB
Newer Older
1
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/* dbus-marshal-header.h  Managing marshaling/demarshaling of message headers
 *
 * Copyright (C) 2005  Red Hat, Inc.
 *
 * Licensed under the Academic Free License version 2.1
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
 *
 */

#ifndef DBUS_MARSHAL_HEADER_H
#define DBUS_MARSHAL_HEADER_H

#include <dbus/dbus-marshal-basic.h>
#include <dbus/dbus-marshal-validate.h>

typedef struct DBusHeader      DBusHeader;
typedef struct DBusHeaderField DBusHeaderField;

#define _DBUS_HEADER_FIELD_VALUE_UNKNOWN -1
#define _DBUS_HEADER_FIELD_VALUE_NONEXISTENT -2

/**
 * Cached information about a header field in the message
 */
struct DBusHeaderField
{
  int            value_pos; /**< Position of field value, or -1/-2 */
};

44 45 46
/**
 * Message header data and some cached details of it.
 */
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
struct DBusHeader
{
  DBusString data; /**< Header network data, stored
                    * separately from body so we can
                    * independently realloc it.
                    */

  DBusHeaderField fields[DBUS_HEADER_FIELD_LAST + 1]; /**< Track the location
                                                       * of each field in header
                                                       */

  dbus_uint32_t padding : 3;        /**< bytes of alignment in header */
  dbus_uint32_t byte_order : 8;     /**< byte order of header */
};

62
dbus_bool_t   _dbus_header_init                   (DBusHeader        *header);
63
void          _dbus_header_free                   (DBusHeader        *header);
64
void          _dbus_header_reinit                 (DBusHeader        *header);
65
dbus_bool_t   _dbus_header_create                 (DBusHeader        *header,
66
                                                   int                byte_order,
67 68 69 70 71 72 73 74 75 76 77 78 79 80
                                                   int                type,
                                                   const char        *destination,
                                                   const char        *path,
                                                   const char        *interface,
                                                   const char        *member,
                                                   const char        *error_name);
dbus_bool_t   _dbus_header_copy                   (const DBusHeader  *header,
                                                   DBusHeader        *dest);
int           _dbus_header_get_message_type       (DBusHeader        *header);
void          _dbus_header_set_serial             (DBusHeader        *header,
                                                   dbus_uint32_t      serial);
dbus_uint32_t _dbus_header_get_serial             (DBusHeader        *header);
void          _dbus_header_update_lengths         (DBusHeader        *header,
                                                   int                body_len);
81
DBUS_PRIVATE_EXPORT
82 83 84 85 86 87 88 89
dbus_bool_t   _dbus_header_set_field_basic        (DBusHeader        *header,
                                                   int                field,
                                                   int                type,
                                                   const void        *value);
dbus_bool_t   _dbus_header_get_field_basic        (DBusHeader        *header,
                                                   int                field,
                                                   int                type,
                                                   void              *value);
90
DBUS_PRIVATE_EXPORT
91 92 93 94
dbus_bool_t   _dbus_header_get_field_raw          (DBusHeader        *header,
                                                   int                field,
                                                   const DBusString **str,
                                                   int               *pos);
95
DBUS_PRIVATE_EXPORT
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
dbus_bool_t   _dbus_header_delete_field           (DBusHeader        *header,
                                                   int                field);
void          _dbus_header_toggle_flag            (DBusHeader        *header,
                                                   dbus_uint32_t      flag,
                                                   dbus_bool_t        value);
dbus_bool_t   _dbus_header_get_flag               (DBusHeader        *header,
                                                   dbus_uint32_t      flag);
dbus_bool_t   _dbus_header_ensure_signature       (DBusHeader        *header,
                                                   DBusString       **type_str,
                                                   int               *type_pos);
dbus_bool_t   _dbus_header_have_message_untrusted (int                max_message_length,
                                                   DBusValidity      *validity,
                                                   int               *byte_order,
                                                   int               *fields_array_len,
                                                   int               *header_len,
                                                   int               *body_len,
                                                   const DBusString  *str,
                                                   int                start,
                                                   int                len);
115 116
dbus_bool_t   _dbus_header_load                   (DBusHeader        *header,
                                                   DBusValidationMode mode,
117 118 119 120 121 122 123 124
                                                   DBusValidity      *validity,
                                                   int                byte_order,
                                                   int                fields_array_len,
                                                   int                header_len,
                                                   int                body_len,
                                                   const DBusString  *str,
                                                   int                start,
                                                   int                len);
125 126
void          _dbus_header_byteswap               (DBusHeader        *header,
                                                   int                new_order);
127
DBUS_PRIVATE_EXPORT
128
char          _dbus_header_get_byte_order         (const DBusHeader  *header);
129 130 131 132



#endif /* DBUS_MARSHAL_HEADER_H */