-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
executable file
·92 lines (81 loc) · 2.25 KB
/
main.c
File metadata and controls
executable file
·92 lines (81 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: efriedma <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/08/06 15:34:21 by efriedma #+# #+# */
/* Updated: 2018/10/16 00:32:23 by efriedma ### ########.fr */
/* */
/* ************************************************************************** */
#include "openssl.h"
const int g_total = 6;
int g_cbc;
void init_command(t_type **arr, size_t index, char *str, void *command)
{
arr[index]->name = ft_strdup(str);
arr[index]->ptr = command;
}
t_type **create(t_type **s)
{
size_t i;
i = 0;
s = ft_memalloc(sizeof(t_type) * g_total);
while (i < g_total)
{
s[i] = ft_memalloc(sizeof(t_type));
i++;
}
init_command(s, 0, "md5", md5start);
init_command(s, 1, "sha256", sha256start);
init_command(s, 2, "base64", base64start);
init_command(s, 3, "des", des);
init_command(s, 4, "des-cbc", des);
init_command(s, 5, "des-ecb", des);
return (s);
}
int dispatch(t_type *t, int argc, char **argv)
{
void (*x) (char**, int);
if (!ft_strcmp(t->name, argv[1]))
{
x = (void (*)(char**, int))(t->ptr);
if (!ft_strcmp(t->name, "des-cbc") || !ft_strcmp(t->name, "des"))
g_cbc = 1;
x(argv, argc);
return (1);
}
return (0);
}
void free_struct(t_type **done)
{
size_t i;
i = 0;
while (i < g_total)
{
free(done[i]->name);
i++;
}
ft_memdel((void**)done);
}
int main(int argc, char **argv)
{
t_type **s;
size_t i;
i = 0;
s = 0;
if (argc >= 2)
{
s = create(s);
i = 0;
while (i < g_total && ft_strcmp(s[i]->name, argv[1]))
i++;
if (i == g_total || !dispatch(s[i], argc, argv))
printcommands(argv[1]);
free_struct(s);
}
else
ft_putstr("usage: ft_ssl command [command opts] [command args]\n");
return (0);
}