• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2001-2004 Brandon Long
3  * All Rights Reserved.
4  *
5  * ClearSilver Templating System
6  *
7  * This code is made available under the terms of the ClearSilver License.
8  * http://www.clearsilver.net/license.hdf
9  *
10  */
11 
12 #ifndef __NEO_STR_H_
13 #define __NEO_STR_H_ 1
14 
15 __BEGIN_DECLS
16 
17 #include <stdarg.h>
18 #include <stdio.h>
19 #include "util/neo_misc.h"
20 
21 /* This modifies the string its called with by replacing all the white
22  * space on the end with \0, and returns a pointer to the first
23  * non-white space character in the string
24  */
25 char *neos_strip (char *s);
26 
27 void neos_lower (char *s);
28 
29 char *sprintf_alloc (const char *fmt, ...) ATTRIBUTE_PRINTF(1,2);
30 char *nsprintf_alloc (int start_size, const char *fmt, ...) ATTRIBUTE_PRINTF(2,3);
31 char *vsprintf_alloc (const char *fmt, va_list ap);
32 char *vnsprintf_alloc (int start_size, const char *fmt, va_list ap);
33 
34 /* Versions of the above which actually return a length, necessary if
35  * you expect embedded NULLs */
36 int vnisprintf_alloc (char **buf, int start_size, const char *fmt, va_list ap);
37 int visprintf_alloc (char **buf, const char *fmt, va_list ap);
38 int isprintf_alloc (char **buf, const char *fmt, ...) ATTRIBUTE_PRINTF(2,3);
39 
40 typedef struct _string
41 {
42   char *buf;
43   int len;
44   int max;
45 } STRING;
46 
47 typedef struct _string_array
48 {
49   char **entries;
50   int count;
51   int max;
52 } STRING_ARRAY;
53 
54 /* At some point, we should add the concept of "max len" to these so we
55  * can't get DoS'd by someone sending us a line without an end point,
56  * etc. */
57 void string_init (STRING *str);
58 NEOERR *string_set (STRING *str, const char *buf);
59 NEOERR *string_append (STRING *str, const char *buf);
60 NEOERR *string_appendn (STRING *str, const char *buf, int l);
61 NEOERR *string_append_char (STRING *str, char c);
62 NEOERR *string_appendf (STRING *str, const char *fmt, ...) ATTRIBUTE_PRINTF(2,3);
63 NEOERR *string_appendvf (STRING *str, const char *fmt, va_list ap);
64 NEOERR *string_readline (STRING *str, FILE *fp);
65 void string_clear (STRING *str);
66 
67 /* typedef struct _ulist ULIST; */
68 #include "util/ulist.h"
69 /* s is not const because we actually temporarily modify the string
70  * during split */
71 NEOERR *string_array_split (ULIST **list, char *s, const char *sep,
72                             int max);
73 
74 BOOL reg_search (const char *re, const char *str);
75 
76 /* NEOS_ESCAPE details the support escape contexts/modes handled
77  * by various NEOS helper methods and reused in CS itself. */
78 typedef enum
79 {
80   NEOS_ESCAPE_UNDEF    =  0,    /* Used to force eval-time checking */
81   NEOS_ESCAPE_NONE     =  1<<0,
82   NEOS_ESCAPE_HTML     =  1<<1,
83   NEOS_ESCAPE_SCRIPT   =  1<<2,
84   NEOS_ESCAPE_URL      =  1<<3,
85   NEOS_ESCAPE_FUNCTION =  1<<4  /* Special case used to override the others */
86 } NEOS_ESCAPE;
87 
88 NEOERR* neos_escape(UINT8 *buf, int buflen, char esc_char, const char *escape,
89                     char **esc);
90 UINT8 *neos_unescape (UINT8 *s, int buflen, char esc_char);
91 
92 char *repr_string_alloc (const char *s);
93 
94 /* This is the "super" escape call which will call the proper helper
95  * variable escape function based on the passed in context. */
96 NEOERR *neos_var_escape (NEOS_ESCAPE context,
97                          const char *in,
98                          char **esc);
99 
100 /* Generic data escaping helper functions used by neos_contextual_escape
101  * and cs built-ins. */
102 NEOERR *neos_url_escape (const char *in, char **esc,
103                          const char *other);
104 
105 NEOERR *neos_js_escape (const char *in, char **esc);
106 
107 NEOERR *neos_html_escape (const char *src, int slen,
108                           char **out);
109 
110 NEOERR *neos_url_validate (const char *in, char **esc);
111 
112 __END_DECLS
113 
114 #endif /* __NEO_STR_H_ */
115