Add API: set-wrappid-path.
[wrappi.git] / lib / connect.c
1 /* wrappi
2  * Copyright (C) 2011-2012 Red Hat Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18
19 #include <config.h>
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <assert.h>
24
25 #include "wrappi.h"
26 #include "internal.h"
27
28 void
29 wrap_connect (wrap_h *w)
30 {
31   switch (w->scheme) {
32   case WRAP_SCHEME_LOCAL:
33     /* nothing needed */
34     return;
35
36   case WRAP_SCHEME_SSH:
37     wrap_int_connect_ssh (w);
38     return;
39
40   default:
41     set_error ("invalid scheme");
42     return;
43   }
44 }
45
46 void
47 wrap_set_scheme (wrap_h *w, wrap_scheme_enum scheme)
48 {
49   if (scheme < 0 || scheme >= wrap_scheme_enum_nr(w)) {
50     set_error ("scheme out of range");
51     return;
52   }
53   w->scheme = scheme;
54 }
55
56 void
57 wrap_set_hostname (wrap_h *w, const char *hostname)
58 {
59   if (hostname == NULL || strlen (hostname) == 0) {
60     set_error ("invalid hostname");
61     return;
62   }
63   w->hostname = strdup (hostname);
64   if (!w->hostname)
65     set_error_errno ("strdup");
66 }
67
68 void
69 wrap_set_wrappid_path (wrap_h *w, const char *wrappid)
70 {
71   if (wrappid == NULL || strlen (wrappid) == 0 || wrappid[0] != '/') {
72     set_error ("invalid path");
73     return;
74   }
75   w->wrappid_path = strdup (wrappid);
76   if (!w->wrappid_path)
77     set_error_errno ("strdup");
78 }
79
80 void
81 wrap_int_make_request (wrap_h *w, int proc_nr, const void *args, void *ret)
82 {
83   switch (w->scheme) {
84   case WRAP_SCHEME_LOCAL:
85     abort (); /* shouldn't be reachable */
86
87     /* XDR-based methods. */
88   case WRAP_SCHEME_SSH:
89     wrap_int_make_request_xdr (w, proc_nr, args, ret);
90     break;
91
92   default:
93     set_error ("invalid scheme");
94   }
95 }