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