gwenhywfar  4.99.15beta
url.c
Go to the documentation of this file.
1 /* This file is auto-generated from "url.xml" by the typemaker
2  tool of Gwenhywfar.
3  Do not edit this file -- all changes will be lost! */
4 #ifdef HAVE_CONFIG_H
5 # include "config.h"
6 #endif
7 
8 #include "url_p.h"
9 #include <gwenhywfar/misc.h>
10 #include <gwenhywfar/db.h>
11 #include <gwenhywfar/debug.h>
12 #include <assert.h>
13 #include <stdlib.h>
14 #include <strings.h>
15 
16 #include <gwenhywfar/types.h>
17 #include <gwenhywfar/urlfns.h>
18 
19 
22 
23 
24 
25 
27 {
28  GWEN_URL *st;
29 
31  st->_usage=1;
33  st->vars=GWEN_DB_Group_new("vars");
34  return st;
35 }
36 
37 
39 {
40  if (st) {
41  assert(st->_usage);
42  if (--(st->_usage)==0) {
43  if (st->protocol)
44  free(st->protocol);
45  if (st->server)
46  free(st->server);
47  if (st->path)
48  free(st->path);
49  if (st->userName)
50  free(st->userName);
51  if (st->password)
52  free(st->password);
53  if (st->vars)
54  GWEN_DB_Group_free(st->vars);
55  if (st->url)
56  free(st->url);
58  GWEN_FREE_OBJECT(st);
59  }
60  }
61 
62 }
63 
64 
66 {
67  GWEN_URL *st;
68 
69  assert(d);
70  st=GWEN_Url_new();
71  if (d->protocol)
72  st->protocol=strdup(d->protocol);
73  if (d->server)
74  st->server=strdup(d->server);
75  st->port=d->port;
76  if (d->path)
77  st->path=strdup(d->path);
78  if (d->userName)
79  st->userName=strdup(d->userName);
80  if (d->password)
81  st->password=strdup(d->password);
82  if (d->vars) {
83  GWEN_DB_Group_free(st->vars);
84  st->vars=GWEN_DB_Group_dup(d->vars);
85  }
86  if (d->url)
87  st->url=strdup(d->url);
88  return st;
89 }
90 
91 
92 int GWEN_Url_toDb(const GWEN_URL *st, GWEN_DB_NODE *db)
93 {
94  assert(st);
95  assert(db);
96  if (st->protocol)
97  if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "protocol", st->protocol))
98  return -1;
99  if (st->server)
100  if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "server", st->server))
101  return -1;
102  if (GWEN_DB_SetIntValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "port", st->port))
103  return -1;
104  if (st->path)
105  if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "path", st->path))
106  return -1;
107  if (st->userName)
108  if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "userName", st->userName))
109  return -1;
110  if (st->password)
111  if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "password", st->password))
112  return -1;
113  if (st->vars)
115  return -1;
116  if (st->url)
117  if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "url", st->url))
118  return -1;
119  return 0;
120 }
121 
122 
124 {
125  assert(st);
126  assert(db);
127  GWEN_Url_SetProtocol(st, GWEN_DB_GetCharValue(db, "protocol", 0, 0));
128  GWEN_Url_SetServer(st, GWEN_DB_GetCharValue(db, "server", 0, 0));
129  GWEN_Url_SetPort(st, GWEN_DB_GetIntValue(db, "port", 0, 0));
130  GWEN_Url_SetPath(st, GWEN_DB_GetCharValue(db, "path", 0, 0));
131  GWEN_Url_SetUserName(st, GWEN_DB_GetCharValue(db, "userName", 0, 0));
132  GWEN_Url_SetPassword(st, GWEN_DB_GetCharValue(db, "password", 0, 0));
133  if (1) { /* for local vars */
134  GWEN_DB_NODE *dbT;
135 
137  if (dbT) {
138  if (st->vars)
139  GWEN_DB_Group_free(st->vars);
140  st->vars=GWEN_DB_Group_dup(dbT);
141  }
142  }
143  GWEN_Url_SetUrl(st, GWEN_DB_GetCharValue(db, "url", 0, 0));
144  return 0;
145 }
146 
147 
149 {
150  GWEN_URL *st;
151 
152  assert(db);
153  st=GWEN_Url_new();
154  GWEN_Url_ReadDb(st, db);
155  st->_modified=0;
156  return st;
157 }
158 
159 
160 
161 
162 const char *GWEN_Url_GetProtocol(const GWEN_URL *st)
163 {
164  assert(st);
165  return st->protocol;
166 }
167 
168 
169 void GWEN_Url_SetProtocol(GWEN_URL *st, const char *d)
170 {
171  assert(st);
172  if (st->protocol)
173  free(st->protocol);
174  if (d && *d)
175  st->protocol=strdup(d);
176  else
177  st->protocol=0;
178  st->_modified=1;
179 }
180 
181 
182 
183 
184 const char *GWEN_Url_GetServer(const GWEN_URL *st)
185 {
186  assert(st);
187  return st->server;
188 }
189 
190 
191 void GWEN_Url_SetServer(GWEN_URL *st, const char *d)
192 {
193  assert(st);
194  if (st->server)
195  free(st->server);
196  if (d && *d)
197  st->server=strdup(d);
198  else
199  st->server=0;
200  st->_modified=1;
201 }
202 
203 
204 
205 
207 {
208  assert(st);
209  return st->port;
210 }
211 
212 
213 void GWEN_Url_SetPort(GWEN_URL *st, int d)
214 {
215  assert(st);
216  st->port=d;
217  st->_modified=1;
218 }
219 
220 
221 
222 
223 const char *GWEN_Url_GetPath(const GWEN_URL *st)
224 {
225  assert(st);
226  return st->path;
227 }
228 
229 
230 void GWEN_Url_SetPath(GWEN_URL *st, const char *d)
231 {
232  assert(st);
233  if (st->path)
234  free(st->path);
235  if (d && *d)
236  st->path=strdup(d);
237  else
238  st->path=0;
239  st->_modified=1;
240 }
241 
242 
243 
244 
245 const char *GWEN_Url_GetUserName(const GWEN_URL *st)
246 {
247  assert(st);
248  return st->userName;
249 }
250 
251 
252 void GWEN_Url_SetUserName(GWEN_URL *st, const char *d)
253 {
254  assert(st);
255  if (st->userName)
256  free(st->userName);
257  if (d && *d)
258  st->userName=strdup(d);
259  else
260  st->userName=0;
261  st->_modified=1;
262 }
263 
264 
265 
266 
267 const char *GWEN_Url_GetPassword(const GWEN_URL *st)
268 {
269  assert(st);
270  return st->password;
271 }
272 
273 
274 void GWEN_Url_SetPassword(GWEN_URL *st, const char *d)
275 {
276  assert(st);
277  if (st->password)
278  free(st->password);
279  if (d && *d)
280  st->password=strdup(d);
281  else
282  st->password=0;
283  st->_modified=1;
284 }
285 
286 
287 
288 
290 {
291  assert(st);
292  return st->vars;
293 }
294 
295 
297 {
298  assert(st);
299  if (st->vars)
300  GWEN_DB_Group_free(st->vars);
301  if (d)
302  st->vars=GWEN_DB_Group_dup(d);
303  else
304  st->vars=0;
305  st->_modified=1;
306 }
307 
308 
309 
310 
311 const char *GWEN_Url_GetUrl(const GWEN_URL *st)
312 {
313  assert(st);
314  return st->url;
315 }
316 
317 
318 void GWEN_Url_SetUrl(GWEN_URL *st, const char *d)
319 {
320  assert(st);
321  if (st->url)
322  free(st->url);
323  if (d && *d)
324  st->url=strdup(d);
325  else
326  st->url=0;
327  st->_modified=1;
328 }
329 
330 
331 
332 
334 {
335  assert(st);
336  return st->_modified;
337 }
338 
339 
341 {
342  assert(st);
343  st->_modified=i;
344 }
345 
346 
348 {
349  assert(st);
350  st->_usage++;
351 }
353 {
354  GWEN_Url_free(st);
355  return 0;
356 }
357 
358 
360 {
361  if (stl) {
363  GWEN_Url_List2_free(stl);
364  }
365 }
366 
367 
369 {
370  if (stl) {
371  GWEN_URL_LIST *nl;
372  GWEN_URL *e;
373 
374  nl=GWEN_Url_List_new();
375  e=GWEN_Url_List_First(stl);
376  while (e) {
377  GWEN_URL *ne;
378 
379  ne=GWEN_Url_dup(e);
380  assert(ne);
381  GWEN_Url_List_Add(ne, nl);
382  e=GWEN_Url_List_Next(e);
383  } /* while (e) */
384  return nl;
385  }
386  else
387  return 0;
388 }
389 
390 
391 
392 
void GWEN_Url_free(GWEN_URL *st)
Definition: url.c:38
const char * GWEN_Url_GetUrl(const GWEN_URL *st)
Definition: url.c:311
#define GWEN_DB_FLAGS_OVERWRITE_VARS
Definition: db.h:121
struct GWEN_DB_NODE GWEN_DB_NODE
Definition: db.h:228
void GWEN_DB_Group_free(GWEN_DB_NODE *n)
Definition: db.c:408
GWEN_URL * GWEN_Url_List_Next(const GWEN_URL *element)
#define GWEN_FREE_OBJECT(varname)
Definition: memory.h:92
void GWEN_Url_List_Add(GWEN_URL *element, GWEN_URL_LIST *list)
const char * GWEN_Url_GetProtocol(const GWEN_URL *st)
Definition: url.c:162
int GWEN_Url_GetPort(const GWEN_URL *st)
Definition: url.c:206
GWEN_URL * GWEN_Url_List2_ForEach(GWEN_URL_LIST2 *list, GWEN_URL_LIST2_FOREACH func, void *user_data)
int GWEN_Url_IsModified(const GWEN_URL *st)
Definition: url.c:333
void GWEN_Url_SetProtocol(GWEN_URL *st, const char *d)
Definition: url.c:169
void GWEN_Url_SetServer(GWEN_URL *st, const char *d)
Definition: url.c:191
GWEN_URL_LIST * GWEN_Url_List_new()
GWEN_URL * GWEN_Url_List_First(const GWEN_URL_LIST *l)
#define GWEN_NEW_OBJECT(typ, varname)
Definition: memory.h:86
GWEN_URL_LIST * GWEN_Url_List_dup(const GWEN_URL_LIST *stl)
Definition: url.c:368
int GWEN_Url_toDb(const GWEN_URL *st, GWEN_DB_NODE *db)
Definition: url.c:92
struct GWEN_URL GWEN_URL
Definition: url.h:77
void GWEN_Url_List2_freeAll(GWEN_URL_LIST2 *stl)
Definition: url.c:359
void GWEN_Url_SetUserName(GWEN_URL *st, const char *d)
Definition: url.c:252
void GWEN_Url_SetPassword(GWEN_URL *st, const char *d)
Definition: url.c:274
const char * GWEN_DB_GetCharValue(GWEN_DB_NODE *n, const char *path, int idx, const char *defVal)
Definition: db.c:958
GWEN_URL * GWEN_Url_dup(const GWEN_URL *d)
Definition: url.c:65
GWEN_DB_NODE * GWEN_DB_Group_dup(const GWEN_DB_NODE *n)
Definition: db.c:415
GWEN_URL * GWEN_Url_new(void)
Definition: url.c:26
GWEN_DB_NODE * GWEN_DB_GetGroup(GWEN_DB_NODE *n, uint32_t flags, const char *path)
Definition: db.c:1368
void GWEN_Url_List2_free(GWEN_URL_LIST2 *l)
const char * GWEN_Url_GetServer(const GWEN_URL *st)
Definition: url.c:184
GWEN_LIST2_FUNCTIONS(TYPEMAKER2_TYPE, Typemaker2_Type)
int GWEN_Url_ReadDb(GWEN_URL *st, GWEN_DB_NODE *db)
Definition: url.c:123
void GWEN_Url_SetModified(GWEN_URL *st, int i)
Definition: url.c:340
struct GWEN_URL_LIST2 GWEN_URL_LIST2
Definition: listdoc.h:7774
const char * GWEN_Url_GetPassword(const GWEN_URL *st)
Definition: url.c:267
int GWEN_DB_SetCharValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, const char *val)
Definition: db.c:984
void GWEN_Url_SetPath(GWEN_URL *st, const char *d)
Definition: url.c:230
const char * GWEN_Url_GetUserName(const GWEN_URL *st)
Definition: url.c:245
void GWEN_Url_SetPort(GWEN_URL *st, int d)
Definition: url.c:213
GWEN_URL * GWEN_Url_List2__freeAll_cb(GWEN_URL *st, GWEN_UNUSED void *user_data)
Definition: url.c:352
void GWEN_Url_SetUrl(GWEN_URL *st, const char *d)
Definition: url.c:318
#define GWEN_LIST_INIT(t, element)
Definition: list1.h:465
GWEN_URL * GWEN_Url_fromDb(GWEN_DB_NODE *db)
Definition: url.c:148
int GWEN_DB_GetIntValue(GWEN_DB_NODE *n, const char *path, int idx, int defVal)
Definition: db.c:1150
GWEN_DB_NODE * GWEN_Url_GetVars(const GWEN_URL *st)
Definition: url.c:289
void GWEN_Url_SetVars(GWEN_URL *st, GWEN_DB_NODE *d)
Definition: url.c:296
GWEN_DB_NODE * GWEN_DB_Group_new(const char *name)
Definition: db.c:160
int GWEN_DB_SetIntValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, int val)
Definition: db.c:1189
#define GWEN_LIST_FUNCTIONS(t, pr)
Definition: list1.h:366
int GWEN_DB_AddGroupChildren(GWEN_DB_NODE *n, GWEN_DB_NODE *nn)
Definition: db.c:1511
void GWEN_Url_Attach(GWEN_URL *st)
Definition: url.c:347
#define GWEN_PATH_FLAGS_NAMEMUSTEXIST
Definition: path.h:84
#define GWEN_LIST_FINI(t, element)
Definition: list1.h:474
const char * GWEN_Url_GetPath(const GWEN_URL *st)
Definition: url.c:223
#define GWEN_UNUSED
#define GWEN_DB_FLAGS_DEFAULT
Definition: db.h:168