Unused variable cleanup
[openafs.git] / src / bucoord / config.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12
13
14 #include <sys/types.h>
15 #ifdef AFS_NT40_ENV
16 #include <winsock2.h>
17 #else
18 #include <sys/socket.h>
19 #include <netinet/in.h>
20 #include <netdb.h>
21 #endif
22 #include <errno.h>
23
24 #include "bc.h"
25
26 struct bc_config *bc_globalConfig;
27
28 #if 0
29 static int
30 TrimLine(char *abuffer, afs_int32 *aport)
31 {
32     register int tc;
33     char garb[100];
34
35     *aport = 0;
36     sscanf(abuffer, "%s %u", garb, aport);
37     while ((tc = *abuffer)) {
38         if (tc == ' ') {
39             *abuffer = 0;
40             return 0;
41         }
42         abuffer++;
43     }
44     return 0;
45 }
46 #endif
47
48 FILE *
49 bc_open(struct bc_config *aconfig, char *aname, char *aext, char *amode)
50 {
51     register FILE *tf;
52     char tpath[256];
53
54     strcpy(tpath, aconfig->path);
55     strcat(tpath, "/");
56     strcat(tpath, aname);
57     if (aext)
58         strcat(tpath, aext);
59     tf = fopen(tpath, amode);
60     return tf;
61 }
62
63 int
64 bc_InitConfig(char *apath)
65 {
66     register struct bc_config *tb;
67
68     /* initialize global config structure */
69     tb = (struct bc_config *)malloc(sizeof(struct bc_config));
70     if (!tb)
71         return (BC_NOMEM);
72
73     bc_globalConfig = tb;
74     memset(tb, 0, sizeof(struct bc_config));
75     tb->path = (char *)malloc(strlen(apath) + 1);
76     if (!tb->path) {
77         free(tb);
78         return (BC_NOMEM);
79     }
80
81     strcpy(tb->path, apath);
82
83     /* now read the important config files; no file means empty list during system init */
84
85     return 0;
86 }
87
88 static int
89 HostAdd(struct bc_hostEntry **alist, char *aname, afs_int32 aport)
90 {
91     register struct bc_hostEntry **tlast, *tentry;
92     struct hostent *th;
93
94     /* check that the host address is real */
95     th = gethostbyname(aname);
96     if (!th)
97         return -1;
98
99     /* check if this guy is already in the list */
100     for (tentry = *alist; tentry; tentry = tentry->next)
101         if (tentry->portOffset == aport)
102             return EEXIST;
103
104     /* add this guy to the end of the list */
105     tlast = alist;
106     for (tentry = *tlast; tentry; tlast = &tentry->next, tentry = *tlast);
107
108     /* tlast now points to the next pointer (or head pointer) we should overwrite */
109     tentry = (struct bc_hostEntry *)malloc(sizeof(struct bc_hostEntry));
110     memset(tentry, 0, sizeof(*tentry));
111     tentry->name = (char *)malloc(strlen(aname) + 1);
112     strcpy(tentry->name, aname);
113     *tlast = tentry;
114     tentry->next = (struct bc_hostEntry *)0;
115     tentry->addr.sin_family = AF_INET;
116     memcpy(&tentry->addr.sin_addr.s_addr, th->h_addr, sizeof(afs_int32));
117     tentry->addr.sin_port = 0;
118 #ifdef STRUCT_SOCKADDR_HAS_SA_LEN
119     tentry->addr.sin_len = sizeof(struct sockaddr_in);
120 #endif
121     tentry->portOffset = aport;
122     return 0;
123 }
124
125 static int
126 HostDelete(struct bc_hostEntry **alist, char *aname, afs_int32 aport)
127 {
128     register struct bc_hostEntry **tlast, *tentry;
129
130     /* find guy to zap */
131     tlast = alist;
132     for (tentry = *tlast; tentry; tlast = &tentry->next, tentry = *tlast)
133         if (strcmp(tentry->name, aname) == 0 && (aport == tentry->portOffset))
134             break;
135     if (!tentry)
136         return ENOENT;          /* failed to find it */
137
138     /* otherwise delete the entry from the list and free appropriate structures */
139     *tlast = tentry->next;
140     free(tentry->name);
141     free(tentry);
142     return 0;
143 }
144
145 int
146 bc_AddTapeHost(struct bc_config *aconfig, char *aname, afs_int32 aport)
147 {
148     register afs_int32 code;
149
150     code = HostAdd(&aconfig->tapeHosts, aname, aport);
151
152     return code;
153 }
154
155 int
156 bc_DeleteTapeHost(struct bc_config *aconfig, char *aname, afs_int32 aport)
157 {
158     register afs_int32 code;
159
160     code = HostDelete(&aconfig->tapeHosts, aname, aport);
161
162     return code;
163 }