/[svn]/linuxsampler/trunk/src/network/lscpserver.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/network/lscpserver.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1353 by iliev, Mon Sep 17 23:15:25 2007 UTC revision 1399 by schoenebeck, Thu Oct 11 18:53:29 2007 UTC
# Line 36  Line 36 
36  #include "../drivers/audio/AudioOutputDeviceFactory.h"  #include "../drivers/audio/AudioOutputDeviceFactory.h"
37  #include "../drivers/midi/MidiInputDeviceFactory.h"  #include "../drivers/midi/MidiInputDeviceFactory.h"
38    
39    
40    /**
41     * Returns a copy of the given string where all special characters are
42     * replaced by LSCP escape sequences ("\xHH"). This function shall be used
43     * to escape LSCP response fields in case the respective response field is
44     * actually defined as using escape sequences in the LSCP specs.
45     *
46     * @e Caution: DO NOT use this function for escaping path based responses,
47     * use the Path class (src/common/Path.h) for this instead!
48     */
49    static String _escapeLscpResponse(String txt) {
50        for (int i = 0; i < txt.length(); i++) {
51            const char c = txt.c_str()[i];
52            if (
53                !(c >= '0' && c <= '9') &&
54                !(c >= 'a' && c <= 'z') &&
55                !(c >= 'A' && c <= 'Z') &&
56                !(c == ' ') && !(c == '!') && !(c == '#') && !(c == '$') &&
57                !(c == '%') && !(c == '&') && !(c == '(') && !(c == ')') &&
58                !(c == '*') && !(c == '+') && !(c == ',') && !(c == '-') &&
59                !(c == '.') && !(c == '/') && !(c == ':') && !(c == ';') &&
60                !(c == '<') && !(c == '=') && !(c == '>') && !(c == '?') &&
61                !(c == '@') && !(c == '[') && !(c == '\\') && !(c == ']') &&
62                !(c == '^') && !(c == '_') && !(c == '`') && !(c == '{') &&
63                !(c == '|') && !(c == '}') && !(c == '~')
64            ) {
65                // convert the "special" character into a "\xHH" LSCP escape sequence
66                char buf[5];
67                snprintf(buf, sizeof(buf), "\\x%02x", static_cast<unsigned char>(c));
68                txt.replace(i, 1, buf);
69                i += 3;
70            }
71        }
72        return txt;
73    }
74    
75  /**  /**
76   * Below are a few static members of the LSCPServer class.   * Below are a few static members of the LSCPServer class.
77   * The big assumption here is that LSCPServer is going to remain a singleton.   * The big assumption here is that LSCPServer is going to remain a singleton.
# Line 768  String LSCPServer::GetEngineInfo(String Line 804  String LSCPServer::GetEngineInfo(String
804      LockRTNotify();      LockRTNotify();
805      try {      try {
806          Engine* pEngine = EngineFactory::Create(EngineName);          Engine* pEngine = EngineFactory::Create(EngineName);
807          result.Add("DESCRIPTION", pEngine->Description());          result.Add("DESCRIPTION", _escapeLscpResponse(pEngine->Description()));
808          result.Add("VERSION",     pEngine->Version());          result.Add("VERSION",     pEngine->Version());
809          EngineFactory::Destroy(pEngine);          EngineFactory::Destroy(pEngine);
810      }      }
# Line 841  String LSCPServer::GetChannelInfo(uint u Line 877  String LSCPServer::GetChannelInfo(uint u
877          if (pSamplerChannel->GetMidiInputChannel() == midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL");          if (pSamplerChannel->GetMidiInputChannel() == midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL");
878          else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());          else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());
879    
880          result.Add("INSTRUMENT_FILE", InstrumentFileName);          result.Add("INSTRUMENT_FILE",
881                       (InstrumentFileName != "NONE" && InstrumentFileName != "") ?
882                            Path::fromPosix(InstrumentFileName).toLscp() : // TODO: assuming POSIX
883                            InstrumentFileName
884            );
885          result.Add("INSTRUMENT_NR", InstrumentIndex);          result.Add("INSTRUMENT_NR", InstrumentIndex);
886          result.Add("INSTRUMENT_NAME", InstrumentName);          result.Add("INSTRUMENT_NAME", _escapeLscpResponse(InstrumentName));
887          result.Add("INSTRUMENT_STATUS", InstrumentStatus);          result.Add("INSTRUMENT_STATUS", InstrumentStatus);
888          result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false"));          result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false"));
889          result.Add("SOLO", Solo);          result.Add("SOLO", Solo);
# Line 1785  String LSCPServer::GetMidiInstrumentMapp Line 1825  String LSCPServer::GetMidiInstrumentMapp
1825          std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.find(idx);          std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.find(idx);
1826          if (iter == mappings.end()) result.Error("there is no map entry with that index");          if (iter == mappings.end()) result.Error("there is no map entry with that index");
1827          else { // found          else { // found
1828              result.Add("NAME", iter->second.Name);              result.Add("NAME", _escapeLscpResponse(iter->second.Name));
1829              result.Add("ENGINE_NAME", iter->second.EngineName);              result.Add("ENGINE_NAME", iter->second.EngineName);
1830              result.Add("INSTRUMENT_FILE", iter->second.InstrumentFile);              result.Add("INSTRUMENT_FILE", Path::fromPosix(iter->second.InstrumentFile).toLscp()); //TODO: assuming POSIX
1831              result.Add("INSTRUMENT_NR", (int) iter->second.InstrumentIndex);              result.Add("INSTRUMENT_NR", (int) iter->second.InstrumentIndex);
1832              String instrumentName;              String instrumentName;
1833              Engine* pEngine = EngineFactory::Create(iter->second.EngineName);              Engine* pEngine = EngineFactory::Create(iter->second.EngineName);
# Line 1800  String LSCPServer::GetMidiInstrumentMapp Line 1840  String LSCPServer::GetMidiInstrumentMapp
1840                  }                  }
1841                  EngineFactory::Destroy(pEngine);                  EngineFactory::Destroy(pEngine);
1842              }              }
1843              result.Add("INSTRUMENT_NAME", instrumentName);              result.Add("INSTRUMENT_NAME", _escapeLscpResponse(instrumentName));
1844              switch (iter->second.LoadMode) {              switch (iter->second.LoadMode) {
1845                  case MidiInstrumentMapper::ON_DEMAND:                  case MidiInstrumentMapper::ON_DEMAND:
1846                      result.Add("LOAD_MODE", "ON_DEMAND");                      result.Add("LOAD_MODE", "ON_DEMAND");
# Line 1955  String LSCPServer::GetMidiInstrumentMap( Line 1995  String LSCPServer::GetMidiInstrumentMap(
1995      dmsg(2,("LSCPServer: GetMidiInstrumentMap()\n"));      dmsg(2,("LSCPServer: GetMidiInstrumentMap()\n"));
1996      LSCPResultSet result;      LSCPResultSet result;
1997      try {      try {
1998          result.Add("NAME", MidiInstrumentMapper::MapName(MidiMapID));          result.Add("NAME", _escapeLscpResponse(MidiInstrumentMapper::MapName(MidiMapID)));
1999          result.Add("DEFAULT", MidiInstrumentMapper::GetDefaultMap() == MidiMapID);          result.Add("DEFAULT", MidiInstrumentMapper::GetDefaultMap() == MidiMapID);
2000      } catch (Exception e) {      } catch (Exception e) {
2001          result.Error(e);          result.Error(e);
# Line 2099  String LSCPServer::GetFxSendInfo(uint ui Line 2139  String LSCPServer::GetFxSendInfo(uint ui
2139          }          }
2140    
2141          // success          // success
2142          result.Add("NAME", pFxSend->Name());          result.Add("NAME", _escapeLscpResponse(pFxSend->Name()));
2143          result.Add("MIDI_CONTROLLER", pFxSend->MidiController());          result.Add("MIDI_CONTROLLER", pFxSend->MidiController());
2144          result.Add("LEVEL", ToString(pFxSend->Level()));          result.Add("LEVEL", ToString(pFxSend->Level()));
2145          result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting);          result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting);
# Line 2222  String LSCPServer::ResetSampler() { Line 2262  String LSCPServer::ResetSampler() {
2262   */   */
2263  String LSCPServer::GetServerInfo() {  String LSCPServer::GetServerInfo() {
2264      dmsg(2,("LSCPServer: GetServerInfo()\n"));      dmsg(2,("LSCPServer: GetServerInfo()\n"));
2265        const std::string description =
2266            _escapeLscpResponse("LinuxSampler - modular, streaming capable sampler");
2267      LSCPResultSet result;      LSCPResultSet result;
2268      result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler");      result.Add("DESCRIPTION", description);
2269      result.Add("VERSION", VERSION);      result.Add("VERSION", VERSION);
2270      result.Add("PROTOCOL_VERSION", ToString(LSCP_RELEASE_MAJOR) + "." + ToString(LSCP_RELEASE_MINOR));      result.Add("PROTOCOL_VERSION", ToString(LSCP_RELEASE_MAJOR) + "." + ToString(LSCP_RELEASE_MINOR));
2271  #if HAVE_SQLITE3  #if HAVE_SQLITE3

Legend:
Removed from v.1353  
changed lines
  Added in v.1399

  ViewVC Help
Powered by ViewVC