~ubuntu-branches/ubuntu/vivid/haproxy/vivid

« back to all changes in this revision

Viewing changes to include/common/chunk.h

  • Committer: Package Import Robot
  • Author(s): Apollon Oikonomopoulos
  • Date: 2014-06-20 11:05:17 UTC
  • mfrom: (1.1.15) (15.1.12 experimental)
  • Revision ID: package-import@ubuntu.com-20140620110517-u6q5p9kyy2f3ozw9
Tags: 1.5.0-1
* New upstream stable series. Notable changes since the 1.4 series:
  + Native SSL support on both sides with SNI/NPN/ALPN and OCSP stapling.
  + IPv6 and UNIX sockets are supported everywhere
  + End-to-end HTTP keep-alive for better support of NTLM and improved
    efficiency in static farms
  + HTTP/1.1 response compression (deflate, gzip) to save bandwidth
  + PROXY protocol versions 1 and 2 on both sides
  + Data sampling on everything in request or response, including payload
  + ACLs can use any matching method with any input sample
  + Maps and dynamic ACLs updatable from the CLI
  + Stick-tables support counters to track activity on any input sample
  + Custom format for logs, unique-id, header rewriting, and redirects
  + Improved health checks (SSL, scripted TCP, check agent, ...)
  + Much more scalable configuration supports hundreds of thousands of
    backends and certificates without sweating

* Upload to unstable, merge all 1.5 work from experimental. Most important
  packaging changes since 1.4.25-1 include:
  + systemd support.
  + A more sane default config file.
  + Zero-downtime upgrades between 1.5 releases by gracefully reloading
    HAProxy during upgrades.
  + HTML documentation shipped in the haproxy-doc package.
  + kqueue support for kfreebsd.

* Packaging changes since 1.5~dev26-2:
  + Drop patches merged upstream:
    o Fix-reference-location-in-manpage.patch
    o 0001-BUILD-stats-workaround-stupid-and-bogus-Werror-forma.patch
  + d/watch: look for stable 1.5 releases
  + systemd: respect CONFIG and EXTRAOPTS when specified in
    /etc/default/haproxy.
  + initscript: test the configuration before start or reload.
  + initscript: remove the ENABLED flag and logic.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * include/common/chunk.h
 
3
 * Chunk management definitions, macros and inline functions.
 
4
 *
 
5
 * Copyright (C) 2000-2012 Willy Tarreau - w@1wt.eu
 
6
 *
 
7
 * This library is free software; you can redistribute it and/or
 
8
 * modify it under the terms of the GNU Lesser General Public
 
9
 * License as published by the Free Software Foundation, version 2.1
 
10
 * exclusively.
 
11
 *
 
12
 * This library is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
 * Lesser General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU Lesser General Public
 
18
 * License along with this library; if not, write to the Free Software
 
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
20
 */
 
21
 
 
22
#ifndef _TYPES_CHUNK_H
 
23
#define _TYPES_CHUNK_H
 
24
 
 
25
#include <stdlib.h>
 
26
#include <string.h>
 
27
 
 
28
#include <common/config.h>
 
29
 
 
30
 
 
31
/* describes a chunk of string */
 
32
struct chunk {
 
33
        char *str;      /* beginning of the string itself. Might not be 0-terminated */
 
34
        int size;       /* total size of the buffer, 0 if the *str is read-only */
 
35
        int len;        /* current size of the string from first to last char. <0 = uninit. */
 
36
};
 
37
 
 
38
/* function prototypes */
 
39
 
 
40
int chunk_printf(struct chunk *chk, const char *fmt, ...)
 
41
        __attribute__ ((format(printf, 2, 3)));
 
42
 
 
43
int chunk_appendf(struct chunk *chk, const char *fmt, ...)
 
44
        __attribute__ ((format(printf, 2, 3)));
 
45
 
 
46
int chunk_htmlencode(struct chunk *dst, struct chunk *src);
 
47
int chunk_asciiencode(struct chunk *dst, struct chunk *src, char qc);
 
48
int chunk_strcmp(const struct chunk *chk, const char *str);
 
49
int chunk_strcasecmp(const struct chunk *chk, const char *str);
 
50
int alloc_trash_buffers(int bufsize);
 
51
struct chunk *get_trash_chunk(void);
 
52
 
 
53
static inline void chunk_reset(struct chunk *chk)
 
54
{
 
55
        chk->len  = 0;
 
56
}
 
57
 
 
58
static inline void chunk_init(struct chunk *chk, char *str, size_t size)
 
59
{
 
60
        chk->str  = str;
 
61
        chk->len  = 0;
 
62
        chk->size = size;
 
63
}
 
64
 
 
65
/* report 0 in case of error, 1 if OK. */
 
66
static inline int chunk_initlen(struct chunk *chk, char *str, size_t size, int len)
 
67
{
 
68
 
 
69
        if (size && len > size)
 
70
                return 0;
 
71
 
 
72
        chk->str  = str;
 
73
        chk->len  = len;
 
74
        chk->size = size;
 
75
 
 
76
        return 1;
 
77
}
 
78
 
 
79
static inline void chunk_initstr(struct chunk *chk, char *str)
 
80
{
 
81
        chk->str = str;
 
82
        chk->len = strlen(str);
 
83
        chk->size = 0;                  /* mark it read-only */
 
84
}
 
85
 
 
86
static inline int chunk_strcpy(struct chunk *chk, const char *str)
 
87
{
 
88
        size_t len;
 
89
 
 
90
        len = strlen(str);
 
91
 
 
92
        if (unlikely(len > chk->size))
 
93
                return 0;
 
94
 
 
95
        chk->len  = len;
 
96
        memcpy(chk->str, str, len);
 
97
 
 
98
        return 1;
 
99
}
 
100
 
 
101
static inline void chunk_drop(struct chunk *chk)
 
102
{
 
103
        chk->str  = NULL;
 
104
        chk->len  = -1;
 
105
        chk->size = 0;
 
106
}
 
107
 
 
108
static inline void chunk_destroy(struct chunk *chk)
 
109
{
 
110
        if (!chk->size)
 
111
                return;
 
112
 
 
113
        free(chk->str);
 
114
        chunk_drop(chk);
 
115
}
 
116
 
 
117
/*
 
118
 * frees the destination chunk if already allocated, allocates a new string,
 
119
 * and copies the source into it. The pointer to the destination string is
 
120
 * returned, or NULL if the allocation fails or if any pointer is NULL..
 
121
 */
 
122
static inline char *chunk_dup(struct chunk *dst, const struct chunk *src)
 
123
{
 
124
        if (!dst || !src || !src->str)
 
125
                return NULL;
 
126
        if (dst->str)
 
127
                free(dst->str);
 
128
        dst->len = src->len;
 
129
        dst->str = (char *)malloc(dst->len);
 
130
        memcpy(dst->str, src->str, dst->len);
 
131
        return dst->str;
 
132
}
 
133
 
 
134
#endif /* _TYPES_CHUNK_H */
 
135
 
 
136
/*
 
137
 * Local variables:
 
138
 *  c-indent-level: 8
 
139
 *  c-basic-offset: 8
 
140
 * End:
 
141
 */