#include "string_buffer.h" #include "utils.h" #include #include #include #define VALID_FOR_USERNAME(c) (isalpha(c) || c == '_') int contain_special(const char *s) { return strchr(s, '&') || strchr(s, '"') || strchr(s, '\'') || strchr(s, '<') || strchr(s, '>'); } int is_valid_username(const char *s) { char c; while ((c = *s++)) { if (!VALID_FOR_USERNAME(c)) { return 0; } } return 1; } int is_valid_password(const char *s) { char c; unsigned char b; while ((c = *s++)) { b = (unsigned char) c; if (b < 32) { return 0; } } return 1; } char * mk_specialchars(const char *input) { StringBuffer _buffer, *buffer; char c; char *retval; buffer = &_buffer; sb_init_empty(buffer); while ((c = *(input++))) { switch (c) { case '&': sb_add_string(buffer, "&"); break; case '"': sb_add_string(buffer, """); break; case '\'': sb_add_string(buffer, "'"); break; case '<': sb_add_string(buffer, "<"); break; case '>': sb_add_string(buffer, ">"); break; default: sb_add_char(buffer, c); } } SB_MOVE(buffer, retval); return retval; }