1 /*	$Id: armsd_miconf_binary.c 20800 2012-01-19 05:13:45Z m-oki $	*/
2 
3 /*
4  * Copyright (c) 2012, Internet Initiative Japan, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include "config.h"
31 
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <inttypes.h>
35 #include <string.h>
36 #include <errno.h>
37 
38 #include <sys/time.h>
39 #include <sys/socket.h>
40 #include <netinet/in.h>
41 
42 #include <libarms.h>
43 
44 #include <armsd_conf.h>
45 #include "armsd_miconf_private.h"
46 #include "armsd_conf_parse.h"
47 
48 int
acmi_clear_conf_buffer(void * dst,int type)49 acmi_clear_conf_buffer(void *dst, int type)
50 {
51        acmi_config_obj_t *acmi = (acmi_config_obj_t *)dst;
52        acmi_config_t *conf = (acmi_config_t *)&acmi->mi_config[type];
53 
54        if (dst == NULL)
55                return -1;
56        if (type < ACMI_CONFIG_RSSOL || type > ACMI_CONFIG_CONFSOL)
57                return -1;
58 
59        memset(conf, 0, sizeof(*conf));
60 
61        return 0;
62 }
63 
64 /* XXX: void * is not good */
65 int
acmi_load_conf_buffer(void * dst,int idx,char * src,int type,size_t len)66 acmi_load_conf_buffer(void *dst, int idx, char *src, int type, size_t len)
67 {
68 	acmi_config_obj_t *acmi = (acmi_config_obj_t *)dst;
69 
70 	if (dst == NULL || src == NULL)
71 		return -1;
72 	if (len <= 0)
73 		return -1;
74 	if (type < ACMI_CONFIG_RSSOL || type > ACMI_CONFIG_CONFSOL)
75 		return -1;
76 
77 	/* XXX: check buffer is US-ASCII text */
78 
79 	return text_config_parse(acmi, idx, src, len);
80 }
81