gwenhywfar  4.6.0beta
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  st->vars=GWEN_DB_Group_dup(d->vars);
81  if (d->url)
82  st->url=strdup(d->url);
83  return st;
84 }
85 
86 
87 int GWEN_Url_toDb(const GWEN_URL *st, GWEN_DB_NODE *db) {
88  assert(st);
89  assert(db);
90  if (st->protocol)
91  if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "protocol", st->protocol))
92  return -1;
93  if (st->server)
94  if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "server", st->server))
95  return -1;
96  if (GWEN_DB_SetIntValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "port", st->port))
97  return -1;
98  if (st->path)
99  if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "path", st->path))
100  return -1;
101  if (st->userName)
102  if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "userName", st->userName))
103  return -1;
104  if (st->password)
105  if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "password", st->password))
106  return -1;
107  if (st->vars)
109  return -1;
110  if (st->url)
111  if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "url", st->url))
112  return -1;
113  return 0;
114 }
115 
116 
118  assert(st);
119  assert(db);
120  GWEN_Url_SetProtocol(st, GWEN_DB_GetCharValue(db, "protocol", 0, 0));
121  GWEN_Url_SetServer(st, GWEN_DB_GetCharValue(db, "server", 0, 0));
122  GWEN_Url_SetPort(st, GWEN_DB_GetIntValue(db, "port", 0, 0));
123  GWEN_Url_SetPath(st, GWEN_DB_GetCharValue(db, "path", 0, 0));
124  GWEN_Url_SetUserName(st, GWEN_DB_GetCharValue(db, "userName", 0, 0));
125  GWEN_Url_SetPassword(st, GWEN_DB_GetCharValue(db, "password", 0, 0));
126  if (1) { /* for local vars */
127  GWEN_DB_NODE *dbT;
128 
130  if (dbT) {
131  if (st->vars)
132  GWEN_DB_Group_free(st->vars);
133  st->vars=GWEN_DB_Group_dup(dbT);
134 }
135  }
136  GWEN_Url_SetUrl(st, GWEN_DB_GetCharValue(db, "url", 0, 0));
137  return 0;
138 }
139 
140 
142  GWEN_URL *st;
143 
144  assert(db);
145  st=GWEN_Url_new();
146  GWEN_Url_ReadDb(st, db);
147  st->_modified=0;
148  return st;
149 }
150 
151 
152 
153 
154 const char *GWEN_Url_GetProtocol(const GWEN_URL *st) {
155  assert(st);
156  return st->protocol;
157 }
158 
159 
160 void GWEN_Url_SetProtocol(GWEN_URL *st, const char *d) {
161  assert(st);
162  if (st->protocol)
163  free(st->protocol);
164  if (d && *d)
165  st->protocol=strdup(d);
166  else
167  st->protocol=0;
168  st->_modified=1;
169 }
170 
171 
172 
173 
174 const char *GWEN_Url_GetServer(const GWEN_URL *st) {
175  assert(st);
176  return st->server;
177 }
178 
179 
180 void GWEN_Url_SetServer(GWEN_URL *st, const char *d) {
181  assert(st);
182  if (st->server)
183  free(st->server);
184  if (d && *d)
185  st->server=strdup(d);
186  else
187  st->server=0;
188  st->_modified=1;
189 }
190 
191 
192 
193 
194 int GWEN_Url_GetPort(const GWEN_URL *st) {
195  assert(st);
196  return st->port;
197 }
198 
199 
200 void GWEN_Url_SetPort(GWEN_URL *st, int d) {
201  assert(st);
202  st->port=d;
203  st->_modified=1;
204 }
205 
206 
207 
208 
209 const char *GWEN_Url_GetPath(const GWEN_URL *st) {
210  assert(st);
211  return st->path;
212 }
213 
214 
215 void GWEN_Url_SetPath(GWEN_URL *st, const char *d) {
216  assert(st);
217  if (st->path)
218  free(st->path);
219  if (d && *d)
220  st->path=strdup(d);
221  else
222  st->path=0;
223  st->_modified=1;
224 }
225 
226 
227 
228 
229 const char *GWEN_Url_GetUserName(const GWEN_URL *st) {
230  assert(st);
231  return st->userName;
232 }
233 
234 
235 void GWEN_Url_SetUserName(GWEN_URL *st, const char *d) {
236  assert(st);
237  if (st->userName)
238  free(st->userName);
239  if (d && *d)
240  st->userName=strdup(d);
241  else
242  st->userName=0;
243  st->_modified=1;
244 }
245 
246 
247 
248 
249 const char *GWEN_Url_GetPassword(const GWEN_URL *st) {
250  assert(st);
251  return st->password;
252 }
253 
254 
255 void GWEN_Url_SetPassword(GWEN_URL *st, const char *d) {
256  assert(st);
257  if (st->password)
258  free(st->password);
259  if (d && *d)
260  st->password=strdup(d);
261  else
262  st->password=0;
263  st->_modified=1;
264 }
265 
266 
267 
268 
270  assert(st);
271  return st->vars;
272 }
273 
274 
276  assert(st);
277  if (st->vars)
278  GWEN_DB_Group_free(st->vars);
279  if (d)
280  st->vars=GWEN_DB_Group_dup(d);
281  else
282  st->vars=0;
283  st->_modified=1;
284 }
285 
286 
287 
288 
289 const char *GWEN_Url_GetUrl(const GWEN_URL *st) {
290  assert(st);
291  return st->url;
292 }
293 
294 
295 void GWEN_Url_SetUrl(GWEN_URL *st, const char *d) {
296  assert(st);
297  if (st->url)
298  free(st->url);
299  if (d && *d)
300  st->url=strdup(d);
301  else
302  st->url=0;
303  st->_modified=1;
304 }
305 
306 
307 
308 
310  assert(st);
311  return st->_modified;
312 }
313 
314 
315 void GWEN_Url_SetModified(GWEN_URL *st, int i) {
316  assert(st);
317  st->_modified=i;
318 }
319 
320 
322  assert(st);
323  st->_usage++;
324 }
326  GWEN_Url_free(st);
327 return 0;
328 }
329 
330 
331 void GWEN_Url_List2_freeAll(GWEN_URL_LIST2 *stl) {
332  if (stl) {
333  GWEN_Url_List2_ForEach(stl, GWEN_Url_List2__freeAll_cb, 0);
334  GWEN_Url_List2_free(stl);
335  }
336 }
337 
338 
339 GWEN_URL_LIST *GWEN_Url_List_dup(const GWEN_URL_LIST *stl) {
340  if (stl) {
341  GWEN_URL_LIST *nl;
342  GWEN_URL *e;
343 
344  nl=GWEN_Url_List_new();
345  e=GWEN_Url_List_First(stl);
346  while(e) {
347  GWEN_URL *ne;
348 
349  ne=GWEN_Url_dup(e);
350  assert(ne);
351  GWEN_Url_List_Add(ne, nl);
352  e=GWEN_Url_List_Next(e);
353  } /* while (e) */
354  return nl;
355  }
356  else
357  return 0;
358 }
359 
360 
361 
362