]> err.no Git - sope/blob - sope-appserver/mod_ngobjweb/config.c
INSTALL_ROOT_DIR patch
[sope] / sope-appserver / mod_ngobjweb / config.c
1 /*
2   Copyright (C) 2000-2003 SKYRIX Software AG
3
4   This file is part of OGo
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21 // $Id$
22
23 #include "common.h"
24
25 //#define LOG_CONFIG 1
26
27 static char *_makeString(char *buf, char *str, int max) {
28   if (buf == NULL)
29     buf = calloc(max + 10, sizeof(char));
30   
31   strncpy(buf, str, max);
32   buf[max] = '\0';
33   return buf;
34 }
35
36 static char *_makePort(char *port, char *str) {
37   return _makeString(port, str, MAX_PORTNAME_SIZE);
38 }
39
40 static int _domainFromPort(char *port) {
41   if (port == NULL) return AF_INET;
42   return *port == '/' ? AF_UNIX : AF_INET;
43 }
44
45 const char *ngobjweb_set_sns_port(cmd_parms *cmd,
46                                   ngobjweb_dir_config *cfg,
47                                   char *arg)
48 {
49   cfg->snsPort = _makePort(cfg->snsPort, arg);
50   cfg->snsPortDomain = _domainFromPort(cfg->snsPort);
51   
52 #if LOG_CONFIG
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");
57 #endif
58   return NULL;
59 }
60
61 const char *ngobjweb_set_app_port(cmd_parms *cmd,
62                                   ngobjweb_dir_config *cfg,
63                                   char *arg)
64 {
65   cfg->appPort = _makePort(cfg->appPort, arg);
66   cfg->appPortDomain = _domainFromPort(cfg->appPort);
67   
68 #if LOG_CONFIG
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");
73 #endif
74   return NULL;
75 }
76
77 const char *ngobjweb_set_app_prefix(cmd_parms *cmd,
78                                     ngobjweb_dir_config *cfg,
79                                     char *arg)
80 {
81   cfg->appPrefix = _makeString(cfg->appPrefix, arg, MAX_APP_PREFIX_SIZE);
82   return NULL;
83 }
84
85 const char *ngobjweb_set_use_http(cmd_parms *cmd,
86                                   ngobjweb_dir_config *cfg)
87 {
88 #if LOG_CONFIG
89   fprintf(stderr, "%s: using HTTP.\n", __PRETTY_FUNCTION__);
90 #endif
91   cfg->useHTTP = 1;
92   return NULL;
93 }
94
95 void *ngobjweb_create_dir_config(apr_pool_t *p, char *dummy) {
96   ngobjweb_dir_config *new;
97
98   new = apr_palloc(p, sizeof(ngobjweb_dir_config));
99   new->snsPort       = NULL;
100   new->snsPortDomain = AF_UNIX;
101   new->appPort       = NULL;
102   new->appPortDomain = AF_INET;
103   new->appPrefix     = NULL;
104   new->useHTTP       = 0;
105
106 #if LOG_CONFIG
107   fprintf(stderr,"%s: created directory config 0x%08X ...\n",
108           __PRETTY_FUNCTION__, (unsigned)new);
109 #endif
110
111   return new;
112 }
113
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;
118
119   base = (ngobjweb_dir_config *)basev;
120   add  = (ngobjweb_dir_config *)addv;
121   if (add == NULL) add = base;
122   
123   if ((new = apr_palloc(p, sizeof(ngobjweb_dir_config))) == NULL) {
124     fprintf(stderr, "%s: couldn't allocate memory of size %ld\n",
125             __PRETTY_FUNCTION__,
126             (long int) sizeof(ngobjweb_dir_config));
127     return NULL;
128   }
129   
130   new->snsPort       = NULL;
131   new->snsPortDomain = 0;
132   new->appPort       = NULL;
133   new->appPortDomain = 0;
134   new->appPrefix     = NULL;
135   new->useHTTP       = 0;
136   
137   if ((add == NULL) && (base == NULL))
138     goto finish;
139   
140   /* copy base stuff */
141   if (add) {
142     if (add->useHTTP)
143       new->useHTTP = 1;
144     
145     if (add->snsPortDomain)
146       new->snsPortDomain = add->snsPortDomain;
147     else
148       new->snsPortDomain = base ? base->snsPortDomain : 0;
149     
150     if (add->appPortDomain)
151       new->appPortDomain = add->appPortDomain;
152     else
153       new->appPortDomain = base ? base->appPortDomain : 0;
154   }
155   if (base) {
156     if (base->useHTTP)
157       new->useHTTP = 1;
158   }
159
160   /* copy SNS port */
161   if ((add != NULL) && (add->snsPort != NULL)) {
162     if ((new->snsPort = _makePort(NULL, add->snsPort)))
163       new->snsPortDomain = _domainFromPort(new->snsPort);
164   }
165   else if ((base != NULL) && (base->snsPort != NULL)) {
166     if ((new->snsPort = _makePort(NULL, base->snsPort)))
167       new->snsPortDomain = _domainFromPort(new->snsPort);
168   }
169
170   /* copy app port */
171   if ((add != NULL) && (add->appPort != NULL)) {
172     if ((new->appPort = _makePort(NULL, add->appPort)))
173       new->appPortDomain = _domainFromPort(new->appPort);
174   }
175   else if ((base != NULL) && (base->appPort != NULL)) {
176     if ((new->appPort = _makePort(NULL, base->appPort)))
177       new->appPortDomain = _domainFromPort(new->appPort);
178   }
179
180   /* copy app prefix */
181   if (add->appPrefix) {
182     new->appPrefix = _makeString(NULL, add->appPrefix, MAX_APP_PREFIX_SIZE);
183   }
184   else if (base->appPrefix) {
185     new->appPrefix = _makeString(NULL, base->appPrefix, MAX_APP_PREFIX_SIZE);
186   }
187   
188  finish:
189 #if LOG_CONFIG
190   fprintf(stderr,
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"
205          );
206 #endif
207   return new;
208 }