libevent
include/event2/tag.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
00003  * Copyright (c) 2007-2010 Niels Provos and Nick Mathewson
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. The name of the author may not be used to endorse or promote products
00014  *    derived from this software without specific prior written permission.
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00017  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00018  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00019  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00020  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00021  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00022  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00023  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00025  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  */
00027 #ifndef _EVENT2_TAG_H_
00028 #define _EVENT2_TAG_H_
00029 
00036 #ifdef __cplusplus
00037 extern "C" {
00038 #endif
00039 
00040 #include <event2/event-config.h>
00041 #ifdef _EVENT_HAVE_SYS_TYPES_H
00042 #include <sys/types.h>
00043 #endif
00044 #ifdef _EVENT_HAVE_SYS_TIME_H
00045 #include <sys/time.h>
00046 #endif
00047 
00048 /* For int types. */
00049 #include <event2/util.h>
00050 
00051 struct evbuffer;
00052 
00053 /*
00054  * Marshaling tagged data - We assume that all tags are inserted in their
00055  * numeric order - so that unknown tags will always be higher than the
00056  * known ones - and we can just ignore the end of an event buffer.
00057  */
00058 
00059 void evtag_init(void);
00060 
00068 int evtag_unmarshal_header(struct evbuffer *evbuf, ev_uint32_t *ptag);
00069 
00070 void evtag_marshal(struct evbuffer *evbuf, ev_uint32_t tag, const void *data,
00071     ev_uint32_t len);
00072 void evtag_marshal_buffer(struct evbuffer *evbuf, ev_uint32_t tag,
00073     struct evbuffer *data);
00074 
00085 void evtag_encode_int(struct evbuffer *evbuf, ev_uint32_t number);
00086 void evtag_encode_int64(struct evbuffer *evbuf, ev_uint64_t number);
00087 
00088 void evtag_marshal_int(struct evbuffer *evbuf, ev_uint32_t tag,
00089     ev_uint32_t integer);
00090 void evtag_marshal_int64(struct evbuffer *evbuf, ev_uint32_t tag,
00091     ev_uint64_t integer);
00092 
00093 void evtag_marshal_string(struct evbuffer *buf, ev_uint32_t tag,
00094     const char *string);
00095 
00096 void evtag_marshal_timeval(struct evbuffer *evbuf, ev_uint32_t tag,
00097     struct timeval *tv);
00098 
00099 int evtag_unmarshal(struct evbuffer *src, ev_uint32_t *ptag,
00100     struct evbuffer *dst);
00101 int evtag_peek(struct evbuffer *evbuf, ev_uint32_t *ptag);
00102 int evtag_peek_length(struct evbuffer *evbuf, ev_uint32_t *plength);
00103 int evtag_payload_length(struct evbuffer *evbuf, ev_uint32_t *plength);
00104 int evtag_consume(struct evbuffer *evbuf);
00105 
00106 int evtag_unmarshal_int(struct evbuffer *evbuf, ev_uint32_t need_tag,
00107     ev_uint32_t *pinteger);
00108 int evtag_unmarshal_int64(struct evbuffer *evbuf, ev_uint32_t need_tag,
00109     ev_uint64_t *pinteger);
00110 
00111 int evtag_unmarshal_fixed(struct evbuffer *src, ev_uint32_t need_tag,
00112     void *data, size_t len);
00113 
00114 int evtag_unmarshal_string(struct evbuffer *evbuf, ev_uint32_t need_tag,
00115     char **pstring);
00116 
00117 int evtag_unmarshal_timeval(struct evbuffer *evbuf, ev_uint32_t need_tag,
00118     struct timeval *ptv);
00119 
00120 #ifdef __cplusplus
00121 }
00122 #endif
00123 
00124 #endif /* _EVENT2_TAG_H_ */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines