aboutsummaryrefslogtreecommitdiffstats
path: root/tools/xenstore/xenstored_core.h
blob: a82ae8b22e7074b71174cd73f22fb52052345ac5 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* 
    Internal interfaces for Xen Store Daemon.
    Copyright (C) 2005 Rusty Russell IBM Corporation

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#ifndef _XENSTORED_CORE_H
#define _XENSTORED_CORE_H

#include <stdbool.h>
#include <stdint.h>
#include <errno.h>
#include "xs_lib.h"
#include "xenstored.h"
#include "list.h"

struct buffered_data
{
	/* Are we still doing the header? */
	bool inhdr;
	/* How far are we? */
	unsigned int used;
	union {
		struct xsd_sockmsg msg;
		char raw[sizeof(struct xsd_sockmsg)];
	} hdr;
	/* The actual data. */
	char *buffer;
};

struct connection;
typedef int connwritefn_t(struct connection *, const void *, unsigned int);
typedef int connreadfn_t(struct connection *, void *, unsigned int);

struct connection
{
	struct list_head list;

	/* The file descriptor we came in on. */
	int fd;

	/* Who am I?  0 for socket connections. */
	domid_t id;

	/* Are we blocked waiting for a transaction to end?  Contains node. */
	char *blocked;

	/* Is this a read-only connection? */
	bool can_write;

	/* Are we waiting for a watch event ack? */
	bool waiting_for_ack;

	/* Buffered incoming data. */
	struct buffered_data *in;

	/* Buffered output data */
	struct buffered_data *out;

	/* If we had a watch fire outgoing when we needed to reply... */
	struct buffered_data *waiting_reply;

	/* My transaction, if any. */
	struct transaction *transaction;

	/* The domain I'm associated with, if any. */
	struct domain *domain;

	/* Methods for communicating over this connection: write can be NULL */
	connwritefn_t *write;
	connreadfn_t *read;
};

/* Return length of string (including nul) at this offset. */
unsigned int get_string(const struct buffered_data *data,
			unsigned int offset);

/* Break input into vectors, return the number, fill in up to num of them. */
unsigned int get_strings(struct buffered_data *data,
			 char *vec[], unsigned int num);

/* Is child node a child or equal to parent node? */
bool is_child(const char *child, const char *parent);

/* Create a new buffer with lifetime of context. */
struct buffered_data *new_buffer(void *ctx);

bool send_reply(struct connection *conn, enum xsd_sockmsg_type type,
                const void *data, unsigned int len);

/* Some routines (write, mkdir, etc) just need a non-error return */
bool send_ack(struct connection *conn, enum xsd_sockmsg_type type);

/* Send an error: error is usually "errno". */
bool send_error(struct connection *conn, int error);

/* Canonicalize this path if possible. */
char *canonicalize(struct connection *conn, const char *node);

/* Check permissions on this node. */
bool check_node_perms(struct connection *conn, const char *node,
		      enum xs_perm_type perm);

/* Path to this node outside transaction. */
char *node_dir_outside_transaction(const char *node);

/* Fail due to excessive corruption, capitalist pigdogs! */
void __attribute__((noreturn)) corrupt(struct connection *conn,
				       const char *fmt, ...);

struct connection *new_connection(connwritefn_t *write, connreadfn_t *read);

void handle_input(struct connection *conn);
void handle_output(struct connection *conn);

/* Is this a valid node name? */
bool is_valid_nodename(const char *node);

/* Convenient talloc-style destructor for paths. */
int destroy_path(void *path);

#endif /* _XENSTORED_CORE_H */