]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/string-private.h
Update HTTP implementation to support field values larger than HTTP_MAX_VALUE
[thirdparty/cups.git] / cups / string-private.h
CommitLineData
ef416fc2 1/*
554aa7b7 2 * Private string definitions for CUPS.
ef416fc2 3 *
59189c00 4 * Copyright 2007-2015 by Apple Inc.
554aa7b7 5 * Copyright 1997-2006 by Easy Software Products.
ef416fc2 6 *
e3101897 7 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
ef416fc2 8 */
9
71e16022
MS
10#ifndef _CUPS_STRING_PRIVATE_H_
11# define _CUPS_STRING_PRIVATE_H_
ef416fc2 12
13/*
14 * Include necessary headers...
15 */
16
ef416fc2 17# include <stdio.h>
a74454a7 18# include <stdlib.h>
ef416fc2 19# include <stdarg.h>
20# include <ctype.h>
71e16022 21# include <errno.h>
757d2cad 22# include <locale.h>
554aa7b7 23# include <time.h>
ef416fc2 24
71e16022 25# include "config.h"
a74454a7 26
ef416fc2 27# ifdef HAVE_STRING_H
28# include <string.h>
29# endif /* HAVE_STRING_H */
30
31# ifdef HAVE_STRINGS_H
32# include <strings.h>
33# endif /* HAVE_STRINGS_H */
34
35# ifdef HAVE_BSTRING_H
36# include <bstring.h>
37# endif /* HAVE_BSTRING_H */
38
21aa3f37
MS
39# if defined(WIN32) && !defined(__CUPS_SSIZE_T_DEFINED)
40# define __CUPS_SSIZE_T_DEFINED
41# include <stddef.h>
42/* Windows does not support the ssize_t type, so map it to long... */
43typedef long ssize_t; /* @private@ */
44# endif /* WIN32 && !__CUPS_SSIZE_T_DEFINED */
45
ef416fc2 46
ef416fc2 47/*
48 * C++ magic...
49 */
50
51# ifdef __cplusplus
52extern "C" {
53# endif /* __cplusplus */
54
55
4400e98d 56/*
57 * String pool structures...
58 */
59
745129be
MS
60# define _CUPS_STR_GUARD 0x12344321
61
4400e98d 62typedef struct _cups_sp_item_s /**** String Pool Item ****/
63{
745129be
MS
64# ifdef DEBUG_GUARDS
65 unsigned int guard; /* Guard word */
66# endif /* DEBUG_GUARDS */
4400e98d 67 unsigned int ref_count; /* Reference count */
426c6a59 68 char str[1]; /* String */
4400e98d 69} _cups_sp_item_t;
70
71
7cf5915e
MS
72/*
73 * Replacements for the ctype macros that are not affected by locale, since we
74 * really only care about testing for ASCII characters when parsing files, etc.
7cf5915e
MS
75 *
76 * The _CUPS_INLINE definition controls whether we get an inline function body,
77 * and external function body, or an external definition.
78 */
79
80# if defined(__GNUC__) || __STDC_VERSION__ >= 199901L
81# define _CUPS_INLINE static inline
82# elif defined(_MSC_VER)
83# define _CUPS_INLINE static __inline
84# elif defined(_CUPS_STRING_C_)
85# define _CUPS_INLINE
86# endif /* __GNUC__ || __STDC_VERSION__ */
87
88# ifdef _CUPS_INLINE
89_CUPS_INLINE int /* O - 1 on match, 0 otherwise */
90_cups_isalnum(int ch) /* I - Character to test */
91{
92 return ((ch >= '0' && ch <= '9') ||
93 (ch >= 'A' && ch <= 'Z') ||
94 (ch >= 'a' && ch <= 'z'));
95}
96
97_CUPS_INLINE int /* O - 1 on match, 0 otherwise */
98_cups_isalpha(int ch) /* I - Character to test */
99{
100 return ((ch >= 'A' && ch <= 'Z') ||
101 (ch >= 'a' && ch <= 'z'));
102}
103
2d0a0f48
MS
104_CUPS_INLINE int /* O - 1 on match, 0 otherwise */
105_cups_islower(int ch) /* I - Character to test */
106{
107 return (ch >= 'a' && ch <= 'z');
108}
109
7cf5915e
MS
110_CUPS_INLINE int /* O - 1 on match, 0 otherwise */
111_cups_isspace(int ch) /* I - Character to test */
112{
113 return (ch == ' ' || ch == '\f' || ch == '\n' || ch == '\r' || ch == '\t' ||
114 ch == '\v');
115}
116
117_CUPS_INLINE int /* O - 1 on match, 0 otherwise */
118_cups_isupper(int ch) /* I - Character to test */
119{
120 return (ch >= 'A' && ch <= 'Z');
121}
88f9aafc
MS
122
123_CUPS_INLINE int /* O - Converted character */
124_cups_tolower(int ch) /* I - Character to convert */
125{
126 return (_cups_isupper(ch) ? ch - 'A' + 'a' : ch);
127}
2d0a0f48
MS
128
129_CUPS_INLINE int /* O - Converted character */
130_cups_toupper(int ch) /* I - Character to convert */
131{
132 return (_cups_islower(ch) ? ch - 'a' + 'A' : ch);
133}
7cf5915e
MS
134# else
135extern int _cups_isalnum(int ch);
136extern int _cups_isalpha(int ch);
2d0a0f48 137extern int _cups_islower(int ch);
7cf5915e
MS
138extern int _cups_isspace(int ch);
139extern int _cups_isupper(int ch);
88f9aafc 140extern int _cups_tolower(int ch);
2d0a0f48 141extern int _cups_toupper(int ch);
7cf5915e
MS
142# endif /* _CUPS_INLINE */
143
144
ef416fc2 145/*
146 * Prototypes...
147 */
148
59189c00 149extern ssize_t _cups_safe_vsnprintf(char *, size_t, const char *, va_list);
ef416fc2 150extern void _cups_strcpy(char *dst, const char *src);
151
152# ifndef HAVE_STRDUP
153extern char *_cups_strdup(const char *);
154# define strdup _cups_strdup
155# endif /* !HAVE_STRDUP */
156
ef416fc2 157extern int _cups_strcasecmp(const char *, const char *);
ef416fc2 158
ef416fc2 159extern int _cups_strncasecmp(const char *, const char *, size_t n);
ef416fc2 160
161# ifndef HAVE_STRLCAT
162extern size_t _cups_strlcat(char *, const char *, size_t);
163# define strlcat _cups_strlcat
164# endif /* !HAVE_STRLCAT */
165
166# ifndef HAVE_STRLCPY
167extern size_t _cups_strlcpy(char *, const char *, size_t);
168# define strlcpy _cups_strlcpy
169# endif /* !HAVE_STRLCPY */
170
171# ifndef HAVE_SNPRINTF
172extern int _cups_snprintf(char *, size_t, const char *, ...)
85dda01c 173 __attribute__ ((__format__ (__printf__, 3, 4)));
ef416fc2 174# define snprintf _cups_snprintf
175# endif /* !HAVE_SNPRINTF */
176
177# ifndef HAVE_VSNPRINTF
178extern int _cups_vsnprintf(char *, size_t, const char *, va_list);
179# define vsnprintf _cups_vsnprintf
180# endif /* !HAVE_VSNPRINTF */
181
4400e98d 182/*
183 * String pool functions...
184 */
185
757d2cad 186extern char *_cupsStrAlloc(const char *s);
d6ae789d 187extern void _cupsStrFlush(void);
757d2cad 188extern void _cupsStrFree(const char *s);
e07d4801 189extern char *_cupsStrRetain(const char *s);
757d2cad 190extern size_t _cupsStrStatistics(size_t *alloc_bytes, size_t *total_bytes);
191
192
193/*
194 * Floating point number functions...
195 */
196
197extern char *_cupsStrFormatd(char *buf, char *bufend, double number,
198 struct lconv *loc);
199extern double _cupsStrScand(const char *buf, char **bufptr,
200 struct lconv *loc);
4400e98d 201
ef416fc2 202
554aa7b7
MS
203/*
204 * Date function...
205 */
206
207extern char *_cupsStrDate(char *buf, size_t bufsize, time_t timeval);
208
209
ef416fc2 210/*
211 * C++ magic...
212 */
213
214# ifdef __cplusplus
215}
216# endif /* __cplusplus */
217
218#endif /* !_CUPS_STRING_H_ */