1 #ifndef BACKEND_H 2 #define BACKEND_H 3 4 #include <stddef.h> 5 #include <inttypes.h> 6 #include <stdbool.h> 7 #include <zlib.h> 8 #include "serial.h" 9 #include "tftp.h" 10 11 /* Backend flags */ 12 #define BE_NEEDLEN 0x01 13 14 struct upload_backend { 15 const char *name; 16 const char *helpmsg; 17 int minargs; 18 19 size_t dbytes; 20 size_t zbytes; 21 const char **argv; 22 23 uint32_t now; 24 25 int (*write)(struct upload_backend *); 26 27 z_stream zstream; 28 char *outbuf; 29 size_t alloc; 30 }; 31 32 /* zout.c */ 33 int init_data(struct upload_backend *be, const char *argv[]); 34 int write_data(struct upload_backend *be, const void *buf, size_t len); 35 int flush_data(struct upload_backend *be); 36 37 /* cpio.c */ 38 #define cpio_init init_data 39 int cpio_hdr(struct upload_backend *be, uint32_t mode, size_t datalen, 40 const char *filename); 41 int cpio_mkdir(struct upload_backend *be, const char *filename); 42 int cpio_writefile(struct upload_backend *be, const char *filename, 43 const void *data, size_t len); 44 int cpio_close(struct upload_backend *be); 45 #define MODE_FILE 0100644 46 #define MODE_DIR 0040755 47 48 /* backends.c */ 49 struct upload_backend *get_upload_backend(const char *name); 50 51 /* backends */ 52 extern struct upload_backend upload_tftp; 53 extern struct upload_backend upload_ymodem; 54 extern struct upload_backend upload_srec; 55 56 #endif /* BACKEND_H */ 57