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