redsnow 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +34 -0
- data/.gitmodules +3 -0
- data/.travis.yml +20 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +62 -0
- data/Rakefile +36 -0
- data/Vagrantfile +20 -0
- data/ext/snowcrash/Makefile +64 -0
- data/ext/snowcrash/Vagrantfile +20 -0
- data/ext/snowcrash/bin/snowcrash +0 -0
- data/ext/snowcrash/common.gypi +163 -0
- data/ext/snowcrash/config.gypi +10 -0
- data/ext/snowcrash/config.mk +5 -0
- data/ext/snowcrash/configure +213 -0
- data/ext/snowcrash/provisioning.sh +15 -0
- data/ext/snowcrash/snowcrash.gyp +141 -0
- data/ext/snowcrash/src/ActionParser.h +503 -0
- data/ext/snowcrash/src/AssetParser.h +215 -0
- data/ext/snowcrash/src/BlockUtility.h +186 -0
- data/ext/snowcrash/src/Blueprint.h +283 -0
- data/ext/snowcrash/src/BlueprintParser.h +347 -0
- data/ext/snowcrash/src/BlueprintParserCore.h +190 -0
- data/ext/snowcrash/src/BlueprintSection.h +140 -0
- data/ext/snowcrash/src/BlueprintUtility.h +126 -0
- data/ext/snowcrash/src/CBlueprint.cc +600 -0
- data/ext/snowcrash/src/CBlueprint.h +354 -0
- data/ext/snowcrash/src/CSourceAnnotation.cc +140 -0
- data/ext/snowcrash/src/CSourceAnnotation.h +106 -0
- data/ext/snowcrash/src/CodeBlockUtility.h +189 -0
- data/ext/snowcrash/src/DescriptionSectionUtility.h +156 -0
- data/ext/snowcrash/src/HTTP.cc +46 -0
- data/ext/snowcrash/src/HTTP.h +105 -0
- data/ext/snowcrash/src/HeaderParser.h +289 -0
- data/ext/snowcrash/src/ListBlockUtility.h +273 -0
- data/ext/snowcrash/src/ListUtility.h +95 -0
- data/ext/snowcrash/src/MarkdownBlock.cc +176 -0
- data/ext/snowcrash/src/MarkdownBlock.h +93 -0
- data/ext/snowcrash/src/MarkdownParser.cc +266 -0
- data/ext/snowcrash/src/MarkdownParser.h +88 -0
- data/ext/snowcrash/src/ParameterDefinitonParser.h +570 -0
- data/ext/snowcrash/src/ParametersParser.h +252 -0
- data/ext/snowcrash/src/Parser.cc +71 -0
- data/ext/snowcrash/src/Parser.h +29 -0
- data/ext/snowcrash/src/ParserCore.cc +120 -0
- data/ext/snowcrash/src/ParserCore.h +82 -0
- data/ext/snowcrash/src/PayloadParser.h +672 -0
- data/ext/snowcrash/src/Platform.h +54 -0
- data/ext/snowcrash/src/RegexMatch.h +32 -0
- data/ext/snowcrash/src/ResourceGroupParser.h +195 -0
- data/ext/snowcrash/src/ResourceParser.h +584 -0
- data/ext/snowcrash/src/SectionUtility.h +142 -0
- data/ext/snowcrash/src/Serialize.cc +52 -0
- data/ext/snowcrash/src/Serialize.h +69 -0
- data/ext/snowcrash/src/SerializeJSON.cc +601 -0
- data/ext/snowcrash/src/SerializeJSON.h +21 -0
- data/ext/snowcrash/src/SerializeYAML.cc +336 -0
- data/ext/snowcrash/src/SerializeYAML.h +21 -0
- data/ext/snowcrash/src/SourceAnnotation.h +177 -0
- data/ext/snowcrash/src/StringUtility.h +109 -0
- data/ext/snowcrash/src/SymbolTable.h +83 -0
- data/ext/snowcrash/src/UriTemplateParser.cc +195 -0
- data/ext/snowcrash/src/UriTemplateParser.h +243 -0
- data/ext/snowcrash/src/Version.h +39 -0
- data/ext/snowcrash/src/csnowcrash.cc +23 -0
- data/ext/snowcrash/src/csnowcrash.h +38 -0
- data/ext/snowcrash/src/posix/RegexMatch.cc +99 -0
- data/ext/snowcrash/src/snowcrash.cc +18 -0
- data/ext/snowcrash/src/snowcrash.h +41 -0
- data/ext/snowcrash/src/snowcrash/snowcrash.cc +170 -0
- data/ext/snowcrash/src/win/RegexMatch.cc +78 -0
- data/ext/snowcrash/sundown/CONTRIBUTING.md +10 -0
- data/ext/snowcrash/sundown/Makefile +83 -0
- data/ext/snowcrash/sundown/Makefile.win +33 -0
- data/ext/snowcrash/sundown/examples/smartypants.c +72 -0
- data/ext/snowcrash/sundown/examples/sundown.c +80 -0
- data/ext/snowcrash/sundown/html/houdini.h +37 -0
- data/ext/snowcrash/sundown/html/houdini_href_e.c +108 -0
- data/ext/snowcrash/sundown/html/houdini_html_e.c +84 -0
- data/ext/snowcrash/sundown/html/html.c +647 -0
- data/ext/snowcrash/sundown/html/html.h +77 -0
- data/ext/snowcrash/sundown/html/html_smartypants.c +389 -0
- data/ext/snowcrash/sundown/html_block_names.txt +25 -0
- data/ext/snowcrash/sundown/src/autolink.c +297 -0
- data/ext/snowcrash/sundown/src/autolink.h +51 -0
- data/ext/snowcrash/sundown/src/buffer.c +225 -0
- data/ext/snowcrash/sundown/src/buffer.h +96 -0
- data/ext/snowcrash/sundown/src/html_blocks.h +206 -0
- data/ext/snowcrash/sundown/src/markdown.c +2701 -0
- data/ext/snowcrash/sundown/src/markdown.h +147 -0
- data/ext/snowcrash/sundown/src/src_map.c +200 -0
- data/ext/snowcrash/sundown/src/src_map.h +58 -0
- data/ext/snowcrash/sundown/src/stack.c +81 -0
- data/ext/snowcrash/sundown/src/stack.h +29 -0
- data/ext/snowcrash/sundown/sundown.def +20 -0
- data/ext/snowcrash/tools/gyp/AUTHORS +11 -0
- data/ext/snowcrash/tools/gyp/DEPS +24 -0
- data/ext/snowcrash/tools/gyp/OWNERS +1 -0
- data/ext/snowcrash/tools/gyp/PRESUBMIT.py +120 -0
- data/ext/snowcrash/tools/gyp/buildbot/buildbot_run.py +190 -0
- data/ext/snowcrash/tools/gyp/codereview.settings +10 -0
- data/ext/snowcrash/tools/gyp/data/win/large-pdb-shim.cc +12 -0
- data/ext/snowcrash/tools/gyp/gyp +8 -0
- data/ext/snowcrash/tools/gyp/gyp.bat +5 -0
- data/ext/snowcrash/tools/gyp/gyp_main.py +18 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSNew.py +340 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSProject.py +208 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSSettings.py +1063 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSToolFile.py +58 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSUserFile.py +147 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSUtil.py +267 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSVersion.py +409 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/__init__.py +537 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/__init__.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/common.py +521 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/common.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/easy_xml.py +157 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/flock_tool.py +49 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/__init__.py +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/__init__.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/android.py +1069 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/cmake.py +1143 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/dump_dependency_json.py +81 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/eclipse.py +335 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/gypd.py +87 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/gypsh.py +56 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/make.py +2181 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/make.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/msvs.py +3335 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/ninja.py +2156 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/xcode.py +1224 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/xcode.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/input.py +2809 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/input.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/mac_tool.py +510 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/msvs_emulation.py +972 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/ninja_syntax.py +160 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/ordered_dict.py +289 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/win_tool.py +292 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.py +1440 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/xcodeproj_file.py +2889 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/xcodeproj_file.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/xml_fix.py +69 -0
- data/ext/snowcrash/tools/gyp/pylintrc +307 -0
- data/ext/snowcrash/tools/gyp/samples/samples +81 -0
- data/ext/snowcrash/tools/gyp/samples/samples.bat +5 -0
- data/ext/snowcrash/tools/gyp/setup.py +19 -0
- data/ext/snowcrash/tools/gyp/tools/Xcode/Specifications/gyp.pbfilespec +27 -0
- data/ext/snowcrash/tools/gyp/tools/Xcode/Specifications/gyp.xclangspec +226 -0
- data/ext/snowcrash/tools/gyp/tools/emacs/gyp.el +252 -0
- data/ext/snowcrash/tools/gyp/tools/graphviz.py +100 -0
- data/ext/snowcrash/tools/gyp/tools/pretty_gyp.py +155 -0
- data/ext/snowcrash/tools/gyp/tools/pretty_sln.py +168 -0
- data/ext/snowcrash/tools/gyp/tools/pretty_vcproj.py +329 -0
- data/ext/snowcrash/tools/homebrew/snowcrash.rb +11 -0
- data/ext/snowcrash/vcbuild.bat +184 -0
- data/lib/redsnow.rb +31 -0
- data/lib/redsnow/binding.rb +132 -0
- data/lib/redsnow/blueprint.rb +365 -0
- data/lib/redsnow/object.rb +18 -0
- data/lib/redsnow/parseresult.rb +107 -0
- data/lib/redsnow/version.rb +4 -0
- data/provisioning.sh +20 -0
- data/redsnow.gemspec +35 -0
- data/test/_helper.rb +15 -0
- data/test/fixtures/sample-api-ast.json +97 -0
- data/test/fixtures/sample-api.apib +20 -0
- data/test/redsnow_binding_test.rb +35 -0
- data/test/redsnow_parseresult_test.rb +50 -0
- data/test/redsnow_test.rb +285 -0
- metadata +358 -0
@@ -0,0 +1,297 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2011, Vicent Marti
|
3
|
+
*
|
4
|
+
* Permission to use, copy, modify, and distribute this software for any
|
5
|
+
* purpose with or without fee is hereby granted, provided that the above
|
6
|
+
* copyright notice and this permission notice appear in all copies.
|
7
|
+
*
|
8
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
9
|
+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
10
|
+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
11
|
+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
12
|
+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
13
|
+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
14
|
+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
15
|
+
*/
|
16
|
+
|
17
|
+
#include "buffer.h"
|
18
|
+
#include "autolink.h"
|
19
|
+
|
20
|
+
#include <string.h>
|
21
|
+
#include <stdlib.h>
|
22
|
+
#include <stdio.h>
|
23
|
+
#include <ctype.h>
|
24
|
+
|
25
|
+
#if defined(_WIN32)
|
26
|
+
#define strncasecmp _strnicmp
|
27
|
+
#endif
|
28
|
+
|
29
|
+
int
|
30
|
+
sd_autolink_issafe(const uint8_t *link, size_t link_len)
|
31
|
+
{
|
32
|
+
static const size_t valid_uris_count = 5;
|
33
|
+
static const char *valid_uris[] = {
|
34
|
+
"/", "http://", "https://", "ftp://", "mailto:"
|
35
|
+
};
|
36
|
+
|
37
|
+
size_t i;
|
38
|
+
|
39
|
+
for (i = 0; i < valid_uris_count; ++i) {
|
40
|
+
size_t len = strlen(valid_uris[i]);
|
41
|
+
|
42
|
+
if (link_len > len &&
|
43
|
+
strncasecmp((char *)link, valid_uris[i], len) == 0 &&
|
44
|
+
isalnum(link[len]))
|
45
|
+
return 1;
|
46
|
+
}
|
47
|
+
|
48
|
+
return 0;
|
49
|
+
}
|
50
|
+
|
51
|
+
static size_t
|
52
|
+
autolink_delim(uint8_t *data, size_t link_end, size_t max_rewind, size_t size)
|
53
|
+
{
|
54
|
+
uint8_t cclose, copen = 0;
|
55
|
+
size_t i;
|
56
|
+
|
57
|
+
for (i = 0; i < link_end; ++i)
|
58
|
+
if (data[i] == '<') {
|
59
|
+
link_end = i;
|
60
|
+
break;
|
61
|
+
}
|
62
|
+
|
63
|
+
while (link_end > 0) {
|
64
|
+
if (strchr("?!.,", data[link_end - 1]) != NULL)
|
65
|
+
link_end--;
|
66
|
+
|
67
|
+
else if (data[link_end - 1] == ';') {
|
68
|
+
size_t new_end = link_end - 2;
|
69
|
+
|
70
|
+
while (new_end > 0 && isalpha(data[new_end]))
|
71
|
+
new_end--;
|
72
|
+
|
73
|
+
if (new_end < link_end - 2 && data[new_end] == '&')
|
74
|
+
link_end = new_end;
|
75
|
+
else
|
76
|
+
link_end--;
|
77
|
+
}
|
78
|
+
else break;
|
79
|
+
}
|
80
|
+
|
81
|
+
if (link_end == 0)
|
82
|
+
return 0;
|
83
|
+
|
84
|
+
cclose = data[link_end - 1];
|
85
|
+
|
86
|
+
switch (cclose) {
|
87
|
+
case '"': copen = '"'; break;
|
88
|
+
case '\'': copen = '\''; break;
|
89
|
+
case ')': copen = '('; break;
|
90
|
+
case ']': copen = '['; break;
|
91
|
+
case '}': copen = '{'; break;
|
92
|
+
}
|
93
|
+
|
94
|
+
if (copen != 0) {
|
95
|
+
size_t closing = 0;
|
96
|
+
size_t opening = 0;
|
97
|
+
size_t i = 0;
|
98
|
+
|
99
|
+
/* Try to close the final punctuation sign in this same line;
|
100
|
+
* if we managed to close it outside of the URL, that means that it's
|
101
|
+
* not part of the URL. If it closes inside the URL, that means it
|
102
|
+
* is part of the URL.
|
103
|
+
*
|
104
|
+
* Examples:
|
105
|
+
*
|
106
|
+
* foo http://www.pokemon.com/Pikachu_(Electric) bar
|
107
|
+
* => http://www.pokemon.com/Pikachu_(Electric)
|
108
|
+
*
|
109
|
+
* foo (http://www.pokemon.com/Pikachu_(Electric)) bar
|
110
|
+
* => http://www.pokemon.com/Pikachu_(Electric)
|
111
|
+
*
|
112
|
+
* foo http://www.pokemon.com/Pikachu_(Electric)) bar
|
113
|
+
* => http://www.pokemon.com/Pikachu_(Electric))
|
114
|
+
*
|
115
|
+
* (foo http://www.pokemon.com/Pikachu_(Electric)) bar
|
116
|
+
* => foo http://www.pokemon.com/Pikachu_(Electric)
|
117
|
+
*/
|
118
|
+
|
119
|
+
while (i < link_end) {
|
120
|
+
if (data[i] == copen)
|
121
|
+
opening++;
|
122
|
+
else if (data[i] == cclose)
|
123
|
+
closing++;
|
124
|
+
|
125
|
+
i++;
|
126
|
+
}
|
127
|
+
|
128
|
+
if (closing != opening)
|
129
|
+
link_end--;
|
130
|
+
}
|
131
|
+
|
132
|
+
return link_end;
|
133
|
+
}
|
134
|
+
|
135
|
+
static size_t
|
136
|
+
check_domain(uint8_t *data, size_t size, int allow_short)
|
137
|
+
{
|
138
|
+
size_t i, np = 0;
|
139
|
+
|
140
|
+
if (!isalnum(data[0]))
|
141
|
+
return 0;
|
142
|
+
|
143
|
+
for (i = 1; i < size - 1; ++i) {
|
144
|
+
if (data[i] == '.') np++;
|
145
|
+
else if (!isalnum(data[i]) && data[i] != '-') break;
|
146
|
+
}
|
147
|
+
|
148
|
+
if (allow_short) {
|
149
|
+
/* We don't need a valid domain in the strict sense (with
|
150
|
+
* least one dot; so just make sure it's composed of valid
|
151
|
+
* domain characters and return the length of the the valid
|
152
|
+
* sequence. */
|
153
|
+
return i;
|
154
|
+
} else {
|
155
|
+
/* a valid domain needs to have at least a dot.
|
156
|
+
* that's as far as we get */
|
157
|
+
return np ? i : 0;
|
158
|
+
}
|
159
|
+
}
|
160
|
+
|
161
|
+
size_t
|
162
|
+
sd_autolink__www(
|
163
|
+
size_t *rewind_p,
|
164
|
+
struct buf *link,
|
165
|
+
uint8_t *data,
|
166
|
+
size_t max_rewind,
|
167
|
+
size_t size,
|
168
|
+
unsigned int flags)
|
169
|
+
{
|
170
|
+
size_t link_end;
|
171
|
+
|
172
|
+
if (max_rewind > 0 && !ispunct(data[-1]) && !isspace(data[-1]))
|
173
|
+
return 0;
|
174
|
+
|
175
|
+
if (size < 4 || memcmp(data, "www.", strlen("www.")) != 0)
|
176
|
+
return 0;
|
177
|
+
|
178
|
+
link_end = check_domain(data, size, 0);
|
179
|
+
|
180
|
+
if (link_end == 0)
|
181
|
+
return 0;
|
182
|
+
|
183
|
+
while (link_end < size && !isspace(data[link_end]))
|
184
|
+
link_end++;
|
185
|
+
|
186
|
+
link_end = autolink_delim(data, link_end, max_rewind, size);
|
187
|
+
|
188
|
+
if (link_end == 0)
|
189
|
+
return 0;
|
190
|
+
|
191
|
+
bufput(link, data, link_end);
|
192
|
+
*rewind_p = 0;
|
193
|
+
|
194
|
+
return (int)link_end;
|
195
|
+
}
|
196
|
+
|
197
|
+
size_t
|
198
|
+
sd_autolink__email(
|
199
|
+
size_t *rewind_p,
|
200
|
+
struct buf *link,
|
201
|
+
uint8_t *data,
|
202
|
+
size_t max_rewind,
|
203
|
+
size_t size,
|
204
|
+
unsigned int flags)
|
205
|
+
{
|
206
|
+
size_t link_end, rewind;
|
207
|
+
int nb = 0, np = 0;
|
208
|
+
|
209
|
+
for (rewind = 0; rewind < max_rewind; ++rewind) {
|
210
|
+
uint8_t c = data[-rewind - 1];
|
211
|
+
|
212
|
+
if (isalnum(c))
|
213
|
+
continue;
|
214
|
+
|
215
|
+
if (strchr(".+-_", c) != NULL)
|
216
|
+
continue;
|
217
|
+
|
218
|
+
break;
|
219
|
+
}
|
220
|
+
|
221
|
+
if (rewind == 0)
|
222
|
+
return 0;
|
223
|
+
|
224
|
+
for (link_end = 0; link_end < size; ++link_end) {
|
225
|
+
uint8_t c = data[link_end];
|
226
|
+
|
227
|
+
if (isalnum(c))
|
228
|
+
continue;
|
229
|
+
|
230
|
+
if (c == '@')
|
231
|
+
nb++;
|
232
|
+
else if (c == '.' && link_end < size - 1)
|
233
|
+
np++;
|
234
|
+
else if (c != '-' && c != '_')
|
235
|
+
break;
|
236
|
+
}
|
237
|
+
|
238
|
+
if (link_end < 2 || nb != 1 || np == 0 ||
|
239
|
+
!isalpha(data[link_end - 1]))
|
240
|
+
return 0;
|
241
|
+
|
242
|
+
link_end = autolink_delim(data, link_end, max_rewind, size);
|
243
|
+
|
244
|
+
if (link_end == 0)
|
245
|
+
return 0;
|
246
|
+
|
247
|
+
bufput(link, data - rewind, link_end + rewind);
|
248
|
+
*rewind_p = rewind;
|
249
|
+
|
250
|
+
return link_end;
|
251
|
+
}
|
252
|
+
|
253
|
+
size_t
|
254
|
+
sd_autolink__url(
|
255
|
+
size_t *rewind_p,
|
256
|
+
struct buf *link,
|
257
|
+
uint8_t *data,
|
258
|
+
size_t max_rewind,
|
259
|
+
size_t size,
|
260
|
+
unsigned int flags)
|
261
|
+
{
|
262
|
+
size_t link_end, rewind = 0, domain_len;
|
263
|
+
|
264
|
+
if (size < 4 || data[1] != '/' || data[2] != '/')
|
265
|
+
return 0;
|
266
|
+
|
267
|
+
while (rewind < max_rewind && isalpha(data[-rewind - 1]))
|
268
|
+
rewind++;
|
269
|
+
|
270
|
+
if (!sd_autolink_issafe(data - rewind, size + rewind))
|
271
|
+
return 0;
|
272
|
+
|
273
|
+
link_end = strlen("://");
|
274
|
+
|
275
|
+
domain_len = check_domain(
|
276
|
+
data + link_end,
|
277
|
+
size - link_end,
|
278
|
+
flags & SD_AUTOLINK_SHORT_DOMAINS);
|
279
|
+
|
280
|
+
if (domain_len == 0)
|
281
|
+
return 0;
|
282
|
+
|
283
|
+
link_end += domain_len;
|
284
|
+
while (link_end < size && !isspace(data[link_end]))
|
285
|
+
link_end++;
|
286
|
+
|
287
|
+
link_end = autolink_delim(data, link_end, max_rewind, size);
|
288
|
+
|
289
|
+
if (link_end == 0)
|
290
|
+
return 0;
|
291
|
+
|
292
|
+
bufput(link, data - rewind, link_end + rewind);
|
293
|
+
*rewind_p = rewind;
|
294
|
+
|
295
|
+
return link_end;
|
296
|
+
}
|
297
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2011, Vicent Marti
|
3
|
+
*
|
4
|
+
* Permission to use, copy, modify, and distribute this software for any
|
5
|
+
* purpose with or without fee is hereby granted, provided that the above
|
6
|
+
* copyright notice and this permission notice appear in all copies.
|
7
|
+
*
|
8
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
9
|
+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
10
|
+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
11
|
+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
12
|
+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
13
|
+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
14
|
+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
15
|
+
*/
|
16
|
+
|
17
|
+
#ifndef UPSKIRT_AUTOLINK_H
|
18
|
+
#define UPSKIRT_AUTOLINK_H
|
19
|
+
|
20
|
+
#include "buffer.h"
|
21
|
+
|
22
|
+
#ifdef __cplusplus
|
23
|
+
extern "C" {
|
24
|
+
#endif
|
25
|
+
|
26
|
+
enum {
|
27
|
+
SD_AUTOLINK_SHORT_DOMAINS = (1 << 0)
|
28
|
+
};
|
29
|
+
|
30
|
+
int
|
31
|
+
sd_autolink_issafe(const uint8_t *link, size_t link_len);
|
32
|
+
|
33
|
+
size_t
|
34
|
+
sd_autolink__www(size_t *rewind_p, struct buf *link,
|
35
|
+
uint8_t *data, size_t offset, size_t size, unsigned int flags);
|
36
|
+
|
37
|
+
size_t
|
38
|
+
sd_autolink__email(size_t *rewind_p, struct buf *link,
|
39
|
+
uint8_t *data, size_t offset, size_t size, unsigned int flags);
|
40
|
+
|
41
|
+
size_t
|
42
|
+
sd_autolink__url(size_t *rewind_p, struct buf *link,
|
43
|
+
uint8_t *data, size_t offset, size_t size, unsigned int flags);
|
44
|
+
|
45
|
+
#ifdef __cplusplus
|
46
|
+
}
|
47
|
+
#endif
|
48
|
+
|
49
|
+
#endif
|
50
|
+
|
51
|
+
/* vim: set filetype=c: */
|
@@ -0,0 +1,225 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2008, Natacha Porté
|
3
|
+
* Copyright (c) 2011, Vicent Martí
|
4
|
+
*
|
5
|
+
* Permission to use, copy, modify, and distribute this software for any
|
6
|
+
* purpose with or without fee is hereby granted, provided that the above
|
7
|
+
* copyright notice and this permission notice appear in all copies.
|
8
|
+
*
|
9
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
10
|
+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
11
|
+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
12
|
+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
13
|
+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
14
|
+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
15
|
+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
16
|
+
*/
|
17
|
+
|
18
|
+
#define BUFFER_MAX_ALLOC_SIZE (1024 * 1024 * 16) //16mb
|
19
|
+
|
20
|
+
#include "buffer.h"
|
21
|
+
|
22
|
+
#include <stdio.h>
|
23
|
+
#include <stdlib.h>
|
24
|
+
#include <string.h>
|
25
|
+
#include <assert.h>
|
26
|
+
|
27
|
+
/* MSVC compat */
|
28
|
+
#if defined(_MSC_VER)
|
29
|
+
# define _buf_vsnprintf _vsnprintf
|
30
|
+
#else
|
31
|
+
# define _buf_vsnprintf vsnprintf
|
32
|
+
#endif
|
33
|
+
|
34
|
+
int
|
35
|
+
bufprefix(const struct buf *buf, const char *prefix)
|
36
|
+
{
|
37
|
+
size_t i;
|
38
|
+
assert(buf && buf->unit);
|
39
|
+
|
40
|
+
for (i = 0; i < buf->size; ++i) {
|
41
|
+
if (prefix[i] == 0)
|
42
|
+
return 0;
|
43
|
+
|
44
|
+
if (buf->data[i] != prefix[i])
|
45
|
+
return buf->data[i] - prefix[i];
|
46
|
+
}
|
47
|
+
|
48
|
+
return 0;
|
49
|
+
}
|
50
|
+
|
51
|
+
/* bufgrow: increasing the allocated size to the given value */
|
52
|
+
int
|
53
|
+
bufgrow(struct buf *buf, size_t neosz)
|
54
|
+
{
|
55
|
+
size_t neoasz;
|
56
|
+
void *neodata;
|
57
|
+
|
58
|
+
assert(buf && buf->unit);
|
59
|
+
|
60
|
+
if (neosz > BUFFER_MAX_ALLOC_SIZE)
|
61
|
+
return BUF_ENOMEM;
|
62
|
+
|
63
|
+
if (buf->asize >= neosz)
|
64
|
+
return BUF_OK;
|
65
|
+
|
66
|
+
neoasz = buf->asize + buf->unit;
|
67
|
+
while (neoasz < neosz)
|
68
|
+
neoasz += buf->unit;
|
69
|
+
|
70
|
+
neodata = realloc(buf->data, neoasz);
|
71
|
+
if (!neodata)
|
72
|
+
return BUF_ENOMEM;
|
73
|
+
|
74
|
+
buf->data = neodata;
|
75
|
+
buf->asize = neoasz;
|
76
|
+
return BUF_OK;
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
/* bufnew: allocation of a new buffer */
|
81
|
+
struct buf *
|
82
|
+
bufnew(size_t unit)
|
83
|
+
{
|
84
|
+
struct buf *ret;
|
85
|
+
ret = malloc(sizeof (struct buf));
|
86
|
+
|
87
|
+
if (ret) {
|
88
|
+
ret->data = 0;
|
89
|
+
ret->size = ret->asize = 0;
|
90
|
+
ret->unit = unit;
|
91
|
+
}
|
92
|
+
return ret;
|
93
|
+
}
|
94
|
+
|
95
|
+
/* bufnullterm: NULL-termination of the string array */
|
96
|
+
const char *
|
97
|
+
bufcstr(struct buf *buf)
|
98
|
+
{
|
99
|
+
assert(buf && buf->unit);
|
100
|
+
|
101
|
+
if (buf->size < buf->asize && buf->data[buf->size] == 0)
|
102
|
+
return (char *)buf->data;
|
103
|
+
|
104
|
+
if (buf->size + 1 <= buf->asize || bufgrow(buf, buf->size + 1) == 0) {
|
105
|
+
buf->data[buf->size] = 0;
|
106
|
+
return (char *)buf->data;
|
107
|
+
}
|
108
|
+
|
109
|
+
return NULL;
|
110
|
+
}
|
111
|
+
|
112
|
+
/* bufprintf: formatted printing to a buffer */
|
113
|
+
void
|
114
|
+
bufprintf(struct buf *buf, const char *fmt, ...)
|
115
|
+
{
|
116
|
+
va_list ap;
|
117
|
+
int n;
|
118
|
+
|
119
|
+
assert(buf && buf->unit);
|
120
|
+
|
121
|
+
if (buf->size >= buf->asize && bufgrow(buf, buf->size + 1) < 0)
|
122
|
+
return;
|
123
|
+
|
124
|
+
va_start(ap, fmt);
|
125
|
+
n = _buf_vsnprintf((char *)buf->data + buf->size, buf->asize - buf->size, fmt, ap);
|
126
|
+
va_end(ap);
|
127
|
+
|
128
|
+
if (n < 0) {
|
129
|
+
#ifdef _MSC_VER
|
130
|
+
va_start(ap, fmt);
|
131
|
+
n = _vscprintf(fmt, ap);
|
132
|
+
va_end(ap);
|
133
|
+
#else
|
134
|
+
return;
|
135
|
+
#endif
|
136
|
+
}
|
137
|
+
|
138
|
+
if ((size_t)n >= buf->asize - buf->size) {
|
139
|
+
if (bufgrow(buf, buf->size + n + 1) < 0)
|
140
|
+
return;
|
141
|
+
|
142
|
+
va_start(ap, fmt);
|
143
|
+
n = _buf_vsnprintf((char *)buf->data + buf->size, buf->asize - buf->size, fmt, ap);
|
144
|
+
va_end(ap);
|
145
|
+
}
|
146
|
+
|
147
|
+
if (n < 0)
|
148
|
+
return;
|
149
|
+
|
150
|
+
buf->size += n;
|
151
|
+
}
|
152
|
+
|
153
|
+
/* bufput: appends raw data to a buffer */
|
154
|
+
void
|
155
|
+
bufput(struct buf *buf, const void *data, size_t len)
|
156
|
+
{
|
157
|
+
assert(buf && buf->unit);
|
158
|
+
|
159
|
+
if (buf->size + len > buf->asize && bufgrow(buf, buf->size + len) < 0)
|
160
|
+
return;
|
161
|
+
|
162
|
+
memcpy(buf->data + buf->size, data, len);
|
163
|
+
buf->size += len;
|
164
|
+
}
|
165
|
+
|
166
|
+
/* bufputs: appends a NUL-terminated string to a buffer */
|
167
|
+
void
|
168
|
+
bufputs(struct buf *buf, const char *str)
|
169
|
+
{
|
170
|
+
bufput(buf, str, strlen(str));
|
171
|
+
}
|
172
|
+
|
173
|
+
|
174
|
+
/* bufputc: appends a single uint8_t to a buffer */
|
175
|
+
void
|
176
|
+
bufputc(struct buf *buf, int c)
|
177
|
+
{
|
178
|
+
assert(buf && buf->unit);
|
179
|
+
|
180
|
+
if (buf->size + 1 > buf->asize && bufgrow(buf, buf->size + 1) < 0)
|
181
|
+
return;
|
182
|
+
|
183
|
+
buf->data[buf->size] = c;
|
184
|
+
buf->size += 1;
|
185
|
+
}
|
186
|
+
|
187
|
+
/* bufrelease: decrease the reference count and free the buffer if needed */
|
188
|
+
void
|
189
|
+
bufrelease(struct buf *buf)
|
190
|
+
{
|
191
|
+
if (!buf)
|
192
|
+
return;
|
193
|
+
|
194
|
+
free(buf->data);
|
195
|
+
free(buf);
|
196
|
+
}
|
197
|
+
|
198
|
+
|
199
|
+
/* bufreset: frees internal data of the buffer */
|
200
|
+
void
|
201
|
+
bufreset(struct buf *buf)
|
202
|
+
{
|
203
|
+
if (!buf)
|
204
|
+
return;
|
205
|
+
|
206
|
+
free(buf->data);
|
207
|
+
buf->data = NULL;
|
208
|
+
buf->size = buf->asize = 0;
|
209
|
+
}
|
210
|
+
|
211
|
+
/* bufslurp: removes a given number of bytes from the head of the array */
|
212
|
+
void
|
213
|
+
bufslurp(struct buf *buf, size_t len)
|
214
|
+
{
|
215
|
+
assert(buf && buf->unit);
|
216
|
+
|
217
|
+
if (len >= buf->size) {
|
218
|
+
buf->size = 0;
|
219
|
+
return;
|
220
|
+
}
|
221
|
+
|
222
|
+
buf->size -= len;
|
223
|
+
memmove(buf->data, buf->data + len, buf->size);
|
224
|
+
}
|
225
|
+
|