Skip to content

Commit

Permalink
v1.5.3
Browse files Browse the repository at this point in the history
 - added url encoding for activities in logItem action in DFDataset
  • Loading branch information
matsfunk committed May 6, 2021
1 parent 35c5c2b commit da2c126
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 1 deletion.
Binary file modified dist/oocsi.zip
Binary file not shown.
34 changes: 34 additions & 0 deletions dist/oocsi/DFDataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ bool DFDataset::logItem() {
activity_id = activity_id != NULL ? activity_id : "";
device_id = device_id != NULL ? device_id : "";

// url encode activity id string because it will be part of the URL
activity_id = urlencode(activity_id);

// do transmission
#ifdef ARDUINO_SAMD_NANO_33_IOT
// compile address
Expand Down Expand Up @@ -483,3 +486,34 @@ void DFDataset::setActivityLEDPin(int ledPin) {
void DFDataset::setLogging(bool log) {
logging = log;
}

const char* DFDataset::urlencode(const char* str)
{
String encodedString="";
char c;
char code0;
char code1;
char code2;
for (int i =0; i < strlen(str); i++){
c=str[i];
if (isalnum(c)){
encodedString+=c;
} else {
code1=(c & 0xf)+'0';
if ((c & 0xf) >9){
code1=(c & 0xf) - 10 + 'A';
}
c=(c>>4)&0xf;
code0=c+'0';
if (c > 9){
code0=c - 10 + 'A';
}
code2='\0';
encodedString+='%';
encodedString+=code0;
encodedString+=code1;
}
yield();
}
return encodedString.c_str();
}
1 change: 1 addition & 0 deletions dist/oocsi/DFDataset.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class DFDataset {
void println();
void println(const String &message);
void println(char message);
const char* urlencode(const char* str);
};

#endif
2 changes: 1 addition & 1 deletion dist/oocsi/library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=OOCSI
version=1.5.2
version=1.5.3
author=Jort Band, Mathias Funk
maintainer=Mathias Funk <m.funk@tue.nl>
sentence=OOCSI client library for the ESP32, ESP8266 and Arduino NANO 33 IoT
Expand Down
34 changes: 34 additions & 0 deletions src/DFDataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ bool DFDataset::logItem() {
activity_id = activity_id != NULL ? activity_id : "";
device_id = device_id != NULL ? device_id : "";

// url encode activity id string because it will be part of the URL
activity_id = urlencode(activity_id);

// do transmission
#ifdef ARDUINO_SAMD_NANO_33_IOT
// compile address
Expand Down Expand Up @@ -483,3 +486,34 @@ void DFDataset::setActivityLEDPin(int ledPin) {
void DFDataset::setLogging(bool log) {
logging = log;
}

const char* DFDataset::urlencode(const char* str)
{
String encodedString="";
char c;
char code0;
char code1;
char code2;
for (int i =0; i < strlen(str); i++){
c=str[i];
if (isalnum(c)){
encodedString+=c;
} else {
code1=(c & 0xf)+'0';
if ((c & 0xf) >9){
code1=(c & 0xf) - 10 + 'A';
}
c=(c>>4)&0xf;
code0=c+'0';
if (c > 9){
code0=c - 10 + 'A';
}
code2='\0';
encodedString+='%';
encodedString+=code0;
encodedString+=code1;
}
yield();
}
return encodedString.c_str();
}
1 change: 1 addition & 0 deletions src/DFDataset.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class DFDataset {
void println();
void println(const String &message);
void println(char message);
const char* urlencode(const char* str);
};

#endif

0 comments on commit da2c126

Please sign in to comment.