1 /**
2  * This file is part of the Detox package.
3  *
4  * Copyright (c) Doug Harple <detox.dharple@gmail.com>
5  *
6  * For the full copyright and license information, please view the LICENSE
7  * file that was distributed with this source code.
8  */
9 
10 #include "config.h"
11 
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <errno.h>
16 
17 #include "detox.h"
18 #include "config_file_spoof.h"
19 #include "clean_string.h"
20 
spoof_config_file(struct detox_options * main_options)21 struct detox_parse_results *spoof_config_file(struct detox_options *main_options)
22 {
23 	struct detox_parse_results *ret = NULL;
24 	struct detox_sequence_list *sequences = NULL;
25 	struct detox_sequence_entry *work = NULL;
26 
27 	/*
28 	 * Initialize return
29 	 */
30 
31 	ret = malloc(sizeof(struct detox_parse_results));
32 	if (ret == NULL) {
33 		fprintf(stderr, "out of memory: %s\n", strerror(errno));
34 		exit(EXIT_FAILURE);
35 	}
36 
37 	memset(ret, 0, sizeof(struct detox_parse_results));
38 
39 	/*
40 	 * Head of sequence
41 	 */
42 
43 	sequences = malloc(sizeof(struct detox_sequence_list));
44 	if (sequences == NULL) {
45 		fprintf(stderr, "out of memory: %s\n", strerror(errno));
46 		exit(EXIT_FAILURE);
47 	}
48 
49 	memset(sequences, 0, sizeof(struct detox_sequence_list));
50 
51 	sequences->name = strdup("default");
52 	sequences->source_filename = strdup("inside the beast");
53 
54 	/*
55 	 * Step 1 - ISO8859_1
56 	 */
57 
58 	sequences->head = malloc(sizeof(struct detox_sequence_entry));
59 	if (sequences->head == NULL) {
60 		fprintf(stderr, "out of memory: %s\n", strerror(errno));
61 		exit(EXIT_FAILURE);
62 	}
63 
64 	work = sequences->head;
65 	memset(work, 0, sizeof(struct detox_sequence_entry));
66 
67 	work->cleaner = &clean_iso8859_1;
68 
69 	/*
70 	 * Step 2 - Safe
71 	 */
72 
73 	work->next = malloc(sizeof(struct detox_sequence_entry));
74 	if (work->next == NULL) {
75 		fprintf(stderr, "out of memory: %s\n", strerror(errno));
76 		exit(EXIT_FAILURE);
77 	}
78 
79 	work = work->next;
80 	memset(work, 0, sizeof(struct detox_sequence_entry));
81 
82 	work->cleaner = &clean_safe;
83 
84 	/*
85 	 * Step 3 - Wipe Up
86 	 */
87 
88 	work->next = malloc(sizeof(struct detox_sequence_entry));
89 	if (work->next == NULL) {
90 		fprintf(stderr, "out of memory: %s\n", strerror(errno));
91 		exit(EXIT_FAILURE);
92 	}
93 
94 	work = work->next;
95 	memset(work, 0, sizeof(struct detox_sequence_entry));
96 
97 	work->cleaner = &clean_wipeup;
98 
99 	/*
100 	 * Deprecated
101 	 */
102 	if (main_options->remove_trailing) {
103 		static struct clean_string_options *csopts;
104 
105 		csopts = malloc(sizeof(struct clean_string_options));
106 		if (csopts == NULL) {
107 			fprintf(stderr, "out of memory: %s\n", strerror(errno));
108 			exit(EXIT_FAILURE);
109 		}
110 
111 		memset(csopts, 0, sizeof(struct clean_string_options));
112 		csopts->remove_trailing = 1;
113 
114 		work->options = csopts;
115 	}
116 
117 	/*
118 	 *
119 	 */
120 
121 	ret->sequences = sequences;
122 
123 	return ret;
124 }
125