kore

An easy to use, scalable and secure web application framework for writing web APIs in C.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

check_integers.c (1321B)



      1 #include <kore/kore.h>
      2 #include <kore/http.h>
      3 
      4 int		page(struct http_request *);
      5 
      6 int
      7 page(struct http_request *req)
      8 {
      9 	float			fl;
     10 	double			dbl;
     11 	int16_t			s16;
     12 	u_int16_t		u16;
     13 	int32_t			s32;
     14 	int64_t			s64;
     15 	u_int64_t		u64;
     16 	u_int32_t		u32;
     17 	size_t			len;
     18 	struct kore_buf		*buf;
     19 	u_int8_t		c, *data;
     20 
     21 	http_populate_get(req);
     22 	buf = kore_buf_alloc(128);
     23 
     24 	if (http_argument_get_byte(req, "id", &c))
     25 		kore_buf_appendf(buf, "byte\t%c\n", c);
     26 
     27 	if (http_argument_get_int16(req, "id", &s16))
     28 		kore_buf_appendf(buf, "int16\t%d\n", s16);
     29 
     30 	if (http_argument_get_uint16(req, "id", &u16))
     31 		kore_buf_appendf(buf, "uint16\t%d\n", u16);
     32 
     33 	if (http_argument_get_int32(req, "id", &s32))
     34 		kore_buf_appendf(buf, "int32\t%d\n", s32);
     35 
     36 	if (http_argument_get_uint32(req, "id", &u32))
     37 		kore_buf_appendf(buf, "uint32\t%d\n", u32);
     38 
     39 	if (http_argument_get_int64(req, "id", &s64))
     40 		kore_buf_appendf(buf, "int64\t%ld\n", s64);
     41 
     42 	if (http_argument_get_uint64(req, "id", &u64))
     43 		kore_buf_appendf(buf, "uint64\t%lu\n", u64);
     44 
     45 	if (http_argument_get_float(req, "id", &fl))
     46 		kore_buf_appendf(buf, "float\t%g\n", fl);
     47 
     48 	if (http_argument_get_double(req, "id", &dbl))
     49 		kore_buf_appendf(buf, "double\t%g\n", dbl);
     50 
     51 	data = kore_buf_release(buf, &len);
     52 	http_response(req, 200, data, len);
     53 	kore_free(data);
     54 
     55 	return (KORE_RESULT_OK);
     56 }