Skip to content

Commit

Permalink
libmycms: mycms-list-str: initial add
Browse files Browse the repository at this point in the history
  • Loading branch information
alonbl committed May 20, 2023
1 parent 82e2565 commit 39e161d
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 17 deletions.
1 change: 1 addition & 0 deletions include/mycms/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mycmsinclude_HEADERS = \
mycms-error.h \
mycms-io.h \
mycms-list.h \
mycms-list-str.h \
mycms-static.h \
mycms-system-driver-core.h \
mycms-system.h \
Expand Down
22 changes: 22 additions & 0 deletions include/mycms/mycms-list-str.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef __MYCMS_LIST_STR_H
#define __MYCMS_LIST_STR_H

#include "mycms-system.h"
#include "mycms-list.h"

MYCMS_LIST_DECLARE(str, char *, str)

bool
mycms_list_str_add(
const mycms_system system,
mycms_list_str * const head,
const char * const str
);

bool
mycms_list_str_free(
const mycms_system system,
const mycms_list_str head
);

#endif
2 changes: 1 addition & 1 deletion include/mycms/mycms.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "mycms-certificate.h"
#include "mycms-io.h"
#include "mycms-dict.h"
#include "mycms-list-str.h"
#include "mycms-context.h"

struct mycms_signer_s {
Expand All @@ -14,7 +15,6 @@ struct mycms_signer_s {
char *digest;
};

MYCMS_LIST_DECLARE(str, char *, str)
MYCMS_LIST_DECLARE(signer, struct mycms_signer_s, signer)

struct __mycms_s;
Expand Down
2 changes: 2 additions & 0 deletions src/libmycms/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ MYCMS_COMMON_EXPORTS = \
mycms-dict.exports \
mycms-error.exports \
mycms-io.exports \
mycms-list-str.exports \
mycms-static.exports \
mycms-system.exports \
mycms.exports \
Expand Down Expand Up @@ -57,6 +58,7 @@ libmycms_internal_la_SOURCES = \
mycms-internal.h \
mycms-io-private.h \
mycms-io.c \
mycms-list-str.c \
mycms-openssl.c \
mycms-openssl.h \
mycms-static.c \
Expand Down
52 changes: 52 additions & 0 deletions src/libmycms/mycms-list-str.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <mycms/mycms-list-str.h>

bool
mycms_list_str_add(
const mycms_system system,
mycms_list_str * const head,
const char * const str
) {
bool ret = false;

mycms_list_str t;
if ((t = mycms_system_zalloc(system, "mycms_list_str_add.new", sizeof(*t))) == NULL) {
goto cleanup;
}
if ((t->str = mycms_system_strdup(system, "mycms_list_str_add.dup", str)) == NULL) {
goto cleanup;
}

if (*head == NULL) {
*head = t;
} else {
mycms_list_str i;
for (i = *head;i->next != NULL; i = i->next);
i->next = t;
}

ret = true;

cleanup:

return ret;
}

bool
mycms_list_str_free(
const mycms_system system,
const mycms_list_str head
) {
mycms_list_str h = head;
while (h != NULL) {
mycms_list_str t = h;
h = h->next;
mycms_system_free(system, "mycms_list_str_free.str", t->str);
mycms_system_free(system, "mycms_list_str_free", t);
}

return true;
}
2 changes: 2 additions & 0 deletions src/libmycms/mycms-list-str.exports
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mycms_list_str_add
mycms_list_str_free
21 changes: 5 additions & 16 deletions src/mycms-tool/cmd-sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,8 @@ _cmd_sign(
ret = 0;
goto cleanup;
case OPT_DIGEST:
{
mycms_list_str t;

if ((t = mycms_system_zalloc(system, "opt.digest", sizeof(*t))) == NULL) {
goto cleanup;
}
t->next = digests;
digests = t;
t->str = optarg;
if (!mycms_list_str_add(system, &digests, optarg)) {
goto cleanup;
}
break;
case OPT_CMS_IN:
Expand Down Expand Up @@ -156,8 +149,7 @@ _cmd_sign(
}

if (digests == NULL) {
digests = mycms_system_zalloc(system, "digests", sizeof(*digests));
digests->str = "SHA3-256";
mycms_list_str_add(system, &digests, "SHA3-256");
}

if ((certificate_dict = mycms_dict_new(context)) == NULL) {
Expand Down Expand Up @@ -236,11 +228,8 @@ _cmd_sign(

cleanup:

while (digests != NULL) {
mycms_list_str t = digests;
digests = digests->next;
mycms_system_free(system, "digests", t);
}
mycms_list_str_free(system, digests);
digests = NULL;

mycms_io_destruct(cms_in);
cms_in = NULL;
Expand Down

0 comments on commit 39e161d

Please sign in to comment.