gwenhywfar 4.0.3
|
00001 /* This file is auto-generated from "url.xml" by the typemaker 00002 tool of Gwenhywfar. 00003 Do not edit this file -- all changes will be lost! */ 00004 #ifdef HAVE_CONFIG_H 00005 # include "config.h" 00006 #endif 00007 00008 #include "url_p.h" 00009 #include <gwenhywfar/misc.h> 00010 #include <gwenhywfar/db.h> 00011 #include <gwenhywfar/debug.h> 00012 #include <assert.h> 00013 #include <stdlib.h> 00014 #include <strings.h> 00015 00016 #include <gwenhywfar/types.h> 00017 #include <gwenhywfar/urlfns.h> 00018 00019 00020 GWEN_LIST_FUNCTIONS(GWEN_URL, GWEN_Url) 00021 GWEN_LIST2_FUNCTIONS(GWEN_URL, GWEN_Url) 00022 00023 00024 00025 00026 GWEN_URL *GWEN_Url_new() { 00027 GWEN_URL *st; 00028 00029 GWEN_NEW_OBJECT(GWEN_URL, st) 00030 st->_usage=1; 00031 GWEN_LIST_INIT(GWEN_URL, st) 00032 st->vars=GWEN_DB_Group_new("vars"); 00033 return st; 00034 } 00035 00036 00037 void GWEN_Url_free(GWEN_URL *st) { 00038 if (st) { 00039 assert(st->_usage); 00040 if (--(st->_usage)==0) { 00041 if (st->protocol) 00042 free(st->protocol); 00043 if (st->server) 00044 free(st->server); 00045 if (st->path) 00046 free(st->path); 00047 if (st->userName) 00048 free(st->userName); 00049 if (st->password) 00050 free(st->password); 00051 if (st->vars) 00052 GWEN_DB_Group_free(st->vars); 00053 if (st->url) 00054 free(st->url); 00055 GWEN_LIST_FINI(GWEN_URL, st) 00056 GWEN_FREE_OBJECT(st); 00057 } 00058 } 00059 00060 } 00061 00062 00063 GWEN_URL *GWEN_Url_dup(const GWEN_URL *d) { 00064 GWEN_URL *st; 00065 00066 assert(d); 00067 st=GWEN_Url_new(); 00068 if (d->protocol) 00069 st->protocol=strdup(d->protocol); 00070 if (d->server) 00071 st->server=strdup(d->server); 00072 st->port=d->port; 00073 if (d->path) 00074 st->path=strdup(d->path); 00075 if (d->userName) 00076 st->userName=strdup(d->userName); 00077 if (d->password) 00078 st->password=strdup(d->password); 00079 if (d->vars) 00080 st->vars=GWEN_DB_Group_dup(d->vars); 00081 if (d->url) 00082 st->url=strdup(d->url); 00083 return st; 00084 } 00085 00086 00087 int GWEN_Url_toDb(const GWEN_URL *st, GWEN_DB_NODE *db) { 00088 assert(st); 00089 assert(db); 00090 if (st->protocol) 00091 if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "protocol", st->protocol)) 00092 return -1; 00093 if (st->server) 00094 if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "server", st->server)) 00095 return -1; 00096 if (GWEN_DB_SetIntValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "port", st->port)) 00097 return -1; 00098 if (st->path) 00099 if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "path", st->path)) 00100 return -1; 00101 if (st->userName) 00102 if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "userName", st->userName)) 00103 return -1; 00104 if (st->password) 00105 if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "password", st->password)) 00106 return -1; 00107 if (st->vars) 00108 if (GWEN_DB_AddGroupChildren(st->vars, GWEN_DB_GetGroup(db, GWEN_DB_FLAGS_DEFAULT, "vars"))) 00109 return -1; 00110 if (st->url) 00111 if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "url", st->url)) 00112 return -1; 00113 return 0; 00114 } 00115 00116 00117 int GWEN_Url_ReadDb(GWEN_URL *st, GWEN_DB_NODE *db) { 00118 assert(st); 00119 assert(db); 00120 GWEN_Url_SetProtocol(st, GWEN_DB_GetCharValue(db, "protocol", 0, 0)); 00121 GWEN_Url_SetServer(st, GWEN_DB_GetCharValue(db, "server", 0, 0)); 00122 GWEN_Url_SetPort(st, GWEN_DB_GetIntValue(db, "port", 0, 0)); 00123 GWEN_Url_SetPath(st, GWEN_DB_GetCharValue(db, "path", 0, 0)); 00124 GWEN_Url_SetUserName(st, GWEN_DB_GetCharValue(db, "userName", 0, 0)); 00125 GWEN_Url_SetPassword(st, GWEN_DB_GetCharValue(db, "password", 0, 0)); 00126 if (1) { /* for local vars */ 00127 GWEN_DB_NODE *dbT; 00128 00129 dbT=GWEN_DB_GetGroup(db, GWEN_PATH_FLAGS_NAMEMUSTEXIST, "vars"); 00130 if (dbT) { 00131 if (st->vars) 00132 GWEN_DB_Group_free(st->vars); 00133 st->vars=GWEN_DB_Group_dup(dbT); 00134 } 00135 } 00136 GWEN_Url_SetUrl(st, GWEN_DB_GetCharValue(db, "url", 0, 0)); 00137 return 0; 00138 } 00139 00140 00141 GWEN_URL *GWEN_Url_fromDb(GWEN_DB_NODE *db) { 00142 GWEN_URL *st; 00143 00144 assert(db); 00145 st=GWEN_Url_new(); 00146 GWEN_Url_ReadDb(st, db); 00147 st->_modified=0; 00148 return st; 00149 } 00150 00151 00152 00153 00154 const char *GWEN_Url_GetProtocol(const GWEN_URL *st) { 00155 assert(st); 00156 return st->protocol; 00157 } 00158 00159 00160 void GWEN_Url_SetProtocol(GWEN_URL *st, const char *d) { 00161 assert(st); 00162 if (st->protocol) 00163 free(st->protocol); 00164 if (d && *d) 00165 st->protocol=strdup(d); 00166 else 00167 st->protocol=0; 00168 st->_modified=1; 00169 } 00170 00171 00172 00173 00174 const char *GWEN_Url_GetServer(const GWEN_URL *st) { 00175 assert(st); 00176 return st->server; 00177 } 00178 00179 00180 void GWEN_Url_SetServer(GWEN_URL *st, const char *d) { 00181 assert(st); 00182 if (st->server) 00183 free(st->server); 00184 if (d && *d) 00185 st->server=strdup(d); 00186 else 00187 st->server=0; 00188 st->_modified=1; 00189 } 00190 00191 00192 00193 00194 int GWEN_Url_GetPort(const GWEN_URL *st) { 00195 assert(st); 00196 return st->port; 00197 } 00198 00199 00200 void GWEN_Url_SetPort(GWEN_URL *st, int d) { 00201 assert(st); 00202 st->port=d; 00203 st->_modified=1; 00204 } 00205 00206 00207 00208 00209 const char *GWEN_Url_GetPath(const GWEN_URL *st) { 00210 assert(st); 00211 return st->path; 00212 } 00213 00214 00215 void GWEN_Url_SetPath(GWEN_URL *st, const char *d) { 00216 assert(st); 00217 if (st->path) 00218 free(st->path); 00219 if (d && *d) 00220 st->path=strdup(d); 00221 else 00222 st->path=0; 00223 st->_modified=1; 00224 } 00225 00226 00227 00228 00229 const char *GWEN_Url_GetUserName(const GWEN_URL *st) { 00230 assert(st); 00231 return st->userName; 00232 } 00233 00234 00235 void GWEN_Url_SetUserName(GWEN_URL *st, const char *d) { 00236 assert(st); 00237 if (st->userName) 00238 free(st->userName); 00239 if (d && *d) 00240 st->userName=strdup(d); 00241 else 00242 st->userName=0; 00243 st->_modified=1; 00244 } 00245 00246 00247 00248 00249 const char *GWEN_Url_GetPassword(const GWEN_URL *st) { 00250 assert(st); 00251 return st->password; 00252 } 00253 00254 00255 void GWEN_Url_SetPassword(GWEN_URL *st, const char *d) { 00256 assert(st); 00257 if (st->password) 00258 free(st->password); 00259 if (d && *d) 00260 st->password=strdup(d); 00261 else 00262 st->password=0; 00263 st->_modified=1; 00264 } 00265 00266 00267 00268 00269 GWEN_DB_NODE *GWEN_Url_GetVars(const GWEN_URL *st) { 00270 assert(st); 00271 return st->vars; 00272 } 00273 00274 00275 void GWEN_Url_SetVars(GWEN_URL *st, GWEN_DB_NODE *d) { 00276 assert(st); 00277 if (st->vars) 00278 GWEN_DB_Group_free(st->vars); 00279 if (d) 00280 st->vars=GWEN_DB_Group_dup(d); 00281 else 00282 st->vars=0; 00283 st->_modified=1; 00284 } 00285 00286 00287 00288 00289 const char *GWEN_Url_GetUrl(const GWEN_URL *st) { 00290 assert(st); 00291 return st->url; 00292 } 00293 00294 00295 void GWEN_Url_SetUrl(GWEN_URL *st, const char *d) { 00296 assert(st); 00297 if (st->url) 00298 free(st->url); 00299 if (d && *d) 00300 st->url=strdup(d); 00301 else 00302 st->url=0; 00303 st->_modified=1; 00304 } 00305 00306 00307 00308 00309 int GWEN_Url_IsModified(const GWEN_URL *st) { 00310 assert(st); 00311 return st->_modified; 00312 } 00313 00314 00315 void GWEN_Url_SetModified(GWEN_URL *st, int i) { 00316 assert(st); 00317 st->_modified=i; 00318 } 00319 00320 00321 void GWEN_Url_Attach(GWEN_URL *st) { 00322 assert(st); 00323 st->_usage++; 00324 } 00325 GWEN_URL *GWEN_Url_List2__freeAll_cb(GWEN_URL *st, GWEN_UNUSED void *user_data) { 00326 GWEN_Url_free(st); 00327 return 0; 00328 } 00329 00330 00331 void GWEN_Url_List2_freeAll(GWEN_URL_LIST2 *stl) { 00332 if (stl) { 00333 GWEN_Url_List2_ForEach(stl, GWEN_Url_List2__freeAll_cb, 0); 00334 GWEN_Url_List2_free(stl); 00335 } 00336 } 00337 00338 00339 GWEN_URL_LIST *GWEN_Url_List_dup(const GWEN_URL_LIST *stl) { 00340 if (stl) { 00341 GWEN_URL_LIST *nl; 00342 GWEN_URL *e; 00343 00344 nl=GWEN_Url_List_new(); 00345 e=GWEN_Url_List_First(stl); 00346 while(e) { 00347 GWEN_URL *ne; 00348 00349 ne=GWEN_Url_dup(e); 00350 assert(ne); 00351 GWEN_Url_List_Add(ne, nl); 00352 e=GWEN_Url_List_Next(e); 00353 } /* while (e) */ 00354 return nl; 00355 } 00356 else 00357 return 0; 00358 } 00359 00360 00361 00362