2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 //#define LOG_CONFIG 1
26 static char *_makeString(char *buf, char *str, int max) {
28 buf = calloc(max + 10, sizeof(char));
30 strncpy(buf, str, max);
35 static char *_makePort(char *port, char *str) {
36 return _makeString(port, str, MAX_PORTNAME_SIZE);
39 static int _domainFromPort(char *port) {
40 if (port == NULL) return AF_INET;
41 return *port == '/' ? AF_UNIX : AF_INET;
44 const char *ngobjweb_set_sns_port(cmd_parms *cmd,
45 ngobjweb_dir_config *cfg,
48 cfg->snsPort = _makePort(cfg->snsPort, arg);
49 cfg->snsPortDomain = _domainFromPort(cfg->snsPort);
52 fprintf(stderr, "%s: 0x%08X set snsport to %s, domain %i (http=%s)\n",
53 __PRETTY_FUNCTION__, (unsigned)cfg,
54 cfg->snsPort, cfg->snsPortDomain,
55 cfg->useHTTP ? "yes" : "no");
60 const char *ngobjweb_set_app_port(cmd_parms *cmd,
61 ngobjweb_dir_config *cfg,
64 cfg->appPort = _makePort(cfg->appPort, arg);
65 cfg->appPortDomain = _domainFromPort(cfg->appPort);
68 fprintf(stderr, "%s: 0x%08X set appPort to %s, domain %i (http=%s)\n",
69 __PRETTY_FUNCTION__, (unsigned)cfg,
70 cfg->appPort, cfg->snsPortDomain,
71 cfg->useHTTP ? "yes" : "no");
76 const char *ngobjweb_set_app_prefix(cmd_parms *cmd,
77 ngobjweb_dir_config *cfg,
80 cfg->appPrefix = _makeString(cfg->appPrefix, arg, MAX_APP_PREFIX_SIZE);
84 const char *ngobjweb_set_use_http(cmd_parms *cmd,
85 ngobjweb_dir_config *cfg)
88 fprintf(stderr, "%s: using HTTP.\n", __PRETTY_FUNCTION__);
94 void *ngobjweb_create_dir_config(apr_pool_t *p, char *dummy) {
95 ngobjweb_dir_config *new;
97 new = apr_palloc(p, sizeof(ngobjweb_dir_config));
99 new->snsPortDomain = AF_UNIX;
101 new->appPortDomain = AF_INET;
102 new->appPrefix = NULL;
106 fprintf(stderr,"%s: created directory config 0x%08X ...\n",
107 __PRETTY_FUNCTION__, (unsigned)new);
113 void *ngobjweb_merge_dir_configs(apr_pool_t *p, void *basev, void *addv) {
114 ngobjweb_dir_config *base;
115 ngobjweb_dir_config *add;
116 ngobjweb_dir_config *new;
118 base = (ngobjweb_dir_config *)basev;
119 add = (ngobjweb_dir_config *)addv;
120 if (add == NULL) add = base;
122 if ((new = apr_palloc(p, sizeof(ngobjweb_dir_config))) == NULL) {
123 fprintf(stderr, "%s: couldn't allocate memory of size %ld\n",
125 (long int) sizeof(ngobjweb_dir_config));
130 new->snsPortDomain = 0;
132 new->appPortDomain = 0;
133 new->appPrefix = NULL;
136 if ((add == NULL) && (base == NULL))
139 /* copy base stuff */
144 if (add->snsPortDomain)
145 new->snsPortDomain = add->snsPortDomain;
147 new->snsPortDomain = base ? base->snsPortDomain : 0;
149 if (add->appPortDomain)
150 new->appPortDomain = add->appPortDomain;
152 new->appPortDomain = base ? base->appPortDomain : 0;
160 if ((add != NULL) && (add->snsPort != NULL)) {
161 if ((new->snsPort = _makePort(NULL, add->snsPort)))
162 new->snsPortDomain = _domainFromPort(new->snsPort);
164 else if ((base != NULL) && (base->snsPort != NULL)) {
165 if ((new->snsPort = _makePort(NULL, base->snsPort)))
166 new->snsPortDomain = _domainFromPort(new->snsPort);
170 if ((add != NULL) && (add->appPort != NULL)) {
171 if ((new->appPort = _makePort(NULL, add->appPort)))
172 new->appPortDomain = _domainFromPort(new->appPort);
174 else if ((base != NULL) && (base->appPort != NULL)) {
175 if ((new->appPort = _makePort(NULL, base->appPort)))
176 new->appPortDomain = _domainFromPort(new->appPort);
179 /* copy app prefix */
180 if (add->appPrefix) {
181 new->appPrefix = _makeString(NULL, add->appPrefix, MAX_APP_PREFIX_SIZE);
183 else if (base->appPrefix) {
184 new->appPrefix = _makeString(NULL, base->appPrefix, MAX_APP_PREFIX_SIZE);
190 "MERGE: (base=0x%08X, add=0x%08X, new=0x%08X\n"
191 " BASE: sns:'%s'%i app:'%s'%i prefix:'%s' http:%s\n"
192 " ADD: sns:'%s'%i app:'%s'%i prefix:'%s' http:%s\n"
193 " NEW: sns:'%s'%i app:'%s'%i prefix:'%s' http:%s\n",
194 (unsigned)base, (unsigned)add, (unsigned)new,
195 base->snsPort, base->snsPortDomain,
196 base->appPort, base->appPortDomain,
197 base->appPrefix, base->useHTTP ? "on" : "off",
198 add->snsPort, add->snsPortDomain,
199 add->appPort, add->appPortDomain,
200 add->appPrefix, add->useHTTP ? "on" : "off",
201 new->snsPort, new->snsPortDomain,
202 new->appPort, new->appPortDomain,
203 new->appPrefix, new->useHTTP ? "on" : "off"