static void car_printf(const struct vehicle *v) { struct car *c = (struct car *)v; printf("Car {"); if (ATTR_IS_SET(v->flags, VEHICLE_PLATE)) printf("\n\tplate = \"%s\"", v->plate); if (ATTR_IS_SET(c->flags, CAR_TYPE)) printf("\n\ttype = \"%s\"", c->type); printf("\n}\n"); }
static void STORE_ATTR_INFO_attr_free(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code) { if (ATTR_IS_SET(attrs, code)) { switch (code) { case STORE_ATTR_FRIENDLYNAME: case STORE_ATTR_EMAIL: case STORE_ATTR_FILENAME: STORE_ATTR_INFO_modify_cstr(attrs, code, NULL, 0); break; case STORE_ATTR_KEYID: case STORE_ATTR_ISSUERKEYID: case STORE_ATTR_SUBJECTKEYID: case STORE_ATTR_ISSUERSERIALHASH: case STORE_ATTR_CERTHASH: STORE_ATTR_INFO_modify_sha1str(attrs, code, NULL, 0); break; case STORE_ATTR_ISSUER: case STORE_ATTR_SUBJECT: STORE_ATTR_INFO_modify_dn(attrs, code, NULL); break; case STORE_ATTR_SERIAL: STORE_ATTR_INFO_modify_number(attrs, code, NULL); break; default: break; } } }
void car_set_type(struct car *c, const char *type) { if (ATTR_IS_SET(c->flags, CAR_TYPE)) free(c->type); c->type = strdup(type); ATTR_SET(c->flags, CAR_TYPE); }
BIGNUM * STORE_ATTR_INFO_get0_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code) { if (!attrs) { STOREerr(STORE_F_STORE_ATTR_INFO_GET0_NUMBER, ERR_R_PASSED_NULL_PARAMETER); return NULL; } if (ATTR_IS_SET(attrs, code)) return attrs->values[code].number; STOREerr(STORE_F_STORE_ATTR_INFO_GET0_NUMBER, STORE_R_NO_VALUE); return NULL; }
X509_NAME * STORE_ATTR_INFO_get0_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code) { if (!attrs) { STOREerr(STORE_F_STORE_ATTR_INFO_GET0_DN, ERR_R_PASSED_NULL_PARAMETER); return NULL; } if (ATTR_IS_SET(attrs, code)) return attrs->values[code].dn; STOREerr(STORE_F_STORE_ATTR_INFO_GET0_DN, STORE_R_NO_VALUE); return NULL; }
unsigned char * STORE_ATTR_INFO_get0_sha1str(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code) { if (!attrs) { STOREerr(STORE_F_STORE_ATTR_INFO_GET0_SHA1STR, ERR_R_PASSED_NULL_PARAMETER); return NULL; } if (ATTR_IS_SET(attrs, code)) return attrs->values[code].sha1string; STOREerr(STORE_F_STORE_ATTR_INFO_GET0_SHA1STR, STORE_R_NO_VALUE); return NULL; }
int STORE_ATTR_INFO_modify_sha1str(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, unsigned char *sha1str, size_t sha1str_size) { if (!attrs) { STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_SHA1STR, ERR_R_PASSED_NULL_PARAMETER); return 0; } if (ATTR_IS_SET(attrs, code)) { free(attrs->values[code].sha1string); attrs->values[code].sha1string = NULL; CLEAR_ATTRBIT(attrs, code); } return STORE_ATTR_INFO_set_sha1str(attrs, code, sha1str, sha1str_size); }
int STORE_ATTR_INFO_modify_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, BIGNUM *number) { if (!attrs) { STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_NUMBER, ERR_R_PASSED_NULL_PARAMETER); return 0; } if (ATTR_IS_SET(attrs, code)) { free(attrs->values[code].number); attrs->values[code].number = NULL; CLEAR_ATTRBIT(attrs, code); } return STORE_ATTR_INFO_set_number(attrs, code, number); }
int STORE_ATTR_INFO_modify_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, X509_NAME *dn) { if (!attrs) { STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_DN, ERR_R_PASSED_NULL_PARAMETER); return 0; } if (ATTR_IS_SET(attrs, code)) { free(attrs->values[code].dn); attrs->values[code].dn = NULL; CLEAR_ATTRBIT(attrs, code); } return STORE_ATTR_INFO_set_dn(attrs, code, dn); }
int STORE_ATTR_INFO_in_ex(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b) { STORE_ATTR_TYPES i; if (a == b) return 1; if (!STORE_ATTR_INFO_in(a, b)) return 0; for (i = 1; i < STORE_ATTR_TYPE_NUM; i++) if (ATTR_IS_SET(a, i)) { switch (i) { case STORE_ATTR_FRIENDLYNAME: case STORE_ATTR_EMAIL: case STORE_ATTR_FILENAME: if (strcmp(a->values[i].cstring, b->values[i].cstring)) return 0; break; case STORE_ATTR_KEYID: case STORE_ATTR_ISSUERKEYID: case STORE_ATTR_SUBJECTKEYID: case STORE_ATTR_ISSUERSERIALHASH: case STORE_ATTR_CERTHASH: if (memcmp(a->values[i].sha1string, b->values[i].sha1string, a->value_sizes[i])) return 0; break; case STORE_ATTR_ISSUER: case STORE_ATTR_SUBJECT: if (X509_NAME_cmp(a->values[i].dn, b->values[i].dn)) return 0; break; case STORE_ATTR_SERIAL: if (BN_cmp(a->values[i].number, b->values[i].number)) return 0; break; default: break; } } return 1; }
int STORE_ATTR_INFO_modify_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, char *cstr, size_t cstr_size) { if (!attrs) { STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_CSTR, ERR_R_PASSED_NULL_PARAMETER); return 0; } if (ATTR_IS_SET(attrs,code)) { OPENSSL_free(attrs->values[code].cstring); attrs->values[code].cstring = NULL; CLEAR_ATTRBIT(attrs, code); } return STORE_ATTR_INFO_set_cstr(attrs, code, cstr, cstr_size); }
int STORE_ATTR_INFO_set_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, char *cstr, size_t cstr_size) { if (!attrs) { STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR, ERR_R_PASSED_NULL_PARAMETER); return 0; } if (!ATTR_IS_SET(attrs, code)) { if ((attrs->values[code].cstring = BUF_strndup(cstr, cstr_size))) return 1; STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR, ERR_R_MALLOC_FAILURE); return 0; } STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR, STORE_R_ALREADY_HAS_A_VALUE); return 0; }
int STORE_ATTR_INFO_set_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, X509_NAME *dn) { if (!attrs) { STOREerr(STORE_F_STORE_ATTR_INFO_SET_DN, ERR_R_PASSED_NULL_PARAMETER); return 0; } if (!ATTR_IS_SET(attrs, code)) { if ((attrs->values[code].dn = X509_NAME_dup(dn))) return 1; STOREerr(STORE_F_STORE_ATTR_INFO_SET_DN, ERR_R_MALLOC_FAILURE); return 0; } STOREerr(STORE_F_STORE_ATTR_INFO_SET_DN, STORE_R_ALREADY_HAS_A_VALUE); return 0; }
int STORE_ATTR_INFO_set_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, BIGNUM *number) { if (!attrs) { STOREerr(STORE_F_STORE_ATTR_INFO_SET_NUMBER, ERR_R_PASSED_NULL_PARAMETER); return 0; } if (!ATTR_IS_SET(attrs, code)) { if ((attrs->values[code].number = BN_dup(number))) return 1; STOREerr(STORE_F_STORE_ATTR_INFO_SET_NUMBER, ERR_R_MALLOC_FAILURE); return 0; } STOREerr(STORE_F_STORE_ATTR_INFO_SET_NUMBER, STORE_R_ALREADY_HAS_A_VALUE); return 0; }
int STORE_ATTR_INFO_set_sha1str(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, unsigned char *sha1str, size_t sha1str_size) { if (!attrs) { STOREerr(STORE_F_STORE_ATTR_INFO_SET_SHA1STR, ERR_R_PASSED_NULL_PARAMETER); return 0; } if (!ATTR_IS_SET(attrs, code)) { if ((attrs->values[code].sha1string = (unsigned char *)BUF_memdup(sha1str, sha1str_size))) return 1; STOREerr(STORE_F_STORE_ATTR_INFO_SET_SHA1STR, ERR_R_MALLOC_FAILURE); return 0; } STOREerr(STORE_F_STORE_ATTR_INFO_SET_SHA1STR, STORE_R_ALREADY_HAS_A_VALUE); return 0; }
const char *car_get_type(const struct car *c) { if (ATTR_IS_SET(c->flags, CAR_TYPE)) return c->type; return NULL; }
void car_free(struct car *c) { if (ATTR_IS_SET(c->flags, CAR_TYPE)) free(c->type); vehicle_free(&c->super); }