Ejemplo n.º 1
0
cStr *dict_add_literal_to_str(cStr *str, cDict *dict, int flags)
{
    Int i;

    str = string_add_chars(str, "#[", 2);
    for (i = 0; i < dict->keys->len; i++) {
        str = string_addc(str, '[');
        str = data_add_literal_to_str(str, &dict->keys->el[i], flags);
        str = string_add_chars(str, ", ", 2);
        str = data_add_literal_to_str(str, &dict->values->el[i], flags);
        str = string_addc(str, ']');
        if (i < dict->keys->len - 1)
            str = string_add_chars(str, ", ", 2);
    }
    return string_addc(str, ']');
}
Ejemplo n.º 2
0
cStr *string_handled (cStr *str, cData *data, int flags)
{
    HandledFrob *h = HANDLED_FROB(data);
    cData d;

    str = string_addc (str, '<');
    d.type = OBJNUM;
    d.u.objnum = h->cclass;
    str = data_add_literal_to_str(str, &d, flags);
    str = string_add_chars(str, ", ", 2);
    str = data_add_literal_to_str(str, &h->rep, flags);
    str = string_add_chars(str, ", ", 2);
    d.type = SYMBOL;
    d.u.symbol = h->handler;
    str = data_add_literal_to_str(str, &d, flags);
    return string_addc(str, '>');
}
Ejemplo n.º 3
0
Archivo: file.c Proyecto: nrhtr/genesis
cStr *build_path(char *fname, struct stat * sbuf, Int nodir)
{
    Int len = strlen(fname);
    cStr *str = NULL;

    if (len == 0)
        THROWN((file_id, "No file specified."))
#ifdef RESTRICTIVE_FILES
            if (strstr(fname, "../") || strstr(fname, "/..")
                || !strcmp(fname, ".."))
            THROWN((perm_id, "Filename \"%s\" is not legal.", fname))
                str = string_from_chars(c_dir_root, strlen(c_dir_root));
    str = string_addc(str, '/');
    str = string_add_chars(str, fname, len);
#else
            if (*fname != '/') {
            str = string_from_chars(c_dir_root, strlen(c_dir_root));
            str = string_addc(str, '/');
            str = string_add_chars(str, fname, len);
        } else {
            str = string_from_chars(fname, len);
        }
#endif

    if (sbuf != NULL) {
        if (stat(str->s, sbuf) < 0) {
            cthrow(file_id, "Cannot find file \"%s\".", str->s);
            string_discard(str);
            return NULL;
        }
        if (nodir) {
            if (S_ISDIR(sbuf->st_mode)) {
                cthrow(directory_id, "\"%s\" is a directory.", str->s);
                string_discard(str);
                return NULL;
            }
        }
    }

    return str;
}
Ejemplo n.º 4
0
Archivo: web.c Proyecto: nrhtr/genesis
cStr *html_escape(cStr * in)
{
    register char *s;
    register int len;
    cStr *out;

    s = string_chars(in);
    len = string_length(in);

    /* incase they don't need it */
    if (!memchr(s, '<', len) && !memchr(s, '>', len) && !memchr(s, '&', len))
        return string_dup(in);

    /* doh, they do.. */
    out = string_new(len);

    for (; *s != '\0'; s++) {
        switch (*s) {
        case '<':
            out = string_add_chars(out, "&lt;", 4);
            break;
        case '>':
            out = string_add_chars(out, "&gt;", 4);
            break;
        case '&':
            out = string_add_chars(out, "&amp;", 5);
            break;
        case '\"':             /* Added double-quote, Patch #1, Bruce Mitchner */
            out = string_add_chars(out, "&quot;", 6);
            break;
        default:
            out = string_addc(out, *s);
        }
    }

    return out;
}
Ejemplo n.º 5
0
Archivo: web.c Proyecto: nrhtr/genesis
cStr *encode_full(cStr * in)
{
    register char *s = string_chars(in);
    cStr *str = string_new(string_length(in));

    for (; *s != '\0'; s++) {
        if (*s == ' ')
            str = string_addc(str, '+');
        else if (*s > ' ' && *s <= '~') {
            if ((*s >= '0' && *s <= '9') || (*s >= 'A' && *s <= 'Z') || (*s >= 'a' && *s <= 'z'))
                str = string_addc(str, *s);
            else
                str = string_add_chars(str, tohex(*s), 3);
        }
    }

    return str;
}
Ejemplo n.º 6
0
Archivo: web.c Proyecto: nrhtr/genesis
cStr *encode_partial(cStr * in)
{
    register char *s = string_chars(in);
    cStr *str = string_new(string_length(in));

    for (; *s != '\0'; s++) {
        if (*s == ' ')
            str = string_addc(str, '+');
        else if (*s > ' ' && *s <= '~') {
            if ((*s >= '0' && *s <= '9') ||
                (*s >= 'A' && *s <= 'Z') ||
                (*s >= 'a' && *s <= 'z') || memchr(DONT_ESCAPE, *s, DONT_ESCAPE_LEN) != NULL)
                str = string_addc(str, *s);
            else
                str = string_add_chars(str, tohex(*s), 3);
        }
    }

    return str;
}