00001
00002
00003
00004 #ifdef HAVE_CONFIG_H
00005 # include "config.h"
00006 #endif
00007
00008 #include "ssl_cert_descr_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/gwentime.h>
00017 #include <gwenhywfar/ssl_cert_flags.h>
00018
00019
00020 GWEN_LIST_FUNCTIONS(GWEN_SSLCERTDESCR, GWEN_SslCertDescr)
00021 GWEN_LIST2_FUNCTIONS(GWEN_SSLCERTDESCR, GWEN_SslCertDescr)
00022
00023
00024
00025
00026 GWEN_SSLCERTDESCR *GWEN_SslCertDescr_new() {
00027 GWEN_SSLCERTDESCR *st;
00028
00029 GWEN_NEW_OBJECT(GWEN_SSLCERTDESCR, st)
00030 st->_usage=1;
00031 GWEN_LIST_INIT(GWEN_SSLCERTDESCR, st)
00032 return st;
00033 }
00034
00035
00036 void GWEN_SslCertDescr_free(GWEN_SSLCERTDESCR *st) {
00037 if (st) {
00038 assert(st->_usage);
00039 if (--(st->_usage)==0) {
00040 if (st->countryName)
00041 free(st->countryName);
00042 if (st->commonName)
00043 free(st->commonName);
00044 if (st->organizationName)
00045 free(st->organizationName);
00046 if (st->organizationalUnitName)
00047 free(st->organizationalUnitName);
00048 if (st->localityName)
00049 free(st->localityName);
00050 if (st->stateOrProvinceName)
00051 free(st->stateOrProvinceName);
00052 if (st->notBefore)
00053 GWEN_Time_free(st->notBefore);
00054 if (st->notAfter)
00055 GWEN_Time_free(st->notAfter);
00056 if (st->ipAddress)
00057 free(st->ipAddress);
00058 if (st->fingerPrint)
00059 free(st->fingerPrint);
00060 if (st->statusText)
00061 free(st->statusText);
00062 GWEN_LIST_FINI(GWEN_SSLCERTDESCR, st)
00063 GWEN_FREE_OBJECT(st);
00064 }
00065 }
00066
00067 }
00068
00069
00070 GWEN_SSLCERTDESCR *GWEN_SslCertDescr_dup(const GWEN_SSLCERTDESCR *d) {
00071 GWEN_SSLCERTDESCR *st;
00072
00073 assert(d);
00074 st=GWEN_SslCertDescr_new();
00075 if (d->countryName)
00076 st->countryName=strdup(d->countryName);
00077 if (d->commonName)
00078 st->commonName=strdup(d->commonName);
00079 if (d->organizationName)
00080 st->organizationName=strdup(d->organizationName);
00081 if (d->organizationalUnitName)
00082 st->organizationalUnitName=strdup(d->organizationalUnitName);
00083 if (d->localityName)
00084 st->localityName=strdup(d->localityName);
00085 if (d->stateOrProvinceName)
00086 st->stateOrProvinceName=strdup(d->stateOrProvinceName);
00087 if (d->notBefore)
00088 st->notBefore=GWEN_Time_dup(d->notBefore);
00089 if (d->notAfter)
00090 st->notAfter=GWEN_Time_dup(d->notAfter);
00091 if (d->ipAddress)
00092 st->ipAddress=strdup(d->ipAddress);
00093 if (d->fingerPrint)
00094 st->fingerPrint=strdup(d->fingerPrint);
00095 if (d->statusText)
00096 st->statusText=strdup(d->statusText);
00097 st->isError=d->isError;
00098 st->statusFlags=d->statusFlags;
00099 return st;
00100 }
00101
00102
00103 int GWEN_SslCertDescr_toDb(const GWEN_SSLCERTDESCR *st, GWEN_DB_NODE *db) {
00104 assert(st);
00105 assert(db);
00106 if (st->countryName)
00107 if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "countryName", st->countryName))
00108 return -1;
00109 if (st->commonName)
00110 if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "commonName", st->commonName))
00111 return -1;
00112 if (st->organizationName)
00113 if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "organizationName", st->organizationName))
00114 return -1;
00115 if (st->organizationalUnitName)
00116 if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "organizationalUnitName", st->organizationalUnitName))
00117 return -1;
00118 if (st->localityName)
00119 if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "localityName", st->localityName))
00120 return -1;
00121 if (st->stateOrProvinceName)
00122 if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "stateOrProvinceName", st->stateOrProvinceName))
00123 return -1;
00124 if (st->notBefore)
00125 if (GWEN_Time_toDb(st->notBefore, GWEN_DB_GetGroup(db, GWEN_DB_FLAGS_DEFAULT, "notBefore")))
00126 return -1;
00127 if (st->notAfter)
00128 if (GWEN_Time_toDb(st->notAfter, GWEN_DB_GetGroup(db, GWEN_DB_FLAGS_DEFAULT, "notAfter")))
00129 return -1;
00130 if (st->ipAddress)
00131 if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "ipAddress", st->ipAddress))
00132 return -1;
00133 if (st->fingerPrint)
00134 if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "fingerPrint", st->fingerPrint))
00135 return -1;
00136 if (st->statusText)
00137 if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "statusText", st->statusText))
00138 return -1;
00139 if (GWEN_DB_SetIntValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "isError", st->isError))
00140 return -1;
00141 if (GWEN_DB_SetIntValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "statusFlags", st->statusFlags))
00142 return -1;
00143 return 0;
00144 }
00145
00146
00147 int GWEN_SslCertDescr_ReadDb(GWEN_SSLCERTDESCR *st, GWEN_DB_NODE *db) {
00148 assert(st);
00149 assert(db);
00150 GWEN_SslCertDescr_SetCountryName(st, GWEN_DB_GetCharValue(db, "countryName", 0, 0));
00151 GWEN_SslCertDescr_SetCommonName(st, GWEN_DB_GetCharValue(db, "commonName", 0, 0));
00152 GWEN_SslCertDescr_SetOrganizationName(st, GWEN_DB_GetCharValue(db, "organizationName", 0, 0));
00153 GWEN_SslCertDescr_SetOrganizationalUnitName(st, GWEN_DB_GetCharValue(db, "organizationalUnitName", 0, 0));
00154 GWEN_SslCertDescr_SetLocalityName(st, GWEN_DB_GetCharValue(db, "localityName", 0, 0));
00155 GWEN_SslCertDescr_SetStateOrProvinceName(st, GWEN_DB_GetCharValue(db, "stateOrProvinceName", 0, 0));
00156 if (1) {
00157 GWEN_DB_NODE *dbT;
00158
00159 dbT=GWEN_DB_GetGroup(db, GWEN_PATH_FLAGS_NAMEMUSTEXIST, "notBefore");
00160 if (dbT) {
00161 if (st->notBefore)
00162 GWEN_Time_free(st->notBefore);
00163 st->notBefore=GWEN_Time_fromDb(dbT);
00164 }
00165 }
00166 if (1) {
00167 GWEN_DB_NODE *dbT;
00168
00169 dbT=GWEN_DB_GetGroup(db, GWEN_PATH_FLAGS_NAMEMUSTEXIST, "notAfter");
00170 if (dbT) {
00171 if (st->notAfter)
00172 GWEN_Time_free(st->notAfter);
00173 st->notAfter=GWEN_Time_fromDb(dbT);
00174 }
00175 }
00176 GWEN_SslCertDescr_SetIpAddress(st, GWEN_DB_GetCharValue(db, "ipAddress", 0, 0));
00177 GWEN_SslCertDescr_SetFingerPrint(st, GWEN_DB_GetCharValue(db, "fingerPrint", 0, 0));
00178 GWEN_SslCertDescr_SetStatusText(st, GWEN_DB_GetCharValue(db, "statusText", 0, 0));
00179 GWEN_SslCertDescr_SetIsError(st, GWEN_DB_GetIntValue(db, "isError", 0, 0));
00180 GWEN_SslCertDescr_SetStatusFlags(st, GWEN_DB_GetIntValue(db, "statusFlags", 0, 0));
00181 return 0;
00182 }
00183
00184
00185 GWEN_SSLCERTDESCR *GWEN_SslCertDescr_fromDb(GWEN_DB_NODE *db) {
00186 GWEN_SSLCERTDESCR *st;
00187
00188 assert(db);
00189 st=GWEN_SslCertDescr_new();
00190 GWEN_SslCertDescr_ReadDb(st, db);
00191 st->_modified=0;
00192 return st;
00193 }
00194
00195
00196
00197
00198 const char *GWEN_SslCertDescr_GetCountryName(const GWEN_SSLCERTDESCR *st) {
00199 assert(st);
00200 return st->countryName;
00201 }
00202
00203
00204 void GWEN_SslCertDescr_SetCountryName(GWEN_SSLCERTDESCR *st, const char *d) {
00205 assert(st);
00206 if (st->countryName)
00207 free(st->countryName);
00208 if (d && *d)
00209 st->countryName=strdup(d);
00210 else
00211 st->countryName=0;
00212 st->_modified=1;
00213 }
00214
00215
00216
00217
00218 const char *GWEN_SslCertDescr_GetCommonName(const GWEN_SSLCERTDESCR *st) {
00219 assert(st);
00220 return st->commonName;
00221 }
00222
00223
00224 void GWEN_SslCertDescr_SetCommonName(GWEN_SSLCERTDESCR *st, const char *d) {
00225 assert(st);
00226 if (st->commonName)
00227 free(st->commonName);
00228 if (d && *d)
00229 st->commonName=strdup(d);
00230 else
00231 st->commonName=0;
00232 st->_modified=1;
00233 }
00234
00235
00236
00237
00238 const char *GWEN_SslCertDescr_GetOrganizationName(const GWEN_SSLCERTDESCR *st) {
00239 assert(st);
00240 return st->organizationName;
00241 }
00242
00243
00244 void GWEN_SslCertDescr_SetOrganizationName(GWEN_SSLCERTDESCR *st, const char *d) {
00245 assert(st);
00246 if (st->organizationName)
00247 free(st->organizationName);
00248 if (d && *d)
00249 st->organizationName=strdup(d);
00250 else
00251 st->organizationName=0;
00252 st->_modified=1;
00253 }
00254
00255
00256
00257
00258 const char *GWEN_SslCertDescr_GetOrganizationalUnitName(const GWEN_SSLCERTDESCR *st) {
00259 assert(st);
00260 return st->organizationalUnitName;
00261 }
00262
00263
00264 void GWEN_SslCertDescr_SetOrganizationalUnitName(GWEN_SSLCERTDESCR *st, const char *d) {
00265 assert(st);
00266 if (st->organizationalUnitName)
00267 free(st->organizationalUnitName);
00268 if (d && *d)
00269 st->organizationalUnitName=strdup(d);
00270 else
00271 st->organizationalUnitName=0;
00272 st->_modified=1;
00273 }
00274
00275
00276
00277
00278 const char *GWEN_SslCertDescr_GetLocalityName(const GWEN_SSLCERTDESCR *st) {
00279 assert(st);
00280 return st->localityName;
00281 }
00282
00283
00284 void GWEN_SslCertDescr_SetLocalityName(GWEN_SSLCERTDESCR *st, const char *d) {
00285 assert(st);
00286 if (st->localityName)
00287 free(st->localityName);
00288 if (d && *d)
00289 st->localityName=strdup(d);
00290 else
00291 st->localityName=0;
00292 st->_modified=1;
00293 }
00294
00295
00296
00297
00298 const char *GWEN_SslCertDescr_GetStateOrProvinceName(const GWEN_SSLCERTDESCR *st) {
00299 assert(st);
00300 return st->stateOrProvinceName;
00301 }
00302
00303
00304 void GWEN_SslCertDescr_SetStateOrProvinceName(GWEN_SSLCERTDESCR *st, const char *d) {
00305 assert(st);
00306 if (st->stateOrProvinceName)
00307 free(st->stateOrProvinceName);
00308 if (d && *d)
00309 st->stateOrProvinceName=strdup(d);
00310 else
00311 st->stateOrProvinceName=0;
00312 st->_modified=1;
00313 }
00314
00315
00316
00317
00318 const GWEN_TIME *GWEN_SslCertDescr_GetNotBefore(const GWEN_SSLCERTDESCR *st) {
00319 assert(st);
00320 return st->notBefore;
00321 }
00322
00323
00324 void GWEN_SslCertDescr_SetNotBefore(GWEN_SSLCERTDESCR *st, const GWEN_TIME *d) {
00325 assert(st);
00326 if (st->notBefore)
00327 GWEN_Time_free(st->notBefore);
00328 if (d)
00329 st->notBefore=GWEN_Time_dup(d);
00330 else
00331 st->notBefore=0;
00332 st->_modified=1;
00333 }
00334
00335
00336
00337
00338 const GWEN_TIME *GWEN_SslCertDescr_GetNotAfter(const GWEN_SSLCERTDESCR *st) {
00339 assert(st);
00340 return st->notAfter;
00341 }
00342
00343
00344 void GWEN_SslCertDescr_SetNotAfter(GWEN_SSLCERTDESCR *st, const GWEN_TIME *d) {
00345 assert(st);
00346 if (st->notAfter)
00347 GWEN_Time_free(st->notAfter);
00348 if (d)
00349 st->notAfter=GWEN_Time_dup(d);
00350 else
00351 st->notAfter=0;
00352 st->_modified=1;
00353 }
00354
00355
00356
00357
00358 const char *GWEN_SslCertDescr_GetIpAddress(const GWEN_SSLCERTDESCR *st) {
00359 assert(st);
00360 return st->ipAddress;
00361 }
00362
00363
00364 void GWEN_SslCertDescr_SetIpAddress(GWEN_SSLCERTDESCR *st, const char *d) {
00365 assert(st);
00366 if (st->ipAddress)
00367 free(st->ipAddress);
00368 if (d && *d)
00369 st->ipAddress=strdup(d);
00370 else
00371 st->ipAddress=0;
00372 st->_modified=1;
00373 }
00374
00375
00376
00377
00378 const char *GWEN_SslCertDescr_GetFingerPrint(const GWEN_SSLCERTDESCR *st) {
00379 assert(st);
00380 return st->fingerPrint;
00381 }
00382
00383
00384 void GWEN_SslCertDescr_SetFingerPrint(GWEN_SSLCERTDESCR *st, const char *d) {
00385 assert(st);
00386 if (st->fingerPrint)
00387 free(st->fingerPrint);
00388 if (d && *d)
00389 st->fingerPrint=strdup(d);
00390 else
00391 st->fingerPrint=0;
00392 st->_modified=1;
00393 }
00394
00395
00396
00397
00398 const char *GWEN_SslCertDescr_GetStatusText(const GWEN_SSLCERTDESCR *st) {
00399 assert(st);
00400 return st->statusText;
00401 }
00402
00403
00404 void GWEN_SslCertDescr_SetStatusText(GWEN_SSLCERTDESCR *st, const char *d) {
00405 assert(st);
00406 if (st->statusText)
00407 free(st->statusText);
00408 if (d && *d)
00409 st->statusText=strdup(d);
00410 else
00411 st->statusText=0;
00412 st->_modified=1;
00413 }
00414
00415
00416
00417
00418 int GWEN_SslCertDescr_GetIsError(const GWEN_SSLCERTDESCR *st) {
00419 assert(st);
00420 return st->isError;
00421 }
00422
00423
00424 void GWEN_SslCertDescr_SetIsError(GWEN_SSLCERTDESCR *st, int d) {
00425 assert(st);
00426 st->isError=d;
00427 st->_modified=1;
00428 }
00429
00430
00431
00432
00433 uint32_t GWEN_SslCertDescr_GetStatusFlags(const GWEN_SSLCERTDESCR *st) {
00434 assert(st);
00435 return st->statusFlags;
00436 }
00437
00438
00439 void GWEN_SslCertDescr_SetStatusFlags(GWEN_SSLCERTDESCR *st, uint32_t d) {
00440 assert(st);
00441 st->statusFlags=d;
00442 st->_modified=1;
00443 }
00444
00445
00446
00447
00448 int GWEN_SslCertDescr_IsModified(const GWEN_SSLCERTDESCR *st) {
00449 assert(st);
00450 return st->_modified;
00451 }
00452
00453
00454 void GWEN_SslCertDescr_SetModified(GWEN_SSLCERTDESCR *st, int i) {
00455 assert(st);
00456 st->_modified=i;
00457 }
00458
00459
00460 void GWEN_SslCertDescr_Attach(GWEN_SSLCERTDESCR *st) {
00461 assert(st);
00462 st->_usage++;
00463 }
00464 GWEN_SSLCERTDESCR *GWEN_SslCertDescr_List2__freeAll_cb(GWEN_SSLCERTDESCR *st, GWEN_UNUSED void *user_data) {
00465 GWEN_SslCertDescr_free(st);
00466 return 0;
00467 }
00468
00469
00470 void GWEN_SslCertDescr_List2_freeAll(GWEN_SSLCERTDESCR_LIST2 *stl) {
00471 if (stl) {
00472 GWEN_SslCertDescr_List2_ForEach(stl, GWEN_SslCertDescr_List2__freeAll_cb, 0);
00473 GWEN_SslCertDescr_List2_free(stl);
00474 }
00475 }
00476
00477
00478 GWEN_SSLCERTDESCR_LIST *GWEN_SslCertDescr_List_dup(const GWEN_SSLCERTDESCR_LIST *stl) {
00479 if (stl) {
00480 GWEN_SSLCERTDESCR_LIST *nl;
00481 GWEN_SSLCERTDESCR *e;
00482
00483 nl=GWEN_SslCertDescr_List_new();
00484 e=GWEN_SslCertDescr_List_First(stl);
00485 while(e) {
00486 GWEN_SSLCERTDESCR *ne;
00487
00488 ne=GWEN_SslCertDescr_dup(e);
00489 assert(ne);
00490 GWEN_SslCertDescr_List_Add(ne, nl);
00491 e=GWEN_SslCertDescr_List_Next(e);
00492 }
00493 return nl;
00494 }
00495 else
00496 return 0;
00497 }
00498
00499
00500
00501