2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
6 OGo 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 OGo 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 OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 //#define LOG_CONFIG 1
27 static char *_makeString(char *buf, char *str, int max) {
29 buf = calloc(max + 10, sizeof(char));
31 strncpy(buf, str, max);
36 static char *_makePort(char *port, char *str) {
37 return _makeString(port, str, MAX_PORTNAME_SIZE);
40 static int _domainFromPort(char *port) {
41 if (port == NULL) return AF_INET;
42 return *port == '/' ? AF_UNIX : AF_INET;
45 const char *ngobjweb_set_sns_port(cmd_parms *cmd,
46 ngobjweb_dir_config *cfg,
49 cfg->snsPort = _makePort(cfg->snsPort, arg);
50 cfg->snsPortDomain = _domainFromPort(cfg->snsPort);
53 fprintf(stderr, "%s: 0x%08X set snsport to %s, domain %i (http=%s)\n",
54 __PRETTY_FUNCTION__, (unsigned)cfg,
55 cfg->snsPort, cfg->snsPortDomain,
56 cfg->useHTTP ? "yes" : "no");
61 const char *ngobjweb_set_app_port(cmd_parms *cmd,
62 ngobjweb_dir_config *cfg,
65 cfg->appPort = _makePort(cfg->appPort, arg);
66 cfg->appPortDomain = _domainFromPort(cfg->appPort);
69 fprintf(stderr, "%s: 0x%08X set appPort to %s, domain %i (http=%s)\n",
70 __PRETTY_FUNCTION__, (unsigned)cfg,
71 cfg->appPort, cfg->snsPortDomain,
72 cfg->useHTTP ? "yes" : "no");
77 const char *ngobjweb_set_app_prefix(cmd_parms *cmd,
78 ngobjweb_dir_config *cfg,
81 cfg->appPrefix = _makeString(cfg->appPrefix, arg, MAX_APP_PREFIX_SIZE);
85 const char *ngobjweb_set_use_http(cmd_parms *cmd,
86 ngobjweb_dir_config *cfg)
89 fprintf(stderr, "%s: using HTTP.\n", __PRETTY_FUNCTION__);
95 void *ngobjweb_create_dir_config(apr_pool_t *p, char *dummy) {
96 ngobjweb_dir_config *new;
98 new = apr_palloc(p, sizeof(ngobjweb_dir_config));
100 new->snsPortDomain = AF_UNIX;
102 new->appPortDomain = AF_INET;
103 new->appPrefix = NULL;
107 fprintf(stderr,"%s: created directory config 0x%08X ...\n",
108 __PRETTY_FUNCTION__, (unsigned)new);
114 void *ngobjweb_merge_dir_configs(apr_pool_t *p, void *basev, void *addv) {
115 ngobjweb_dir_config *base;
116 ngobjweb_dir_config *add;
117 ngobjweb_dir_config *new;
119 base = (ngobjweb_dir_config *)basev;
120 add = (ngobjweb_dir_config *)addv;
121 if (add == NULL) add = base;
123 if ((new = apr_palloc(p, sizeof(ngobjweb_dir_config))) == NULL) {
124 fprintf(stderr, "%s: couldn't allocate memory of size %ld\n",
126 (long int) sizeof(ngobjweb_dir_config));
131 new->snsPortDomain = 0;
133 new->appPortDomain = 0;
134 new->appPrefix = NULL;
137 if ((add == NULL) && (base == NULL))
140 /* copy base stuff */
145 if (add->snsPortDomain)
146 new->snsPortDomain = add->snsPortDomain;
148 new->snsPortDomain = base ? base->snsPortDomain : 0;
150 if (add->appPortDomain)
151 new->appPortDomain = add->appPortDomain;
153 new->appPortDomain = base ? base->appPortDomain : 0;
161 if ((add != NULL) && (add->snsPort != NULL)) {
162 if ((new->snsPort = _makePort(NULL, add->snsPort)))
163 new->snsPortDomain = _domainFromPort(new->snsPort);
165 else if ((base != NULL) && (base->snsPort != NULL)) {
166 if ((new->snsPort = _makePort(NULL, base->snsPort)))
167 new->snsPortDomain = _domainFromPort(new->snsPort);
171 if ((add != NULL) && (add->appPort != NULL)) {
172 if ((new->appPort = _makePort(NULL, add->appPort)))
173 new->appPortDomain = _domainFromPort(new->appPort);
175 else if ((base != NULL) && (base->appPort != NULL)) {
176 if ((new->appPort = _makePort(NULL, base->appPort)))
177 new->appPortDomain = _domainFromPort(new->appPort);
180 /* copy app prefix */
181 if (add->appPrefix) {
182 new->appPrefix = _makeString(NULL, add->appPrefix, MAX_APP_PREFIX_SIZE);
184 else if (base->appPrefix) {
185 new->appPrefix = _makeString(NULL, base->appPrefix, MAX_APP_PREFIX_SIZE);
191 "MERGE: (base=0x%08X, add=0x%08X, new=0x%08X\n"
192 " BASE: sns:'%s'%i app:'%s'%i prefix:'%s' http:%s\n"
193 " ADD: sns:'%s'%i app:'%s'%i prefix:'%s' http:%s\n"
194 " NEW: sns:'%s'%i app:'%s'%i prefix:'%s' http:%s\n",
195 (unsigned)base, (unsigned)add, (unsigned)new,
196 base->snsPort, base->snsPortDomain,
197 base->appPort, base->appPortDomain,
198 base->appPrefix, base->useHTTP ? "on" : "off",
199 add->snsPort, add->snsPortDomain,
200 add->appPort, add->appPortDomain,
201 add->appPrefix, add->useHTTP ? "on" : "off",
202 new->snsPort, new->snsPortDomain,
203 new->appPort, new->appPortDomain,
204 new->appPrefix, new->useHTTP ? "on" : "off"