diff options
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | lstring.c | 30 | ||||
-rw-r--r-- | lstring.h | 34 | ||||
-rw-r--r-- | proxy.c | 29 |
4 files changed, 67 insertions, 29 deletions
@@ -41,7 +41,7 @@ LIBS+=-g -lowfat -lssl -lcrypto %: %.c $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) ${LIBS} -ldadp: version.in.h tmpbuffer.o ini.o client.o server.o helper.o proxy.o epoll.o openssl.o ldap.a asn1.a +ldadp: version.in.h tmpbuffer.o ini.o client.o server.o helper.o proxy.o epoll.o openssl.o lstring.o ldap.a asn1.a version.in.h: ./gen-version @@ -63,6 +63,7 @@ helper.o: helper.c helper.h types.h proxy.o: proxy.c proxy.h types.h helper.h epoll.o: epoll.c epoll.h types.h openssl.o: openssl.c openssl.h types.h +lstring.o: lstring.c asn1.h types.h fmt_asn1int.o: fmt_asn1int.c asn1.h fmt_asn1intpayload.o: fmt_asn1intpayload.c asn1.h diff --git a/lstring.c b/lstring.c new file mode 100644 index 0000000..ee8904f --- /dev/null +++ b/lstring.c @@ -0,0 +1,30 @@ +#include "lstring.h" + +BOOL isInt(const struct string *value, int start) +{ + size_t i; + for (i = start; i < value->l; ++i) { + if (value->s[i] < '0' || value->s[i] > '9') return FALSE; + } + return TRUE; +} + +uint32_t parseUInt32(const struct string * const s) +{ + if (s == NULL || s->l > 10) { + return 0; + } + uint32_t ret = 0, last = 0; + for (size_t i = 0; i < s->l; ++i) { + if (s->s[i] < '0' || s->s[i] > '9') { + return 0; + } + ret = ret * 10 + (s->s[i] - '0'); + if (ret < last) { + return 0; + } + last = ret; + } + return ret; +} + diff --git a/lstring.h b/lstring.h new file mode 100644 index 0000000..1d20967 --- /dev/null +++ b/lstring.h @@ -0,0 +1,34 @@ +#ifndef _LSTRING_H_ +#define _LSTRING_H_ + +#include "asn1.h" +#include "types.h" + +#include <ctype.h> +#include <string.h> + +BOOL isInt(const struct string * const value, int start); + +uint32_t parseUInt32(const struct string * const s); + +static inline int equals(const struct string *a, const struct string *b) +{ + if (a->l != b->l) return 0; + if (a->s == b->s) return 1; + return strncmp(a->s, b->s, a->l) == 0; +} + +/** + * b MUST be in lowercase already. + */ +static inline int iequals(const struct string * const a, const struct string * const b) +{ + if (a->l != b->l) return 0; + if (a->s == b->s) return 1; + for (size_t i = 0; i < a->l; ++i) { + if (tolower(a->s[i]) != b->s[i]) return 0; + } + return 1; +} + +#endif @@ -4,6 +4,7 @@ #include "helper.h" #include "tmpbuffer.h" #include "ldap.h" +#include "lstring.h" #include <stdio.h> #include <string.h> #include <ctype.h> @@ -68,14 +69,6 @@ static struct string s_bogusfieldname42, s_bogusfieldname43; static struct string str_ADUSER, str_ADUSERDN; // HACK -static BOOL isInt(struct string *value, int start) -{ - size_t i; - for (i = start; i < value->l; ++i) { - if (value->s[i] < '0' || value->s[i] > '9') return FALSE; - } - return TRUE; -} static void fixUnNumeric(struct string *value) { if (value == NULL || value->l < 2) return; @@ -335,26 +328,6 @@ static void pref(int spaces, char prefix) } */ -static inline int equals(struct string *a, struct string *b) -{ - if (a->l != b->l) return 0; - if (a->s == b->s) return 1; - return strncmp(a->s, b->s, a->l) == 0; -} - -/** - * b MUST be in lowercase already. - */ -static inline int iequals(const struct string * const a, const struct string * const b) -{ - if (a->l != b->l) return 0; - if (a->s == b->s) return 1; - for (size_t i = 0; i < a->l; ++i) { - if (tolower(a->s[i]) != b->s[i]) return 0; - } - return 1; -} - // ---- client to AD replacements //#define PREF(...) do { pref(spaces, prefix); printf(__VA_ARGS__); } while (0) |