1 /* cvm/client_xfer_compat.c - CVM client command transmission wrappers
2 * Copyright (C) 2010 Bruce Guenter <bruce@untroubled.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program 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
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 #include <sys/types.h>
19 #include <netdb.h>
20 #include <signal.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <sys/wait.h>
24 #include <unistd.h>
25
26 #include <bglibs/sysdeps.h>
27
28 #include "v1client.h"
29
wrapper(const char * module,unsigned char buffer[CVM_BUFSIZE],unsigned * buflen,unsigned (* fn)(const char * module,const struct cvm_packet * request,struct cvm_packet * response))30 static unsigned wrapper(const char* module,
31 unsigned char buffer[CVM_BUFSIZE],
32 unsigned* buflen,
33 unsigned (*fn)(const char* module,
34 const struct cvm_packet* request,
35 struct cvm_packet* response))
36 {
37 struct cvm_packet request;
38 struct cvm_packet response;
39 unsigned result;
40
41 memcpy(request.data, buffer, sizeof buffer);
42 request.length = *buflen;
43 result = fn(module, &request, &response);
44 memcpy(buffer, response.data, sizeof buffer);
45 *buflen = response.length;
46 return result;
47 }
48
49
cvm_xfer_command(const char * module,unsigned char buffer[CVM_BUFSIZE],unsigned * buflen)50 unsigned cvm_xfer_command(const char* module,
51 unsigned char buffer[CVM_BUFSIZE],
52 unsigned* buflen)
53 {
54 return wrapper(module, buffer, buflen, cvm_xfer_command_packets);
55 }
56
cvm_xfer_local(const char * module,unsigned char buffer[CVM_BUFSIZE],unsigned * buflen)57 unsigned cvm_xfer_local(const char* module,
58 unsigned char buffer[CVM_BUFSIZE],
59 unsigned* buflen)
60 {
61 return wrapper(module, buffer, buflen, cvm_xfer_local_packets);
62 }
63
cvm_xfer_udp(const char * module,unsigned char buffer[CVM_BUFSIZE],unsigned * buflen)64 unsigned cvm_xfer_udp(const char* module,
65 unsigned char buffer[CVM_BUFSIZE],
66 unsigned* buflen)
67 {
68 return wrapper(module, buffer, buflen, cvm_xfer_udp_packets);
69 }
70