timekeeper

My first (abandoned unfinished) web application for time tracking
git clone git://jacobedwards.org/timekeeper
Log | Files | Refs | README

key.c (953B)


      1 #include <sys/types.h>
      2 #include <stdarg.h>
      3 #include <stdint.h>
      4 #include <kcgi.h>
      5 #include <kcgihtml.h>
      6 
      7 #include <ctype.h>
      8 
      9 #include "key.h"
     10 
     11 #include "page.h"
     12 #include "user.h"
     13 
     14 int
     15 kvalid_name(struct kpair *p)
     16 {
     17 	char *s;
     18 
     19 	if (!kvalid_stringne(p) || p->valsz < NameMin || p->valsz > NameMax)
     20 		return 0;
     21 
     22 	for (s = p->val; *s; ++s)
     23 		if (!isalnum(*s) && *s != '-')
     24 			return 0;
     25 	return 1;
     26 }
     27 
     28 int
     29 kvalid_pass(struct kpair *p)
     30 {
     31 	if (!kvalid_stringne(p) || p->valsz < PassMin || p->valsz > PassMax)
     32 		return 0;
     33 	return 1;
     34 }
     35 
     36 struct kvalid keys[] = {
     37 	[KeyUsername] = { kvalid_name, "username" },
     38 	[KeyPassword] = { kvalid_pass, "password" },
     39 	[KeyHash] = { kvalid_stringne, "hash" },
     40 	[KeyCreate] = { kvalid_stringne, "create" },
     41 	[KeyDelete] = { kvalid_stringne, "delete" },
     42 	[KeyTime] = { kvalid_stringne, "time" },
     43 	[KeyFormat] = { kvalid_stringne, "format" },
     44 	[KeyBreak] = { kvalid_stringne, "break" },
     45 	[KeyPeriod] = { kvalid_uint, "period" }
     46 };