MCPcopy Create free account
hub / github.com/acl-dev/acl / test_parse

Function test_parse

lib_acl_cpp/samples/http_mime/http_mime.cpp:7–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5#include "acl_cpp/lib_acl.hpp"
6
7static void test_parse(const char* path, const char* boundary)
8{
9 acl::http_mime mime(boundary);
10 mime.set_saved_path(path);
11 acl::string buf;
12
13 if (acl::ifstream::load(path, &buf) == false) {
14 printf("load %s error\r\n", path);
15 return;
16 }
17
18 mime.update(buf.c_str(), buf.length());
19#if 1
20 const std::list<acl::http_mime_node*>& nodes = mime.get_nodes();
21 for (std::list<acl::http_mime_node*>::const_iterator cit = nodes.begin();
22 cit != nodes.end(); ++cit) {
23 acl::http_mime_node* node = *cit;
24 if (node->get_mime_type() == acl::HTTP_MIME_PARAM) {
25 const char* name = node->get_name();
26 const char* value = node->get_value();
27 printf("name: %s, value: %s\r\n", name ? name : "null",
28 value ? value : "null");
29 } else if (node->get_mime_type() == acl::HTTP_MIME_FILE) {
30 const char* filename = node->get_filename();
31 printf("filename: %s\r\n", filename ? filename : "null");
32 (void) node->save(filename);
33 }
34 }
35#endif
36
37#if 1
38 printf("length: %d\r\n", (int) buf.length());
39 const std::list<acl::http_mime_node*>& nodes2 = mime.get_nodes();
40 for (std::list<acl::http_mime_node*>::const_iterator cit = nodes2.begin();
41 cit != nodes2.end(); ++cit) {
42 const char* n1, *f, *v;
43 n1 = (*cit)->get_name();
44 f = (*cit)->get_filename();
45 v = (*cit)->get_value();
46 printf(">>>name: %s, value: %s, file: %s<br>\r\n",
47 n1 ? n1 : "null", v ? v : "null", f ? f : "null");
48 }
49
50 const acl::http_mime_node* node = mime.get_node("file_0");
51 if (node == NULL || node->get_mime_type() != acl::HTTP_MIME_FILE) {
52 printf("filename not found\r\n");
53 return;
54 }
55 const char* ptr = node->get_filename();
56 if (ptr == NULL || *ptr == 0) {
57 printf("filename's value null\r\n");
58 } else {
59 printf("filename: %s\r\n", ptr);
60 }
61#endif
62}
63
64static void test_build(const char* file, const char* boundary) {

Callers 1

mainFunction · 0.70

Calls 13

set_saved_pathMethod · 0.80
beginMethod · 0.80
get_mime_typeMethod · 0.80
updateMethod · 0.45
c_strMethod · 0.45
lengthMethod · 0.45
get_nodesMethod · 0.45
endMethod · 0.45
get_nameMethod · 0.45
get_valueMethod · 0.45
get_filenameMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…