mirror of
https://github.com/SpacehuhnTech/esp8266_deauther.git
synced 2025-12-21 23:01:00 -08:00
No more static stuff
Moved the print functions to the function.h and included them in language using extern so not every class has to "extern" them again. Also fixed some type comparisons and made removed the static from the progmem variables. C code is super messy! But I'm not going to rewrite it again so deal with it :D
This commit is contained in:
@@ -12,7 +12,7 @@ void Names::load() {
|
||||
checkFile(FILE_PATH, String(OPEN_BRACKET) + String(CLOSE_BRACKET));
|
||||
JsonArray &arr = parseJSONFile(FILE_PATH, jsonBuffer);
|
||||
|
||||
for (int i = 0; i < arr.size() && i < NAME_LIST_SIZE; i++) {
|
||||
for (uint32_t i = 0; i < arr.size() && i < NAME_LIST_SIZE; i++) {
|
||||
JsonArray &tmpArray = arr.get<JsonVariant>(i);
|
||||
internal_add(tmpArray.get<String>(0), tmpArray.get<String>(2), tmpArray.get<String>(3), tmpArray.get<uint8_t>(4), false);
|
||||
sort();
|
||||
|
||||
@@ -12,7 +12,7 @@ void SSIDs::load() {
|
||||
JsonObject &obj = parseJSONFile(FILE_PATH, jsonBuffer);
|
||||
JsonArray &arr = obj.get<JsonArray>(str(SS_JSON_SSIDS));
|
||||
|
||||
for (int i = 0; i < arr.size() && i < SSID_LIST_SIZE; i++) {
|
||||
for (uint32_t i = 0; i < arr.size() && i < SSID_LIST_SIZE; i++) {
|
||||
JsonArray &tmpArray = arr.get<JsonVariant>(i);
|
||||
internal_add(tmpArray.get<String>(0), tmpArray.get<bool>(1), tmpArray.get<int>(2));
|
||||
}
|
||||
|
||||
@@ -261,7 +261,7 @@ void Scan::save(bool force) {
|
||||
buf = String(); // clear buffer
|
||||
uint32_t apCount = accesspoints.count();
|
||||
|
||||
for (int i = 0; i < apCount; i++) {
|
||||
for (uint32_t i = 0; i < apCount; i++) {
|
||||
buf += String(OPEN_BRACKET) + String(DOUBLEQUOTES) + escape(accesspoints.getSSID(i)) + String(DOUBLEQUOTES) + String(COMMA); // ["ssid",
|
||||
buf += String(DOUBLEQUOTES) + escape(accesspoints.getNameStr(i)) + String(DOUBLEQUOTES) + String(COMMA); // "name",
|
||||
buf += String(accesspoints.getCh(i)) + String(COMMA); // 1,
|
||||
@@ -287,7 +287,7 @@ void Scan::save(bool force) {
|
||||
buf += String(CLOSE_BRACKET) + String(COMMA) + String(DOUBLEQUOTES) + str(SC_JSON_STATIONS) + String(DOUBLEQUOTES) + String(DOUBLEPOINT) + String(OPEN_BRACKET); // ],"stations":[;
|
||||
uint32_t stationCount = stations.count();
|
||||
|
||||
for (int i = 0; i < stationCount; i++) {
|
||||
for (uint32_t i = 0; i < stationCount; i++) {
|
||||
buf += String(OPEN_BRACKET) + String(DOUBLEQUOTES) + stations.getMacStr(i) + String(DOUBLEQUOTES) + String(COMMA); // ["00:11:22:00:11:22",
|
||||
buf += String(stations.getCh(i)) + String(COMMA); // 1,
|
||||
buf += String(DOUBLEQUOTES) + stations.getNameStr(i) + String(DOUBLEQUOTES) + String(COMMA); // "name",
|
||||
|
||||
@@ -49,7 +49,7 @@ void SerialInterface::parameterError(String parameter) {
|
||||
bool SerialInterface::isInt(String str) {
|
||||
if (eqls(str,STR_TRUE) || eqls(str,STR_FALSE))
|
||||
return true;
|
||||
for (int i = 0; i < str.length(); i++)
|
||||
for (uint32_t i = 0; i < str.length(); i++)
|
||||
if (!isDigit(str.charAt(i))) return false;
|
||||
return true;
|
||||
}
|
||||
@@ -130,7 +130,7 @@ void SerialInterface::update() {
|
||||
void SerialInterface::runCommands(String input) {
|
||||
String tmp;
|
||||
|
||||
for (int i = 0; i < input.length(); i++) {
|
||||
for (uint32_t i = 0; i < input.length(); i++) {
|
||||
// when 2 semicolons in a row without a backslash escaping the first
|
||||
if (input.charAt(i) == SEMICOLON && input.charAt(i + 1) == SEMICOLON && input.charAt(i - 1) != BACKSLASH) {
|
||||
runCommand(tmp);
|
||||
@@ -156,7 +156,7 @@ void SerialInterface::runCommand(String input) {
|
||||
bool withinQuotes = false;
|
||||
bool escaped = false;
|
||||
char c;
|
||||
for (int i = 0; i < input.length() && i < 512; i++) {
|
||||
for (uint32_t i = 0; i < input.length() && i < 512; i++) {
|
||||
c = input.charAt(i);
|
||||
|
||||
// when char is an unescaped
|
||||
|
||||
@@ -153,6 +153,117 @@ String replaceUtf8(String str, String r){
|
||||
return result;
|
||||
}
|
||||
|
||||
// ===== LANGUAGE STRING FUNCTIONS ===== //
|
||||
|
||||
// for reading Strings from the PROGMEM
|
||||
String str(const char* ptr){
|
||||
char keyword[strlen_P(ptr)];
|
||||
strcpy_P(keyword, ptr);
|
||||
return String(keyword);
|
||||
}
|
||||
|
||||
// for converting keywords
|
||||
String keyword(const char* keywordPtr){
|
||||
char keyword[strlen_P(keywordPtr)];
|
||||
strcpy_P(keyword, keywordPtr);
|
||||
|
||||
String str = "";
|
||||
uint8_t len = strlen(keyword);
|
||||
uint8_t i = 0;
|
||||
|
||||
while(i<len && keyword[i] != SLASH && keyword[i] != COMMA){
|
||||
str += keyword[i];
|
||||
i++;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
// equals function
|
||||
bool eqls(const char* str, const char* keywordPtr){
|
||||
if(strlen(str) > 255) return false; // when string too long
|
||||
|
||||
char keyword[strlen_P(keywordPtr) + 1];
|
||||
strcpy_P(keyword, keywordPtr);
|
||||
|
||||
uint8_t lenStr = strlen(str);
|
||||
uint8_t lenKeyword = strlen(keyword);
|
||||
if(lenStr > lenKeyword) return false; // string can't be longer than keyword (but can be smaller because of '/' and ',')
|
||||
|
||||
uint8_t a = 0;
|
||||
uint8_t b = 0;
|
||||
bool result = true;
|
||||
while(a < lenStr && b < lenKeyword){
|
||||
if(keyword[b] == SLASH || keyword[b] == COMMA) b++;
|
||||
if(tolower(str[a]) != tolower(keyword[b])) result = false;
|
||||
if((a == lenStr && !result) || !result){ // fast forward to next comma
|
||||
while(b < lenKeyword && keyword[b] != COMMA) b++;
|
||||
result = true;
|
||||
a = 0;
|
||||
} else {
|
||||
a++;
|
||||
b++;
|
||||
}
|
||||
}
|
||||
// comparison correct AND string checked until the end AND keyword checked until the end
|
||||
return result && a == lenStr && (keyword[b] == COMMA || keyword[b] == SLASH || keyword[b] == ENDOFLINE);
|
||||
}
|
||||
|
||||
bool eqls(String str, const char* keywordPtr){
|
||||
return eqls(str.c_str(), keywordPtr);
|
||||
}
|
||||
|
||||
// boolean to string
|
||||
String b2s(bool input){
|
||||
return str(input ? STR_TRUE : STR_FALSE);
|
||||
}
|
||||
|
||||
// boolean to asterix *
|
||||
String b2a(bool input){
|
||||
return (input ? String(ASTERIX) : String(SPACE));
|
||||
}
|
||||
|
||||
// string to boolean
|
||||
bool s2b(String input){
|
||||
return eqls(input, STR_TRUE);
|
||||
}
|
||||
|
||||
// ===== PRINT FUNCTIONS ===== //
|
||||
void prnt(String s){
|
||||
Serial.print(s);
|
||||
}
|
||||
void prnt(bool b){
|
||||
Serial.print(b2s(b));
|
||||
}
|
||||
void prnt(char c){
|
||||
Serial.print(c);
|
||||
}
|
||||
void prnt(const char* ptr){
|
||||
Serial.print(FPSTR(ptr));
|
||||
}
|
||||
void prnt(int i){
|
||||
Serial.print((String)i);
|
||||
}
|
||||
|
||||
void prntln(){
|
||||
Serial.println();
|
||||
}
|
||||
void prntln(String s){
|
||||
Serial.println(s);
|
||||
}
|
||||
void prntln(bool b){
|
||||
Serial.println(b2s(b));
|
||||
}
|
||||
void prntln(char c){
|
||||
Serial.println(c);
|
||||
}
|
||||
void prntln(const char* ptr){
|
||||
Serial.println(FPSTR(ptr));
|
||||
}
|
||||
void prntln(int i){
|
||||
Serial.println((String)i);
|
||||
}
|
||||
|
||||
/* ===== WiFi ===== */
|
||||
void setWifiChannel(uint8_t ch){
|
||||
if(ch != wifi_channel && ch > 0 && ch < 15){
|
||||
@@ -593,4 +704,4 @@ String formatBytes(size_t bytes) {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user