ext/rinku/autolink.c in rinku-1.2.2 vs ext/rinku/autolink.c in rinku-1.3.0
- old
+ new
@@ -20,11 +20,11 @@
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
int
-is_safe_link(const char *link, size_t link_len)
+sd_autolink_issafe(const uint8_t *link, size_t link_len)
{
static const size_t valid_uris_count = 4;
static const char *valid_uris[] = {
"http://", "https://", "ftp://", "mailto://"
};
@@ -33,22 +33,22 @@
for (i = 0; i < valid_uris_count; ++i) {
size_t len = strlen(valid_uris[i]);
if (link_len > len &&
- strncasecmp(link, valid_uris[i], len) == 0 &&
+ strncasecmp((char *)link, valid_uris[i], len) == 0 &&
isalnum(link[len]))
return 1;
}
return 0;
}
static size_t
-autolink_delim(char *data, size_t link_end, size_t offset, size_t size)
+autolink_delim(uint8_t *data, size_t link_end, size_t offset, size_t size)
{
- char cclose, copen = 0;
+ uint8_t cclose, copen = 0;
size_t i;
for (i = 0; i < link_end; ++i)
if (data[i] == '<') {
link_end = i;
@@ -126,11 +126,11 @@
return link_end;
}
static size_t
-check_domain(char *data, size_t size)
+check_domain(uint8_t *data, size_t size)
{
size_t i, np = 0;
if (!isalnum(data[0]))
return 0;
@@ -145,18 +145,18 @@
return i;
}
size_t
-ups_autolink__www(size_t *rewind_p, struct buf *link, char *data, size_t offset, size_t size)
+sd_autolink__www(size_t *rewind_p, struct buf *link, uint8_t *data, size_t offset, size_t size)
{
size_t link_end;
if (offset > 0 && !ispunct(data[-1]) && !isspace(data[-1]))
return 0;
- if (size < 4 || memcmp(data, "www.", STRLEN("www.")) != 0)
+ if (size < 4 || memcmp(data, "www.", strlen("www.")) != 0)
return 0;
link_end = check_domain(data, size);
if (link_end == 0)
@@ -175,17 +175,17 @@
return (int)link_end;
}
size_t
-ups_autolink__email(size_t *rewind_p, struct buf *link, char *data, size_t offset, size_t size)
+sd_autolink__email(size_t *rewind_p, struct buf *link, uint8_t *data, size_t offset, size_t size)
{
size_t link_end, rewind;
int nb = 0, np = 0;
for (rewind = 0; rewind < offset; ++rewind) {
- char c = data[-rewind - 1];
+ uint8_t c = data[-rewind - 1];
if (isalnum(c))
continue;
if (strchr(".+-_", c) != NULL)
@@ -196,11 +196,11 @@
if (rewind == 0)
return 0;
for (link_end = 0; link_end < size; ++link_end) {
- char c = data[link_end];
+ uint8_t c = data[link_end];
if (isalnum(c))
continue;
if (c == '@')
@@ -224,22 +224,22 @@
return link_end;
}
size_t
-ups_autolink__url(size_t *rewind_p, struct buf *link, char *data, size_t offset, size_t size)
+sd_autolink__url(size_t *rewind_p, struct buf *link, uint8_t *data, size_t offset, size_t size)
{
size_t link_end, rewind = 0, domain_len;
if (size < 4 || data[1] != '/' || data[2] != '/')
return 0;
while (rewind < offset && isalpha(data[-rewind - 1]))
rewind++;
- if (!is_safe_link(data - rewind, size + rewind))
+ if (!sd_autolink_issafe(data - rewind, size + rewind))
return 0;
- link_end = STRLEN("://");
+ link_end = strlen("://");
domain_len = check_domain(data + link_end, size - link_end);
if (domain_len == 0)
return 0;