normalizing

add_key_notification
Volker Birk 2019-12-22 19:55:59 +01:00
parent 98649dac3a
commit a575e8b9c3
2 changed files with 59 additions and 61 deletions

View File

@ -9,9 +9,9 @@
#include "keyreset_command.h"
DYNAMIC_API keyreset_command * new_keyreset_command(const pEp_identity *ident, const char *new_key)
DYNAMIC_API keyreset_command * new_keyreset_command(const pEp_identity * ident, const char * new_key)
{
keyreset_command *command = NULL;
keyreset_command * command = NULL;
// key and command should not be NULL, that's bad style (while legal)
@ -26,22 +26,22 @@ DYNAMIC_API keyreset_command * new_keyreset_command(const pEp_identity *ident, c
command->ident = ident ? identity_dup(ident) : new_identity(NULL, NULL, NULL, NULL);
if (command->ident == NULL)
goto enomem;
if (command->ident && command->ident->fpr) {
// make hex code uppercase
// make content uppercase
for (size_t i=0; i<strlen(command->ident->fpr); i++)
command->ident->fpr[i] = toupper(command->ident->fpr[i]);
}
command->new_key = new_key ? strdup(new_key) : strdup("");
assert(command->new_key);
if (command->new_key == NULL)
goto enomem;
// make hex code uppercase
// make content uppercase
for (size_t i=0; i<strlen(command->new_key); i++)
command->new_key[i] = toupper(command->new_key[i]);
return command;
enomem:
@ -58,7 +58,7 @@ DYNAMIC_API void free_keyreset_command(keyreset_command * command)
}
}
DYNAMIC_API keyreset_command * keyreset_command_dup(const keyreset_command *src)
DYNAMIC_API keyreset_command * keyreset_command_dup(const keyreset_command * src)
{
assert(src);
if (src == NULL)
@ -67,9 +67,9 @@ DYNAMIC_API keyreset_command * keyreset_command_dup(const keyreset_command *src)
return new_keyreset_command(src->ident, src->new_key);
}
DYNAMIC_API keyreset_command_list *new_keyreset_command_list(keyreset_command *command)
DYNAMIC_API keyreset_command_list * new_keyreset_command_list(keyreset_command * command)
{
keyreset_command_list *result = calloc(1, sizeof(keyreset_command_list));
keyreset_command_list * result = calloc(1, sizeof(keyreset_command_list));
assert(result);
if (result && command)
@ -78,32 +78,32 @@ DYNAMIC_API keyreset_command_list *new_keyreset_command_list(keyreset_command *c
return result;
}
DYNAMIC_API keyreset_command_list *keyreset_command_list_dup(
const keyreset_command_list *src
DYNAMIC_API keyreset_command_list * keyreset_command_list_dup(
const keyreset_command_list * src
)
{
assert(src);
if (src == NULL)
return NULL;
keyreset_command* copy_pair = keyreset_command_dup(src->command);
keyreset_command * cpy = keyreset_command_dup(src->command);
keyreset_command_list *dst = new_keyreset_command_list(copy_pair);
keyreset_command_list * dst = new_keyreset_command_list(cpy);
if (dst == NULL)
return NULL;
keyreset_command_list* src_curr = src->next;
keyreset_command_list** dst_curr_ptr = &dst->next;
keyreset_command_list * src_curr = src->next;
keyreset_command_list ** dst_curr_ptr = &dst->next;
while (src_curr) {
copy_pair = keyreset_command_dup(src_curr->command);
if (copy_pair == NULL) {
cpy = keyreset_command_dup(src_curr->command);
if (cpy == NULL) {
free_keyreset_command_list(dst);
return NULL;
}
*dst_curr_ptr = new_keyreset_command_list(copy_pair);
*dst_curr_ptr = new_keyreset_command_list(cpy);
if (*dst_curr_ptr == NULL) {
free_keyreset_command(copy_pair);
free_keyreset_command(cpy);
free_keyreset_command_list(dst);
return NULL;
}
@ -112,12 +112,11 @@ DYNAMIC_API keyreset_command_list *keyreset_command_list_dup(
}
return dst;
}
DYNAMIC_API keyreset_command_list *keyreset_command_list_add(
keyreset_command_list *command_list,
keyreset_command *command
DYNAMIC_API keyreset_command_list * keyreset_command_list_add(
keyreset_command_list * command_list,
keyreset_command * command
)
{
assert(command);
@ -140,7 +139,7 @@ DYNAMIC_API keyreset_command_list *keyreset_command_list_add(
return command_list;
}
keyreset_command_list* list_curr = command_list;
keyreset_command_list * list_curr = command_list;
while (list_curr->next)
list_curr = list_curr->next;
@ -152,12 +151,11 @@ DYNAMIC_API keyreset_command_list *keyreset_command_list_add(
return NULL;
return list_curr->next;
}
DYNAMIC_API keyreset_command_list *keyreset_command_list_append(
keyreset_command_list *command_list,
keyreset_command_list *second
DYNAMIC_API keyreset_command_list * keyreset_command_list_append(
keyreset_command_list * command_list,
keyreset_command_list * second
)
{
assert(command_list);
@ -168,9 +166,9 @@ DYNAMIC_API keyreset_command_list *keyreset_command_list_append(
if (second == NULL || second->command == NULL)
return command_list;
keyreset_command_list *_s = command_list;
for (keyreset_command_list *_s2 = second; _s2 != NULL; _s2 = _s2->next) {
keyreset_command *_sp = keyreset_command_dup(_s2->command);
keyreset_command_list * _s = command_list;
for (keyreset_command_list * _s2 = second; _s2 != NULL; _s2 = _s2->next) {
keyreset_command * _sp = keyreset_command_dup(_s2->command);
if (_sp == NULL)
return NULL;
_s = keyreset_command_list_add(_s, _sp);
@ -183,18 +181,18 @@ DYNAMIC_API keyreset_command_list *keyreset_command_list_append(
}
DYNAMIC_API int keyreset_command_list_length(
const keyreset_command_list *command_list
const keyreset_command_list * command_list
)
{
int len = 0;
for (const keyreset_command_list *_sl = command_list; _sl && _sl->command; _sl = _sl->next)
for (const keyreset_command_list * _sl = command_list; _sl && _sl->command; _sl = _sl->next)
len++;
return len;
}
DYNAMIC_API void free_keyreset_command_list(keyreset_command_list *command_list)
DYNAMIC_API void free_keyreset_command_list(keyreset_command_list * command_list)
{
if (command_list) {
free_keyreset_command_list(command_list->next);

View File

@ -11,8 +11,8 @@ extern "C" {
#endif
typedef struct _keyreset_command {
pEp_identity *ident;
char *new_key;
pEp_identity * ident;
char * new_key;
} keyreset_command;
// new_keyreset_command() - allocate new keyreset_command
@ -21,13 +21,13 @@ typedef struct _keyreset_command {
// ident (in) identity to reset, including fpr of existing key
// new_key (in) fpr of new key
//
// return command:
// return value:
// pointer to keyreset_command or NULL on failure
//
// caveat:
// ident and new_key are copied and remain in the ownership of the caller
// ident, new_key are copied and remain in the ownership of the caller
DYNAMIC_API keyreset_command * new_keyreset_command(const pEp_identity *ident, const char *new_key);
DYNAMIC_API keyreset_command * new_keyreset_command(const pEp_identity * ident, const char * new_key);
// free_keyreset_command() - free memory allocated by keyreset_command
@ -35,7 +35,7 @@ DYNAMIC_API keyreset_command * new_keyreset_command(const pEp_identity *ident, c
// parameters:
// command (in) pointer to keyreset_command to free
DYNAMIC_API void free_keyreset_command(keyreset_command *command);
DYNAMIC_API void free_keyreset_command(keyreset_command * command);
// keyreset_command_dup() - duplicate keyreset_command (deep copy)
@ -43,15 +43,15 @@ DYNAMIC_API void free_keyreset_command(keyreset_command *command);
// parameters:
// src (in) pointer to keyreset_command to duplicate
//
// return command:
// return value:
// pointer to copy of src or NULL on failure
DYNAMIC_API keyreset_command * keyreset_command_dup(const keyreset_command *src);
DYNAMIC_API keyreset_command * keyreset_command_dup(const keyreset_command * src);
typedef struct _keyreset_command_list {
keyreset_command *command;
struct _keyreset_command_list *next;
keyreset_command * command;
struct _keyreset_command_list * next;
} keyreset_command_list;
@ -60,14 +60,14 @@ typedef struct _keyreset_command_list {
// parameters:
// command (in) initial command
//
// return command:
// return value:
// pointer to keyreset_command_list object or NULL if out of memory
//
// caveat:
// the ownership of the command goes to the keyreset_command_list
// next pointer is NULL
DYNAMIC_API keyreset_command_list *new_keyreset_command_list(keyreset_command *command);
DYNAMIC_API keyreset_command_list * new_keyreset_command_list(keyreset_command * command);
// keyreset_command_list_dup() - duplicate a keyreset_command_list (deep copy)
@ -75,12 +75,12 @@ DYNAMIC_API keyreset_command_list *new_keyreset_command_list(keyreset_command *c
// parameters:
// src (in) keyreset_command_list to copy
//
// return command:
// return value:
// pointer to keyreset_command_list object or NULL if out of memory
// keyreset_command command copies created by this function belong to the returned list
DYNAMIC_API keyreset_command_list *keyreset_command_list_dup(
const keyreset_command_list *src
DYNAMIC_API keyreset_command_list * keyreset_command_list_dup(
const keyreset_command_list * src
);
@ -90,15 +90,15 @@ DYNAMIC_API keyreset_command_list *keyreset_command_list_dup(
// command_list (in) keyreset_command_list struct or NULL to create a new one
// command (in) keyreset_command to add
//
// return command:
// return value:
// pointer to last element in keyreset_command_list or NULL if out of memory
//
// caveat:
// the ownership of the command goes to the keyreset_command_list if add is successful
DYNAMIC_API keyreset_command_list *keyreset_command_list_add(
keyreset_command_list *command_list,
keyreset_command *command
DYNAMIC_API keyreset_command_list * keyreset_command_list_add(
keyreset_command_list * command_list,
keyreset_command * command
);
@ -108,7 +108,7 @@ DYNAMIC_API keyreset_command_list *keyreset_command_list_add(
// command_list (in) keyreset_command_list struct to append to
// second (in) keyreset_command_list struct to append
//
// return command:
// return value:
// pointer to last element in command_list or NULL if out of memory
// or command_list is NULL
//
@ -116,9 +116,9 @@ DYNAMIC_API keyreset_command_list *keyreset_command_list_add(
// all commands are being copied before being added to the list
// the original commands are still being owned by the caller
DYNAMIC_API keyreset_command_list *keyreset_command_list_append(
keyreset_command_list *command_list,
keyreset_command_list *second
DYNAMIC_API keyreset_command_list * keyreset_command_list_append(
keyreset_command_list * command_list,
keyreset_command_list * second
);
@ -127,11 +127,11 @@ DYNAMIC_API keyreset_command_list *keyreset_command_list_append(
// parameters:
// command_list (in) keyreset_command_list struct to determine length of
//
// return command:
// return value:
// length of command_list in number of elements
DYNAMIC_API int keyreset_command_list_length(
const keyreset_command_list *command_list
const keyreset_command_list * command_list
);
@ -140,7 +140,7 @@ DYNAMIC_API int keyreset_command_list_length(
// parameters:
// command_list (in) keyreset_command_list to free
DYNAMIC_API void free_keyreset_command_list(keyreset_command_list *command_list);
DYNAMIC_API void free_keyreset_command_list(keyreset_command_list * command_list);
#ifdef __cplusplus