1 /*
2 * ModSecurity, http://www.modsecurity.org/
3 * Copyright (c) 2015 - 2021 Trustwave Holdings, Inc. (http://www.trustwave.com/)
4 *
5 * You may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * If any of the files related to licensing are missing or if you have any
11 * other questions related to licensing please contact Trustwave Holdings, Inc.
12 * directly using the email address security@modsecurity.org.
13 *
14 */
15
16
17 #include <stdio.h>
18 #include <stdlib.h>
19
20 #include "modsecurity/modsecurity.h"
21 #include "modsecurity/rules_set.h"
22
23
24 char main_rule_uri[] = "basic_rules.conf";
25
main(int argc,char ** argv)26 int main (int argc, char **argv)
27 {
28 int ret;
29 const char *error = NULL;
30 ModSecurity *modsec;
31 Transaction *transaction = NULL;
32 RulesSet *rules;
33
34 modsec = msc_init();
35
36 msc_set_connector_info(modsec, "ModSecurity-test v0.0.1-alpha (Simple " \
37 "example on how to use ModSecurity API");
38
39 rules = msc_create_rules_set();
40
41 ret = msc_rules_add_file(rules, main_rule_uri, &error);
42 if (ret < 0) {
43 fprintf(stderr, "Problems loading the rules --\n");
44 fprintf(stderr, "%s\n", error);
45 goto end;
46 }
47 msc_rules_dump(rules);
48
49 ret = msc_rules_add_remote(rules, "test",
50 "https://www.modsecurity.org/modsecurity-regression-test-secremoterules.txt",
51 &error);
52 if (ret < 0) {
53 fprintf(stderr, "Problems loading the rules --\n");
54 fprintf(stderr, "%s\n", error);
55 goto end;
56 }
57 msc_rules_dump(rules);
58
59 transaction = msc_new_transaction(modsec, rules, NULL);
60
61 msc_process_connection(transaction, "127.0.0.1", 12345, "127.0.0.1", 80);
62 msc_process_uri(transaction,
63 "http://www.modsecurity.org/test?key1=value1&key2=value2&key3=value3",
64 "GET", "1.1");
65 msc_process_request_headers(transaction);
66 msc_process_request_body(transaction);
67 msc_process_response_headers(transaction, 200, "HTTP 1.3");
68 msc_process_response_body(transaction);
69 msc_process_logging(transaction);
70 end:
71 msc_rules_cleanup(rules);
72 msc_cleanup(modsec);
73
74 return 0;
75 }
76
77
78