• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef SQL_ANALYZER_H
17 #define SQL_ANALYZER_H
18 
19 #include <string>
20 
21 #include "values_bucket.h"
22 
23 #include "constant.h"
24 
25 namespace OHOS::Request::Download {
26 class SqlAnalyzer {
27 public:
28     SqlAnalyzer();
29     ~SqlAnalyzer();
30 
31     bool CheckValuesBucket(const NativeRdb::ValuesBucket &value);
32     bool FindIllegalWords(std::string sql);
33     bool StrCheck(char &ch, std::size_t strlen, std::string sql, std::size_t &pos);
34     bool CharCheck(char &ch, std::string sql, std::size_t &pos);
35 
36 private:
IsNumber(char ch)37     inline bool IsNumber(char ch)
38     {
39         return (ch >= '0' && ch <= '9');
40     }
IsLetter(char ch)41     inline bool IsLetter(char ch)
42     {
43         return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch == '_');
44     }
IsLetterNumber(char ch)45     inline bool IsLetterNumber(char ch)
46     {
47         return IsNumber(ch) || IsLetter(ch);
48     }
PickChar(std::string str,std::size_t index)49     inline char PickChar(std::string str, std::size_t index)
50     {
51         if (index < str.length()) {
52             return str.at(index);
53         }
54         return '\0';
55     }
IsInStr(char ch,std::string str)56     inline int IsInStr(char ch, std::string str)
57     {
58         std::size_t pos = str.find(ch);
59         if (pos == std::string::npos) {
60             return OPERATION_ERROR;
61         }
62         return 0;
63     }
64 };
65 } // namespace OHOS::Request::Download
66 #endif // SQL_ANALYZER_H
67