summaryrefslogtreecommitdiffstats
path: root/daemon/stubs.c
blob: 4eccfb5b946012538a3839156038f6474f0b53ea (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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/* libguestfs generated file
 * WARNING: THIS FILE IS GENERATED BY 'src/generator.ml'.
 * ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST.
 *
 * Copyright (C) 2009 Red Hat Inc.
 *
 * 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.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include <rpc/types.h>
#include <rpc/xdr.h>
#include "daemon.h"
#include "../src/guestfs_protocol.h"
#include "actions.h"

static void cat_stub (XDR *xdr_in)
{
  char *r;
  struct guestfs_cat_args args;
  const char *path;

  memset (&args, 0, sizeof args);

  if (!xdr_guestfs_cat_args (xdr_in, &args)) {
    reply_with_error ("cat: daemon failed to decode procedure arguments");
    return;
  }
  path = args.path;

  r = do_cat (path);
  if (r == NULL)
    /* do_cat has already called reply_with_error, so just return */
    return;

  struct guestfs_cat_ret ret;
  ret.content = r;
  reply ((xdrproc_t) &xdr_guestfs_cat_ret, (char *) &ret);
  free (r);
}

static void ll_stub (XDR *xdr_in)
{
  char *r;
  struct guestfs_ll_args args;
  const char *directory;

  memset (&args, 0, sizeof args);

  if (!xdr_guestfs_ll_args (xdr_in, &args)) {
    reply_with_error ("ll: daemon failed to decode procedure arguments");
    return;
  }
  directory = args.directory;

  r = do_ll (directory);
  if (r == NULL)
    /* do_ll has already called reply_with_error, so just return */
    return;

  struct guestfs_ll_ret ret;
  ret.listing = r;
  reply ((xdrproc_t) &xdr_guestfs_ll_ret, (char *) &ret);
  free (r);
}

static void ls_stub (XDR *xdr_in)
{
  char **r;
  struct guestfs_ls_args args;
  const char *directory;

  memset (&args, 0, sizeof args);

  if (!xdr_guestfs_ls_args (xdr_in, &args)) {
    reply_with_error ("ls: daemon failed to decode procedure arguments");
    return;
  }
  directory = args.directory;

  r = do_ls (directory);
  if (r == NULL)
    /* do_ls has already called reply_with_error, so just return */
    return;

  struct guestfs_ls_ret ret;
  ret.listing.listing_len = count_strings (r);
  ret.listing.listing_val = r;
  reply ((xdrproc_t) &xdr_guestfs_ls_ret, (char *) &ret);
  free_strings (r);
}

static void mount_stub (XDR *xdr_in)
{
  int r;
  struct guestfs_mount_args args;
  const char *device;
  const char *mountpoint;

  memset (&args, 0, sizeof args);

  if (!xdr_guestfs_mount_args (xdr_in, &args)) {
    reply_with_error ("mount: daemon failed to decode procedure arguments");
    return;
  }
  device = args.device;
  mountpoint = args.mountpoint;

  r = do_mount (device, mountpoint);
  if (r == -1)
    /* do_mount has already called reply_with_error, so just return */
    return;

  reply (NULL, NULL);
}

static void sync_stub (XDR *xdr_in)
{
  int r;

  r = do_sync ();
  if (r == -1)
    /* do_sync has already called reply_with_error, so just return */
    return;

  reply (NULL, NULL);
}

static void touch_stub (XDR *xdr_in)
{
  int r;
  struct guestfs_touch_args args;
  const char *path;

  memset (&args, 0, sizeof args);

  if (!xdr_guestfs_touch_args (xdr_in, &args)) {
    reply_with_error ("touch: daemon failed to decode procedure arguments");
    return;
  }
  path = args.path;

  r = do_touch (path);
  if (r == -1)
    /* do_touch has already called reply_with_error, so just return */
    return;

  reply (NULL, NULL);
}

void dispatch_incoming_message (XDR *xdr_in)
{
  switch (proc_nr) {
    case GUESTFS_PROC_CAT:
      cat_stub (xdr_in);
      break;
    case GUESTFS_PROC_LL:
      ll_stub (xdr_in);
      break;
    case GUESTFS_PROC_LS:
      ls_stub (xdr_in);
      break;
    case GUESTFS_PROC_MOUNT:
      mount_stub (xdr_in);
      break;
    case GUESTFS_PROC_SYNC:
      sync_stub (xdr_in);
      break;
    case GUESTFS_PROC_TOUCH:
      touch_stub (xdr_in);
      break;
    default:
      reply_with_error ("dispatch_incoming_message: unknown procedure number %d", proc_nr);
  }
}