summaryrefslogtreecommitdiffstats
path: root/src/dbi.h
blob: 84b898cafa988e89e1a76d64a825152980a03aec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef __OG_DBI
#define __OG_DBI

#include <dbi/dbi.h>
#include <stdbool.h>

struct og_dbi_config {
	const char	*user;
	const char	*passwd;
	const char	*host;
	const char	*port;
	const char	*database;
};

struct og_dbi {
	dbi_conn	conn;
	dbi_inst	inst;
};

struct og_dbi *og_dbi_open(struct og_dbi_config *config);
void og_dbi_close(struct og_dbi *db);

#define OG_DB_COMPUTER_NAME_MAXLEN	100
#define OG_DB_CENTER_NAME_MAXLEN	100
#define OG_DB_ROOM_NAME_MAXLEN		100
#define OG_DB_IMAGE_NAME_MAXLEN 50
#define OG_DB_FILESYSTEM_MAXLEN 16
#define OG_DB_INT8_MAXLEN	8
#define OG_DB_INT_MAXLEN	11
#define OG_DB_IP_MAXLEN		15
#define OG_DB_SMALLINT_MAXLEN	6

struct og_image_legacy {
	char software_id[OG_DB_INT_MAXLEN + 1];
	char image_id[OG_DB_INT_MAXLEN + 1];
	char name[OG_DB_IMAGE_NAME_MAXLEN + 1];
	char repo[OG_DB_IP_MAXLEN + 1];
	char part[OG_DB_SMALLINT_MAXLEN + 1];
	char disk[OG_DB_SMALLINT_MAXLEN + 1];
	char code[OG_DB_INT8_MAXLEN + 1];
};

struct og_legacy_partition {
	char partition[OG_DB_SMALLINT_MAXLEN + 1];
	char code[OG_DB_INT8_MAXLEN + 1];
	char size[OG_DB_INT_MAXLEN + 1];
	char filesystem[OG_DB_FILESYSTEM_MAXLEN + 1];
	char format[2]; /* Format is a boolean 0 or 1 => length is 2 */
};

extern struct og_dbi_config dbi_config;

struct og_computer {
	unsigned int	procedure_id;
	unsigned int	hardware_id;
	unsigned int	repo_id;
	unsigned int	center;
	unsigned int	room;
	unsigned int	id;
	bool		maintenance;
	bool		remote;
	char		*serial_number;
	char		*netdriver;
	char		*netiface;
	char		*netmask;
	char		*livedir;
	char		*name;
	char		*boot;
	char		*mac;
	char		*ip;
};

struct in_addr;
int og_dbi_get_computer_info(struct og_dbi *dbi, struct og_computer *computer,
			     struct in_addr addr);
void og_dbi_free_computer_info(struct og_computer *computer);

#endif