Avoid service overhead about checking netstat ports
[anna.git] / source / http / functions.cpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
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 //
7
8
9 #include <ctype.h>
10
11 #include <anna/http/functions.hpp>
12 #include <anna/http/internal/sccs.hpp>
13
14 using namespace anna;
15
16 void http::functions::initialize()
17 throw() {
18   http::sccs::activate();
19 }
20
21 int http::functions::find(const void* _data, const int size, const char* searched)
22 throw() {
23   int result(-1);
24   const char* data = (const char*) _data;
25   int i, matchBegin, matchLen;
26   i = matchLen = 0;
27   matchBegin = -1;
28
29   while((i + matchLen) < size) {
30     if(tolower(data [i + matchLen]) == tolower(searched [matchLen])) {
31       if(matchBegin == -1)
32         matchBegin = i;
33
34       if(searched [++ matchLen] == 0) {
35         result = matchBegin;
36         break;
37       }
38     } else {
39       if(matchBegin == -1)
40         i ++;
41       else {
42         i = matchBegin + 1;
43         matchBegin = -1;
44         matchLen = 0;
45       }
46     }
47   }
48
49   return result;
50 }