util.h 855 Bytes
Newer Older
Julian Rother's avatar
Julian Rother committed
1 2 3 4 5 6
#include <unistd.h>
#include <stdarg.h>

/* Generic */
#define SL(s) (s), (sizeof(s)-1)
#define BL(b) (b), (sizeof(b))
Julian Rother's avatar
Julian Rother committed
7
extern int jobid;
Julian Rother's avatar
Julian Rother committed
8

Julian Rother's avatar
Julian Rother committed
9 10 11 12 13
char *vmprintf(const char *fmt, va_list ap);
char *mprintf(const char *fmt, ...);

/* Logging */
void init_avlogbuf(void);
Julian Rother's avatar
Julian Rother committed
14 15 16 17 18
void avlogbuf_callback(void *classp, int level, const char *fmt, va_list ap);
char *get_avlogbuf(void);

/* API */
int ping_job(int id, char *state, char *status, ...);
Julian Rother's avatar
Julian Rother committed
19
void job_failed(char *msg, ...);
Julian Rother's avatar
Julian Rother committed
20 21

/* JSON parser */
Julian Rother's avatar
Julian Rother committed
22
#define JSON_KEY_SIZE 100
Julian Rother's avatar
Julian Rother committed
23 24

ssize_t jbin(char *s, char *buf, size_t len);
Julian Rother's avatar
Julian Rother committed
25 26
char *jstrb(char *s, char *err, char *buf, size_t len);
#define jstr(s, e) jstrb(s, e, (char[JSON_KEY_SIZE]){0}, JSON_KEY_SIZE)
Julian Rother's avatar
Julian Rother committed
27 28 29 30 31
int jint(char *s, int err);
char *jenter(char *s);
char *jnext(char *s);
char *jvalue(char *s);
char *jlookup(char *s, char *key);
Julian Rother's avatar
Julian Rother committed
32 33

/* JSON util */
34
char *jescape(char *s);