Home | History | Annotate | Download | only in dbus
      1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
      2 /* dbus-marshal-header.h  Managing marshaling/demarshaling of message headers
      3  *
      4  * Copyright (C) 2005  Red Hat, Inc.
      5  *
      6  * Licensed under the Academic Free License version 2.1
      7  *
      8  * This program is free software; you can redistribute it and/or modify
      9  * it under the terms of the GNU General Public License as published by
     10  * the Free Software Foundation; either version 2 of the License, or
     11  * (at your option) any later version.
     12  *
     13  * This program is distributed in the hope that it will be useful,
     14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16  * GNU General Public License for more details.
     17  *
     18  * You should have received a copy of the GNU General Public License
     19  * 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 #ifndef DBUS_MARSHAL_HEADER_H
     25 #define DBUS_MARSHAL_HEADER_H
     26 
     27 #include <dbus/dbus-marshal-basic.h>
     28 #include <dbus/dbus-marshal-validate.h>
     29 
     30 typedef struct DBusHeader      DBusHeader;
     31 typedef struct DBusHeaderField DBusHeaderField;
     32 
     33 #define _DBUS_HEADER_FIELD_VALUE_UNKNOWN -1
     34 #define _DBUS_HEADER_FIELD_VALUE_NONEXISTENT -2
     35 
     36 /**
     37  * Cached information about a header field in the message
     38  */
     39 struct DBusHeaderField
     40 {
     41   int            value_pos; /**< Position of field value, or -1/-2 */
     42 };
     43 
     44 /**
     45  * Message header data and some cached details of it.
     46  */
     47 struct DBusHeader
     48 {
     49   DBusString data; /**< Header network data, stored
     50                     * separately from body so we can
     51                     * independently realloc it.
     52                     */
     53 
     54   DBusHeaderField fields[DBUS_HEADER_FIELD_LAST + 1]; /**< Track the location
     55                                                        * of each field in header
     56                                                        */
     57 
     58   dbus_uint32_t padding : 3;        /**< bytes of alignment in header */
     59   dbus_uint32_t byte_order : 8;     /**< byte order of header */
     60 };
     61 
     62 dbus_bool_t   _dbus_header_init                   (DBusHeader        *header,
     63                                                    int                byte_order);
     64 void          _dbus_header_free                   (DBusHeader        *header);
     65 void          _dbus_header_reinit                 (DBusHeader        *header,
     66                                                    int                byte_order);
     67 dbus_bool_t   _dbus_header_create                 (DBusHeader        *header,
     68                                                    int                type,
     69                                                    const char        *destination,
     70                                                    const char        *path,
     71                                                    const char        *interface,
     72                                                    const char        *member,
     73                                                    const char        *error_name);
     74 dbus_bool_t   _dbus_header_copy                   (const DBusHeader  *header,
     75                                                    DBusHeader        *dest);
     76 int           _dbus_header_get_message_type       (DBusHeader        *header);
     77 void          _dbus_header_set_serial             (DBusHeader        *header,
     78                                                    dbus_uint32_t      serial);
     79 dbus_uint32_t _dbus_header_get_serial             (DBusHeader        *header);
     80 void          _dbus_header_update_lengths         (DBusHeader        *header,
     81                                                    int                body_len);
     82 dbus_bool_t   _dbus_header_set_field_basic        (DBusHeader        *header,
     83                                                    int                field,
     84                                                    int                type,
     85                                                    const void        *value);
     86 dbus_bool_t   _dbus_header_get_field_basic        (DBusHeader        *header,
     87                                                    int                field,
     88                                                    int                type,
     89                                                    void              *value);
     90 dbus_bool_t   _dbus_header_get_field_raw          (DBusHeader        *header,
     91                                                    int                field,
     92                                                    const DBusString **str,
     93                                                    int               *pos);
     94 dbus_bool_t   _dbus_header_delete_field           (DBusHeader        *header,
     95                                                    int                field);
     96 void          _dbus_header_toggle_flag            (DBusHeader        *header,
     97                                                    dbus_uint32_t      flag,
     98                                                    dbus_bool_t        value);
     99 dbus_bool_t   _dbus_header_get_flag               (DBusHeader        *header,
    100                                                    dbus_uint32_t      flag);
    101 dbus_bool_t   _dbus_header_ensure_signature       (DBusHeader        *header,
    102                                                    DBusString       **type_str,
    103                                                    int               *type_pos);
    104 dbus_bool_t   _dbus_header_have_message_untrusted (int                max_message_length,
    105                                                    DBusValidity      *validity,
    106                                                    int               *byte_order,
    107                                                    int               *fields_array_len,
    108                                                    int               *header_len,
    109                                                    int               *body_len,
    110                                                    const DBusString  *str,
    111                                                    int                start,
    112                                                    int                len);
    113 dbus_bool_t   _dbus_header_load                   (DBusHeader        *header,
    114                                                    DBusValidationMode mode,
    115                                                    DBusValidity      *validity,
    116                                                    int                byte_order,
    117                                                    int                fields_array_len,
    118                                                    int                header_len,
    119                                                    int                body_len,
    120                                                    const DBusString  *str,
    121                                                    int                start,
    122                                                    int                len);
    123 void          _dbus_header_byteswap               (DBusHeader        *header,
    124                                                    int                new_order);
    125 
    126 
    127 
    128 #endif /* DBUS_MARSHAL_HEADER_H */
    129