void exec_char(char c) { int bif_r; int bif_c; printf("%c",c); switch(c) { case '.': //end freeall(mat,256); printf("\nThe end.\n"); exit(1); break; case ' ': //spaces are ignored break; case '*': //print mat['!'] prettyprint(mat['!'], fib[bif_rows['!']], fib[bif_cols['!']]); break; case '+': // add mat['!'] to mat['@'], and set mat['!'] to NULL add(); break; case '?': // compare mat['!'] mat['@'], and set mat['!'] to NULL printf(compare() ? "\nYes, equal.\n" : "\nNo, not equal.\n"); break; case '\n': //multiply mat['!'] by mat['@'] if (mat['@'] == NULL) { mat['!'] = NULL; } else if (mat['!'] == NULL) { mat['!'] = mat['@']; bif_rows['!'] = bif_rows['@']; bif_cols['!'] = bif_cols['@']; } else { multiply(); } mat['@'] = NULL; break; default: if(mat[c] != NULL) //first try to tensor mat['@'] by mat[c] { tensor(mat[c], bif_rows[c], bif_cols[c]); } else if(('A' <= c) && (c <= 'Z')) // store mat['!'] in mat[lower-case] { if(mat['!'] == NULL) { die("tried to assign NULL to a variable."); } if(mat[c + 'a' - 'A'] != NULL) { free(mat[c + 'a' - 'A']); } mat[c + 'a' - 'A'] = copy_array(mat['!'], fib[bif_rows['!']] * fib[bif_cols['!']]); bif_rows[c + 'a' - 'A'] = bif_rows['!']; bif_cols[c + 'a' - 'A'] = bif_cols['!']; } else { die("unknown character."); } break; } //for debugging: // printf("%d is %d by %d and %d is %d by %d\n", // mat['!'], fib[bif_rows['!']], fib[bif_cols['!']], // mat['@'], fib[bif_rows['@']], fib[bif_cols['@']]); }
std::string GumboInterface::prettyprint_contents(GumboNode* node, int lvl, const std::string indent_chars) { std::string contents = ""; std::string tagname = get_tag_name(node); bool no_entity_substitution = in_set(no_entity_sub, tagname); bool keep_whitespace = in_set(preserve_whitespace, tagname); bool is_inline = in_set(nonbreaking_inline, tagname); bool is_structural = in_set(structural_tags, tagname); // bool pp_okay = !is_inline && !keep_whitespace; char c = indent_chars.at(0); int n = indent_chars.length(); GumboVector* children = &node->v.element.children; for (unsigned int i = 0; i < children->length; ++i) { GumboNode* child = static_cast<GumboNode*> (children->data[i]); if (child->type == GUMBO_NODE_TEXT) { std::string val; if (no_entity_substitution) { val = std::string(child->v.text.text); } else { val = substitute_xml_entities_into_text(std::string(child->v.text.text)); } // if child of a structual element is text, indent it properly if (is_structural) { std::string indent_space = std::string((lvl-1)*n,c); contents.append(indent_space); ltrim(val); } else if (!keep_whitespace && !is_structural) { // okay to condense whitespace condense_whitespace(val); } contents.append(val); } else if (child->type == GUMBO_NODE_ELEMENT || child->type == GUMBO_NODE_TEMPLATE) { std::string val = prettyprint(child, lvl, indent_chars); contents.append(val); } else if (child->type == GUMBO_NODE_WHITESPACE) { if (keep_whitespace) { std::string wspace = std::string(child->v.text.text); contents.append(wspace); } else if (is_inline || in_set(other_text_holders, tagname)) { char last_char = 'x'; if (!contents.empty()) { last_char = contents.at(contents.length()-1); } if (std::string(" \t\v\f\r\n").find(last_char) == std::string::npos) { contents.append(std::string(" ")); } } } else if (child->type == GUMBO_NODE_CDATA) { contents.append("<![CDATA[" + std::string(child->v.text.text) + "]]>"); } else if (child->type == GUMBO_NODE_COMMENT) { contents.append("<!--" + std::string(child->v.text.text) + "-->"); } else { fprintf(stderr, "unknown element of type: %d\n", child->type); } } return contents; }
int ProcessFromClient(SFSnortPacket *sp) { RULEDATA *ruledata; WEB_ENTRY webentry; int result; FILEINFO *fileinfo; DEBUGOUT((D_CLIENT | D_INFO), printf("ProcessFromClient enter\n")); DEBUGOUT((D_PACKET | D_WARN), prettyprint(sp->payload, sp->payload_size)); ruledata = _dpd.streamAPI->get_application_data(sp->stream_session_ptr, SAAC_HTTP); if(!ruledata) { DEBUGOUT((D_CLIENT | D_DEBUG), printf("ProcessFromClient: adding new rule data\n")); ruledata = calloc(1, sizeof(RULEDATA)); if(!ruledata) { DEBUGOUT(D_CRITICAL, printf("ProcessFromClient: ruledata malloc failed\n")); return(-1); } _dpd.streamAPI->set_application_data(sp->stream_session_ptr, SAAC_HTTP, ruledata, &free); ruledata->sid = NRTSID; ruledata->streaminfoidx = INVALIDSTREAMIDX; ruledata->state = WAITINGFORRESPONSEHEADER; } else if(ruledata->sid != NRTSID) { DEBUGOUT(D_CRITICAL, printf("ProcessFromClient: Not our data! (sid %d/0x%08x)\n", ruledata->sid, ruledata->sid)); return(-1); } else if(IsStreamIgnored(ruledata)) { DEBUGOUT((D_SERVER | D_WARN), printf("ProcessFromClient: stream is ignored\n")); return(-1); } fileinfo = calloc(1, sizeof(FILEINFO)); // Set all counts and sizes to 0, all strings to empty, and pointers to NULL // memset(fileinfo, '\0', sizeof(FILEINFO)); result = ParseClientRequest(sp->payload, sp->payload_size, &webentry); DEBUGOUT((D_CLIENT | D_INFO), printf("return from ParseClientRequest() was %d\n", result)); if(result <= 0) { free(fileinfo); return(-1); } // Copy URL and Host header out of webentry into fileinfo snprintf(fileinfo->url, sizeof(fileinfo->url), "%s", webentry.url); fileinfo->url[sizeof(fileinfo->url) - 1] = 0; snprintf(fileinfo->hostname, sizeof(fileinfo->hostname), "%s", webentry.host); fileinfo->hostname[sizeof(fileinfo->hostname) - 1] = 0; // Now store what we know about this request fileinfo->saddr = sp->ip4_header->source; fileinfo->daddr = sp->ip4_header->destination; // Add address info to webentry webentry.src_ip.ip.ipv4 = sp->ip4_header->source; webentry.src_ip.family = AF_INET; webentry.dst_ip.ip.ipv4 = sp->ip4_header->destination; webentry.dst_ip.family = AF_INET; // Now send our webentry as an Intel Nugget! if(rzb_collection.sendWebTrack(&webentry) == R_FAIL) { printf("Failed to send web track info!\n"); // Not making this fatal error } DEBUGOUT((D_CLIENT | D_DEBUG), DumpFileInfo(fileinfo)); result = AddFileInfoListElem(ruledata, fileinfo); DEBUGOUT((D_CLIENT | D_INFO), printf("return from StoreFileData() was %d\n", result)); if(result < 0) { DEBUGOUT(D_CRITICAL, printf("AddFileInfoListElem failed!\n")); free(fileinfo); return(-1); } DEBUGOUT((D_CLIENT | D_WARN), DumpFileInfoList(ruledata)); // _dpd.alertAdd(GENERATOR_NRT, DST_PORT_MATCH, // 1, 0, 3, DST_PORT_MATCH_STR, 0); return(0); }