aboutsummaryrefslogtreecommitdiffstats
path: root/tests/tools/cmp_tbdata.c
blob: c0b12cd9b1d4c901e2db12e55f149eabf050a800 (plain)
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
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>

int line = 0;
char buffer1[8192];
char buffer2[8192];

void check(bool ok)
{
	if (ok)
		return;
	fprintf(stderr, "Error in testbench output compare (line=%d):\n-%s\n+%s\n", line, buffer1, buffer2);
	exit(1);
}

int main(int argc, char **argv)
{
	FILE *f1, *f2;
	bool eof1, eof2;
	int i;

	check(argc == 3);

	f1 = fopen(argv[1], "r");
	f2 = fopen(argv[2], "r");

	check(f1 && f2);

	while (!feof(f1) && !feof(f2))
	{
		line++;
		buffer1[0] = 0;
		buffer2[0] = 0;

		eof1 = fgets(buffer1, 1024, f1) == NULL;
		eof2 = fgets(buffer2, 1024, f2) == NULL;

		if (*buffer1 && buffer1[strlen(buffer1)-1] == '\n')
			buffer1[strlen(buffer1)-1] = 0;

		if (*buffer2 && buffer2[strlen(buffer2)-1] == '\n')
			buffer2[strlen(buffer2)-1] = 0;

		check(eof1 == eof2);

		for (i = 0; buffer1[i] || buffer2[i]; i++)
		{
			check(buffer1[i] != 0 && buffer2[i] != 0);

			// first argument is the reference. An 'z' or 'x'
			// here means we don't care about the result.
			if (buffer1[i] == 'z' || buffer1[i] == 'x')
				continue;
			if (buffer1[i] == 'Z' || buffer1[i] == 'X')
				continue;

			check(buffer1[i] == buffer2[i]);
		}
	}

	check(feof(f1) && feof(f2));

	fclose(f1);
	fclose(f2);
	return 0;
}
span>> <th>libmproxy.protocol.http.HTTPResponse</th> <td>An HTTP response.</td> </tr> <tr> <th>libmproxy.protocol.http.HTTPRequest</th> <td>An HTTP request.</td> </tr> <tr> <th>libmproxy.protocol.primitives.Error</th> <td>A communications error.</td> </tr> <tr> <th>libmproxy.script.ScriptContext</th> <td> A handle for interacting with mitmproxy's from within scripts.</td> </tr> <tr> <th>libmproxy.flow.ODict</th> <td>A dictionary-like object for managing sets of key/value data. There is also a variant called CaselessODict that ignores key case for some calls (used mainly for headers). </td> </tr> <tr> <th>netlib.certutils.SSLCert</th> <td>Exposes information SSL certificates.</td> </tr> </table> The canonical API documentation is the code, which you can browse locally or in our [GitHub repo](https://github.com/mitmproxy/mitmproxy). You can view the API documentation using pydoc (which is installed with Python by default), like this: <pre class="terminal"> > pydoc libmproxy.protocol.http.HTTPRequest </pre> ## Running scripts in parallel We have a single flow primitive, so when a script is handling something, other requests block. While that's a very desirable behaviour under some circumstances, scripts can be run threaded by using the <code>libmproxy.script.concurrent</code> decorator. $!example("examples/nonblocking.py")!$ ## Make scripts configurable with arguments Sometimes, you want to pass runtime arguments to the inline script. This can be simply done by surrounding the script call with quotes, e.g. <code>mitmdump -s "script.py --foo 42"</code>. The arguments are then exposed in the start event: $!example("examples/modify_response_body.py")!$ ## Running scripts on saved flows Sometimes, we want to run a script on __Flow__ objects that are already complete. This happens when you start a script, and then load a saved set of flows from a file (see the "scripted data transformation" example on the [mitmdump](@!urlTo("mitmdump.html")!@) page). It also happens when you run a one-shot script on a single flow through the _|_ (pipe) shortcut in mitmproxy. In this case, there are no client connections, and the events are run in the following order: __start__, __request__, __responseheaders__, __response__, __error__, __done__. If the flow doesn't have a __response__ or __error__ associated with it, the matching events will be skipped. ## Spaces in the script path By default, spaces are interpreted as separator between the inline script and its arguments (e.g. <code>-s "foo.py 42"</code>). Consequently, the script path needs to be wrapped in a separate pair of quotes if it contains spaces: <code>-s "'./foo bar/baz.py' 42"</code>.