Skip to content
Snippets Groups Projects
Commit 605831db authored by Anian Bühler's avatar Anian Bühler
Browse files

added message-legnth-limit (cut Topic or Payload)

parent 0b3ad2a5
No related branches found
No related tags found
2 merge requests!3Dev to master,!2Dev to Master
......@@ -5,7 +5,6 @@
#######################################
# Datatypes (KEYWORD1)
#######################################
didacticPSNet KEYWORD1
didacticPSNetBroker KEYWORD1
didacticPSNetClient KEYWORD1
......
......@@ -150,8 +150,7 @@ int didacticPSNet::extractData(int startCounter, int maxLength, char* buffer, ch
buffer[counter-startCounter] = _readBufferMessage[counter];
counter++;
if((counter-startCounter) > maxLength){
//return -1;
Serial.print("\nextractData - Return on MAX length\n");
counter--;
break; //if > maxLenght -> leave while and return
}
}
......@@ -232,24 +231,6 @@ int didacticPSNetClient::publish(char* topic, char* payload){
for(int i = 0; i < payloadLength; i++){
_sendBufferMessage[2+topicLength+1+i] = payload[i];
}
/*
if(topicLength <= MAX_LEN_TOPICS){
for(int i = 0; i < topicLength; i++){
_sendBufferMessage[2+i] = topic[i];
}
}else { //cut topic if longer than max
_dataToSend = false;
return false;
}
if(payloadLength <= MAX_LEN_PAYLOAD){
for(int i = 0; i < payloadLength; i++){
_sendBufferMessage[2+topicLength+1+i] = payload[i];
}
}else { //cut message if longer than max
_dataToSend = false;
return false;
}
*/
_dataToSend = true;
return error;
......@@ -264,7 +245,7 @@ int didacticPSNetClient::publish(char* topic, int topicLength, char* payload , i
_sendBufferMessage[2+topicLength+1+payloadLength] = MSG_DELIMITER;
_sendBufferMessage[2+topicLength+1+payloadLength+1] = '\0';
//TODO: check
//TODO: check
if(topicLength > MAX_LEN_TOPICS){
topicLength = MAX_LEN_TOPICS;
error += DN_ERROR_TOPIC_LEN;
......@@ -280,24 +261,7 @@ int didacticPSNetClient::publish(char* topic, int topicLength, char* payload , i
for(int i = 0; i < payloadLength; i++){
_sendBufferMessage[2+topicLength+1+i] = payload[i];
}
/*
if(topicLength <= MAX_LEN_TOPICS){
for(int i = 0; i < topicLength; i++){
_sendBufferMessage[2+i] = topic[i];
}
}else { //cut topic if longer than max
_dataToSend = false;
return false;
}
if(payloadLength <= MAX_LEN_PAYLOAD){
for(int i = 0; i < payloadLength; i++){
_sendBufferMessage[2+topicLength+1+i] = payload[i];
}
}else { //cut message if longer than max
_dataToSend = false;
return false;
}
*/
_dataToSend = true;
return error;
}
......@@ -323,8 +287,6 @@ int didacticPSNetClient::subscribe(char* topic){
if(topicNumber < 0){
topicNumber = 0;
}
// if( topicLength <= MAX_LEN_TOPICS){
for(int i = 0; i < topicLength; i++){
_topic[topicNumber][i] = topic[i];
_sendBufferMessage[2+i]= topic[i];
......@@ -332,21 +294,13 @@ int didacticPSNetClient::subscribe(char* topic){
_topic[topicNumber][topicLength] = '\0';
_sendBufferMessage[2+topicLength+1]= '\0';
_dataToSend = true;
/* }
else {
_dataToSend = false;
return false;
}*/
}
else{
//if( topicLength <= MAX_LEN_TOPICS){
for(int i = 0; i < topicLength; i++){
_sendBufferMessage[2+i]= topic[i];
}
_sendBufferMessage[2+topicLength+1]= '\0';
_dataToSend = true;
//}
}
while(_dataToSend){
handleNetwork();
......@@ -373,8 +327,6 @@ int didacticPSNetClient::subscribe(char* topic, int topicLength){
if(topicNumber < 0){
topicNumber = 0;
}
// if( topicLength <= MAX_LEN_TOPICS){
for(int i = 0; i < topicLength; i++){
_topic[topicNumber][i] = topic[i];
_sendBufferMessage[2+i]= topic[i];
......@@ -382,21 +334,13 @@ int didacticPSNetClient::subscribe(char* topic, int topicLength){
_topic[topicNumber][topicLength] = '\0';
_sendBufferMessage[2+topicLength+1]= '\0';
_dataToSend = true;
/* }
else {
_dataToSend = false;
return false;
}*/
}
else{
//if( topicLength <= MAX_LEN_TOPICS){
for(int i = 0; i < topicLength; i++){
_sendBufferMessage[2+i]= topic[i];
}
_sendBufferMessage[2+topicLength+1]= '\0';
_dataToSend = true;
//}
}
while(_dataToSend){
handleNetwork();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment