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