1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
11 #include <anna/config/defines.hpp>
12 #include <anna/core/DataBlock.hpp>
14 #include <anna/http/internal/Tokenizer.hpp>
15 #include <anna/http/internal/defines.hpp>
16 #include <anna/http/functions.hpp>
20 //--------------------------------------------------------------------------------------------
21 // Extrae los datos del bloque de memoria separando por espacios en blancos, tabs, etc, etc
22 //--------------------------------------------------------------------------------------------
23 void http::Tokenizer::apply(const DataBlock& data)
24 throw(RuntimeException) {
25 const char* p = data.getData();
26 const char* maxp = p + data.getSize();
27 bool searchingInit = true;
28 const char* init = NULL;
33 if(searchingInit == true) {
34 if(isSpace(*p) == false) {
37 searchingInit = false;
40 if(isSpace(*p) == true) {
41 createToken(init, len);
50 if(searchingInit == false)
51 createToken(init, len);
54 void http::Tokenizer::apply(const DataBlock& data, const char* separator)
55 throw(RuntimeException) {
56 const char* p = data.getData();
57 int size = data.getSize();
58 const char* maxp = p + size;
59 const int lenSeparator = anna_strlen(separator);
63 while(p < maxp && size > 0) {
64 if((pos = find(p, size, separator)) != -1) {
66 p += (pos + lenSeparator);
67 size -= (pos + lenSeparator);
76 void http::Tokenizer::apply(const DataBlock& data, const char separator)
77 throw(RuntimeException) {
78 const char* p = data.getData();
79 int size = data.getSize();
80 const char* maxp = p + size;
84 while(p < maxp && size > 0) {
85 if((pos = find(p, size, separator)) != -1) {
97 const http::Token* http::Tokenizer::operator [](int index) const
99 const_iterator ii = begin();
100 const_iterator maxii = end();
102 while(index && ii != maxii) {
107 return operator[](index);
110 int http::Tokenizer::find(const char* data, const int size, const char searched)
112 for(int i = 0; i < size; i ++, data ++) {
113 if(*data == searched)
120 int http::Tokenizer::find(const char* data, const int size, const char* searched)
122 static const int EndOfLineLen = 2;
127 const int slen = anna_strlen(searched);
129 if(slen == EndOfLineLen) {
130 while((pos = find(w, s, *searched)) != -1) {
131 if((s - pos) < EndOfLineLen)
136 if(*w == *searched && *(w + 1) == *(searched + 1)) {
145 while((pos = find(w, s, *searched)) != -1) {
151 if(anna_strncmp(w, searched, slen) == 0) {