716 |
} |
} |
717 |
|
|
718 |
/** |
/** |
719 |
|
* Generate the relevant LSCP documentation reference section if necessary. |
720 |
|
* The documentation section for the currently active command on the LSCP |
721 |
|
* shell's command line will be encoded in a special format, specifically for |
722 |
|
* the LSCP shell application. |
723 |
|
* |
724 |
|
* @param line - current LSCP command line |
725 |
|
* @param param - reentrant Bison parser parameters |
726 |
|
* |
727 |
|
* @return encoded reference string or empty string if nothing shall be sent |
728 |
|
* to LSCP shell (client) at this point |
729 |
|
*/ |
730 |
|
String LSCPServer::generateLSCPDocReply(const String& line, yyparse_param_t* param) { |
731 |
|
String result; |
732 |
|
lscp_ref_entry_t* ref = lscp_reference_for_command(line.c_str()); |
733 |
|
// Pointer comparison works here, since the function above always |
734 |
|
// returns the same constant pointer for the respective LSCP |
735 |
|
// command ... Only send the LSCP reference section to the client if |
736 |
|
// another LSCP reference section became relevant now: |
737 |
|
if (ref != param->pLSCPDocRef) { |
738 |
|
param->pLSCPDocRef = ref; |
739 |
|
if (ref) { // send a new LSCP doc section to client ... |
740 |
|
result += "SHD:" + ToString(LSCP_SHD_MATCH) + ":" + String(ref->name) + "\n"; |
741 |
|
result += String(ref->section) + "\n"; |
742 |
|
result += "."; // dot line marks the end of the text for client |
743 |
|
} else { // inform client that no LSCP doc section matches right now ... |
744 |
|
result = "SHD:" + ToString(LSCP_SHD_NO_MATCH); |
745 |
|
} |
746 |
|
} |
747 |
|
dmsg(4,("LSCP doc reply -> '%s'\n", result.c_str())); |
748 |
|
return result; |
749 |
|
} |
750 |
|
|
751 |
|
/** |
752 |
* Will be called to try to read the command from the socket |
* Will be called to try to read the command from the socket |
753 |
* If command is read, it will return true. Otherwise false is returned. |
* If command is read, it will return true. Otherwise false is returned. |
754 |
* In any case the received portion (complete or incomplete) is saved into bufferedCommand map. |
* In any case the received portion (complete or incomplete) is saved into bufferedCommand map. |
783 |
String s = lscpParserProcessShellInteraction(bufferedCommands[socket], &(*iter), false); |
String s = lscpParserProcessShellInteraction(bufferedCommands[socket], &(*iter), false); |
784 |
if (!s.empty() && (*iter).bShellInteract) AnswerClient(s + "\n"); |
if (!s.empty() && (*iter).bShellInteract) AnswerClient(s + "\n"); |
785 |
} |
} |
786 |
|
// if other side is LSCP shell application, send the relevant LSCP |
787 |
|
// documentation section of the current command line (if necessary) |
788 |
|
if ((*iter).bShellSendLSCPDoc && (*iter).bShellInteract) { |
789 |
|
String s = generateLSCPDocReply(bufferedCommands[socket], &(*iter)); |
790 |
|
if (!s.empty()) AnswerClient(s + "\n"); |
791 |
|
} |
792 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket)); |
793 |
bufferedCommands[socket] += "\r\n"; |
bufferedCommands[socket] += "\r\n"; |
794 |
return true; //Complete command was read |
return true; //Complete command was read |
818 |
if (!s.empty() && (*iter).bShellInteract && i == input.size() - 1) |
if (!s.empty() && (*iter).bShellInteract && i == input.size() - 1) |
819 |
AnswerClient(s + "\n"); |
AnswerClient(s + "\n"); |
820 |
} |
} |
821 |
|
// if other side is LSCP shell application, send the relevant LSCP |
822 |
|
// documentation section of the current command line (if necessary) |
823 |
|
if ((*iter).bShellSendLSCPDoc && (*iter).bShellInteract) { |
824 |
|
String s = generateLSCPDocReply(bufferedCommands[socket], &(*iter)); |
825 |
|
if (!s.empty()) AnswerClient(s + "\n"); |
826 |
|
} |
827 |
} |
} |
828 |
|
|
829 |
// handle network errors ... |
// handle network errors ... |
4092 |
else throw Exception("Not a boolean value, must either be 0 or 1"); |
else throw Exception("Not a boolean value, must either be 0 or 1"); |
4093 |
} catch (Exception e) { |
} catch (Exception e) { |
4094 |
result.Error(e); |
result.Error(e); |
4095 |
|
} |
4096 |
|
return result.Produce(); |
4097 |
|
} |
4098 |
|
|
4099 |
|
String LSCPServer::SetShellDoc(yyparse_param_t* pSession, double boolean_value) { |
4100 |
|
dmsg(2,("LSCPServer: SetShellDoc(val=%f)\n", boolean_value)); |
4101 |
|
LSCPResultSet result; |
4102 |
|
try { |
4103 |
|
if (boolean_value == 0) pSession->bShellSendLSCPDoc = false; |
4104 |
|
else if (boolean_value == 1) pSession->bShellSendLSCPDoc = true; |
4105 |
|
else throw Exception("Not a boolean value, must either be 0 or 1"); |
4106 |
|
} catch (Exception e) { |
4107 |
|
result.Error(e); |
4108 |
} |
} |
4109 |
return result.Produce(); |
return result.Produce(); |
4110 |
} |
} |