libevent
tag.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
3  * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 #ifndef EVENT2_TAG_H_INCLUDED_
28 #define EVENT2_TAG_H_INCLUDED_
29 
36 #include <event2/visibility.h>
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 #include <event2/event-config.h>
43 #ifdef EVENT__HAVE_SYS_TYPES_H
44 #include <sys/types.h>
45 #endif
46 #ifdef EVENT__HAVE_SYS_TIME_H
47 #include <sys/time.h>
48 #endif
49 
50 /* For int types. */
51 #include <event2/util.h>
52 
53 struct evbuffer;
54 
55 /*
56  * Marshaling tagged data - We assume that all tags are inserted in their
57  * numeric order - so that unknown tags will always be higher than the
58  * known ones - and we can just ignore the end of an event buffer.
59  */
60 
61 EVENT2_EXPORT_SYMBOL
62 void evtag_init(void);
63 
73 EVENT2_EXPORT_SYMBOL
74 int evtag_unmarshal_header(struct evbuffer *evbuf, ev_uint32_t *ptag);
75 
76 EVENT2_EXPORT_SYMBOL
77 void evtag_marshal(struct evbuffer *evbuf, ev_uint32_t tag, const void *data,
78  ev_uint32_t len);
79 EVENT2_EXPORT_SYMBOL
80 void evtag_marshal_buffer(struct evbuffer *evbuf, ev_uint32_t tag,
81  struct evbuffer *data);
82 
93 EVENT2_EXPORT_SYMBOL
94 void evtag_encode_int(struct evbuffer *evbuf, ev_uint32_t number);
95 EVENT2_EXPORT_SYMBOL
96 void evtag_encode_int64(struct evbuffer *evbuf, ev_uint64_t number);
97 
98 EVENT2_EXPORT_SYMBOL
99 void evtag_marshal_int(struct evbuffer *evbuf, ev_uint32_t tag,
100  ev_uint32_t integer);
101 EVENT2_EXPORT_SYMBOL
102 void evtag_marshal_int64(struct evbuffer *evbuf, ev_uint32_t tag,
103  ev_uint64_t integer);
104 
105 EVENT2_EXPORT_SYMBOL
106 void evtag_marshal_string(struct evbuffer *buf, ev_uint32_t tag,
107  const char *string);
108 
109 EVENT2_EXPORT_SYMBOL
110 void evtag_marshal_timeval(struct evbuffer *evbuf, ev_uint32_t tag,
111  struct timeval *tv);
112 
113 EVENT2_EXPORT_SYMBOL
114 int evtag_unmarshal(struct evbuffer *src, ev_uint32_t *ptag,
115  struct evbuffer *dst);
116 EVENT2_EXPORT_SYMBOL
117 int evtag_peek(struct evbuffer *evbuf, ev_uint32_t *ptag);
118 EVENT2_EXPORT_SYMBOL
119 int evtag_peek_length(struct evbuffer *evbuf, ev_uint32_t *plength);
120 EVENT2_EXPORT_SYMBOL
121 int evtag_payload_length(struct evbuffer *evbuf, ev_uint32_t *plength);
122 EVENT2_EXPORT_SYMBOL
123 int evtag_consume(struct evbuffer *evbuf);
124 
125 EVENT2_EXPORT_SYMBOL
126 int evtag_unmarshal_int(struct evbuffer *evbuf, ev_uint32_t need_tag,
127  ev_uint32_t *pinteger);
128 EVENT2_EXPORT_SYMBOL
129 int evtag_unmarshal_int64(struct evbuffer *evbuf, ev_uint32_t need_tag,
130  ev_uint64_t *pinteger);
131 
132 EVENT2_EXPORT_SYMBOL
133 int evtag_unmarshal_fixed(struct evbuffer *src, ev_uint32_t need_tag,
134  void *data, size_t len);
135 
136 EVENT2_EXPORT_SYMBOL
137 int evtag_unmarshal_string(struct evbuffer *evbuf, ev_uint32_t need_tag,
138  char **pstring);
139 
140 EVENT2_EXPORT_SYMBOL
141 int evtag_unmarshal_timeval(struct evbuffer *evbuf, ev_uint32_t need_tag,
142  struct timeval *ptv);
143 
144 #ifdef __cplusplus
145 }
146 #endif
147 
148 #endif /* EVENT2_TAG_H_INCLUDED_ */
EVENT2_EXPORT_SYMBOL int evtag_unmarshal_header(struct evbuffer *evbuf, ev_uint32_t *ptag)
Unmarshals the header and returns the length of the payload.
An evbuffer is an opaque data type for efficiently buffering data to be sent or received on the netwo...
Definition: buffer.h:97
Common convenience functions for cross-platform portability and related socket manipulations.
EVENT2_EXPORT_SYMBOL void evtag_encode_int(struct evbuffer *evbuf, ev_uint32_t number)
Encode an integer and store it in an evbuffer.