[2629906] | 1 | #ifndef __OG_DBI |
---|
| 2 | #define __OG_DBI |
---|
| 3 | |
---|
| 4 | #include <dbi/dbi.h> |
---|
[cbd9421] | 5 | #include <stdbool.h> |
---|
[d2f20d0] | 6 | #include <sys/stat.h> |
---|
[2629906] | 7 | |
---|
| 8 | struct og_dbi_config { |
---|
| 9 | const char *user; |
---|
[fe1ce97] | 10 | const char *pass; |
---|
| 11 | const char *ip; |
---|
[0631b0e] | 12 | const char *port; |
---|
[fe1ce97] | 13 | const char *name; |
---|
[2629906] | 14 | }; |
---|
| 15 | |
---|
| 16 | struct og_dbi { |
---|
| 17 | dbi_conn conn; |
---|
| 18 | dbi_inst inst; |
---|
| 19 | }; |
---|
| 20 | |
---|
| 21 | struct og_dbi *og_dbi_open(struct og_dbi_config *config); |
---|
| 22 | void og_dbi_close(struct og_dbi *db); |
---|
| 23 | |
---|
[9c8e5c7] | 24 | #define OG_DB_COMPUTER_NAME_MAXLEN 100 |
---|
[3d253e6] | 25 | #define OG_DB_CENTER_NAME_MAXLEN 100 |
---|
| 26 | #define OG_DB_ROOM_NAME_MAXLEN 100 |
---|
[29e7641] | 27 | #define OG_DB_ROOM_LOC_MAXLEN 255 |
---|
[f537daf] | 28 | #define OG_DB_SERIAL_NUMBER_MAXLEN 25 |
---|
[d2f20d0] | 29 | #define OG_DB_IMAGE_DESCRIPTION_MAXLEN 250 |
---|
[047677b] | 30 | #define OG_DB_PART_NAME_MAXLEN 250 |
---|
[04ca20e] | 31 | #define OG_DB_IMAGE_NAME_MAXLEN 50 |
---|
| 32 | #define OG_DB_FILESYSTEM_MAXLEN 16 |
---|
[f537daf] | 33 | #define OG_DB_NETDRIVER_MAXLEN 30 |
---|
| 34 | #define OG_DB_NETIFACE_MAXLEN 4 |
---|
| 35 | #define OG_DB_LIVEDIR_MAXLEN 50 |
---|
[04ca20e] | 36 | #define OG_DB_INT8_MAXLEN 8 |
---|
[f537daf] | 37 | #define OG_DB_BOOT_MAXLEN 30 |
---|
[04ca20e] | 38 | #define OG_DB_INT_MAXLEN 11 |
---|
[f537daf] | 39 | #define OG_DB_MAC_MAXLEN 15 |
---|
[04ca20e] | 40 | #define OG_DB_IP_MAXLEN 15 |
---|
| 41 | #define OG_DB_SMALLINT_MAXLEN 6 |
---|
| 42 | |
---|
| 43 | struct og_image_legacy { |
---|
| 44 | char software_id[OG_DB_INT_MAXLEN + 1]; |
---|
| 45 | char image_id[OG_DB_INT_MAXLEN + 1]; |
---|
| 46 | char name[OG_DB_IMAGE_NAME_MAXLEN + 1]; |
---|
| 47 | char repo[OG_DB_IP_MAXLEN + 1]; |
---|
| 48 | char part[OG_DB_SMALLINT_MAXLEN + 1]; |
---|
| 49 | char disk[OG_DB_SMALLINT_MAXLEN + 1]; |
---|
| 50 | char code[OG_DB_INT8_MAXLEN + 1]; |
---|
| 51 | }; |
---|
| 52 | |
---|
[d2f20d0] | 53 | struct og_image { |
---|
| 54 | char name[OG_DB_IMAGE_NAME_MAXLEN + 1]; |
---|
| 55 | char description[OG_DB_IMAGE_DESCRIPTION_MAXLEN + 1]; |
---|
[b86b6e1] | 56 | char repo_ip[OG_DB_IP_MAXLEN + 1]; |
---|
[d8b78bb] | 57 | uint64_t software_id; |
---|
[d2f20d0] | 58 | uint64_t center_id; |
---|
| 59 | uint64_t datasize; |
---|
| 60 | uint64_t group_id; |
---|
[52a38d3] | 61 | uint64_t repo_id; |
---|
[d8b78bb] | 62 | uint64_t type; |
---|
| 63 | uint64_t id; |
---|
[d2f20d0] | 64 | struct stat image_stats; |
---|
| 65 | }; |
---|
| 66 | |
---|
[04ca20e] | 67 | struct og_legacy_partition { |
---|
| 68 | char partition[OG_DB_SMALLINT_MAXLEN + 1]; |
---|
[047677b] | 69 | char code[OG_DB_PART_NAME_MAXLEN + 1]; |
---|
[04ca20e] | 70 | char size[OG_DB_INT_MAXLEN + 1]; |
---|
| 71 | char filesystem[OG_DB_FILESYSTEM_MAXLEN + 1]; |
---|
| 72 | char format[2]; /* Format is a boolean 0 or 1 => length is 2 */ |
---|
| 73 | }; |
---|
| 74 | |
---|
[3cb98c7] | 75 | struct og_computer { |
---|
[cbd9421] | 76 | unsigned int procedure_id; |
---|
| 77 | unsigned int hardware_id; |
---|
| 78 | unsigned int repo_id; |
---|
[3cb98c7] | 79 | unsigned int center; |
---|
| 80 | unsigned int room; |
---|
[cbd9421] | 81 | unsigned int id; |
---|
| 82 | bool maintenance; |
---|
| 83 | bool remote; |
---|
[f537daf] | 84 | char serial_number[OG_DB_SERIAL_NUMBER_MAXLEN + 1]; |
---|
| 85 | char netdriver[OG_DB_NETDRIVER_MAXLEN + 1]; |
---|
| 86 | char name[OG_DB_COMPUTER_NAME_MAXLEN + 1]; |
---|
| 87 | char netiface[OG_DB_NETIFACE_MAXLEN + 1]; |
---|
| 88 | char livedir[OG_DB_LIVEDIR_MAXLEN + 1]; |
---|
| 89 | char netmask[OG_DB_IP_MAXLEN + 1]; |
---|
| 90 | char boot[OG_DB_BOOT_MAXLEN + 1]; |
---|
| 91 | char mac[OG_DB_MAC_MAXLEN + 1]; |
---|
| 92 | char ip[OG_DB_IP_MAXLEN + 1]; |
---|
[3cb98c7] | 93 | }; |
---|
| 94 | |
---|
[29e7641] | 95 | struct og_room { |
---|
| 96 | uint32_t center; |
---|
| 97 | uint32_t group; |
---|
| 98 | char location[OG_DB_ROOM_LOC_MAXLEN + 1]; |
---|
| 99 | char name[OG_DB_ROOM_NAME_MAXLEN + 1]; |
---|
| 100 | char gateway[OG_DB_IP_MAXLEN + 1]; |
---|
| 101 | char netmask[OG_DB_IP_MAXLEN + 1]; |
---|
| 102 | char ntp[OG_DB_IP_MAXLEN + 1]; |
---|
| 103 | char dns[OG_DB_IP_MAXLEN + 1]; |
---|
| 104 | bool remote; |
---|
| 105 | }; |
---|
| 106 | |
---|
[3cb98c7] | 107 | struct in_addr; |
---|
[d7e2022] | 108 | int og_dbi_get_computer_info(struct og_dbi *dbi, struct og_computer *computer, |
---|
| 109 | struct in_addr addr); |
---|
[d2f20d0] | 110 | int og_dbi_add_image(struct og_dbi *dbi, const struct og_image *image); |
---|
[3cb98c7] | 111 | |
---|
[7d74d42] | 112 | int og_dbi_schema_update(void); |
---|
| 113 | |
---|
[52a38d3] | 114 | int og_dbi_get_repository_ip(const struct og_dbi *dbi, const uint64_t image_id, |
---|
| 115 | char *repository_ip); |
---|
| 116 | |
---|
[2629906] | 117 | #endif |
---|