File: exampleProgram.cpp

package info (click to toggle)
bibledit-cloud 5.0.922-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 235,632 kB
  • sloc: xml: 863,336; ansic: 168,904; cpp: 82,911; javascript: 52,743; sh: 4,594; makefile: 503; php: 69
file content (91 lines) | stat: -rw-r--r-- 3,215 bytes parent folder | download | duplicates (5)
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
/*
 The MIT License (MIT)
 Copyright (c) 2012 Cyril Margorin, Imperx Inc. and other contributors
 https://code.google.com/p/parsewebdata/
 
 Permission is hereby granted, free of charge, to any person obtaining
 a copy of this software and associated documentation files (the
 "Software"), to deal in the Software without restriction, including
 without limitation the rights to use, copy, modify, merge, publish,
 distribute, sublicense, and/or sell copies of the Software, and to
 permit persons to whom the Software is furnished to do so, subject to
 the following conditions:
 
 The above copyright notice and this permission notice shall be
 included in all copies or substantial portions of the Software.
 
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
/*
 ============================================================================
 Name        : exampleProgram.c
 Author      : Cyril Margorin
 Version     :
 Copyright   : Your copyright notice
 Description : Uses shared library to print greeting
 To run the resulting executable the LD_LIBRARY_PATH must be
 set to ${project_loc}/ParseWebData/.libs
 Alternatively, libtool creates a wrapper shell script in the
 build directory of this program which can be used to run it.
 Here the script will be called exampleProgram.
 ============================================================================
 */

#include <ParseWebData.h>

#include <string.h>
#include <iostream>
#include <iomanip>


using namespace std;


int main(int argc, char *argv[]) {
	struct ContentDataPair {
		const char* ct;
		const char* data;
	};
	ContentDataPair testData[] = {
		{ "multipart/form-data; boundary=----WebKitFormBoundaryoSPfJ4Xa1po4HxQA",
				"------WebKitFormBoundaryoSPfJ4Xa1po4HxQA\r\n"
				"Content-Disposition: form-data; name=\"file\"; filename=\"file.txt\"\r\n"
				"Content-Type: text/plain\r\n"
				"\r\n"
				"file-content\r\n"
				"\r\n"
				"------WebKitFormBoundaryoSPfJ4Xa1po4HxQA\r\n"
				"Content-Disposition: form-data; name=\"command\"\r\n"
				"\r\n"
				"cmd\r\n"
				"------WebKitFormBoundaryoSPfJ4Xa1po4HxQA--\r\n" 
		},
		{ "application/x-www-form-urlencoded",
				"file=file-content&command=cmd" 
		}, 
		{ "text/plain",
				"file=file-content\r\n"
				"command=cmd\r\n" 
		}, 
		{ NULL, NULL } 
	};

	for (ContentDataPair *data = testData; data->ct != NULL; ++data) {
		ParseWebData::WebDataMap dataMap;
		ParseWebData::parse_post_data(data->data, data->ct, dataMap);
		cout << "Data with type " << data->ct << endl;
		for (ParseWebData::WebDataMap::const_iterator iter = dataMap.begin();
				iter != dataMap.end(); ++iter) {
			cout << setw(20) << setfill('-') << '-' << endl;
			cout << (*iter).first << " : " << (*iter).second.value << endl;
		}
		cout << setw(40) << setfill('=') << '=' << endl;
	}
	return 0;
}