/[svn]/liblscp/trunk/src/client.c
ViewVC logotype

Diff of /liblscp/trunk/src/client.c

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

revision 114 by capela, Mon Jun 7 21:40:23 2004 UTC revision 623 by capela, Thu Jun 9 10:37:19 2005 UTC
# Line 2  Line 2 
2  //  //
3  /****************************************************************************  /****************************************************************************
4     liblscp - LinuxSampler Control Protocol API     liblscp - LinuxSampler Control Protocol API
5     Copyright (C) 2004, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2005, rncbc aka Rui Nuno Capela. All rights reserved.
6    
7     This library is free software; you can redistribute it and/or     This library is free software; you can redistribute it and/or
8     modify it under the terms of the GNU Lesser General Public     modify it under the terms of the GNU Lesser General Public
# Line 14  Line 14 
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15     Lesser General Public License for more details.     Lesser General Public License for more details.
16    
17     You should have received a copy of the GNU Lesser General Public     You should 14have received a copy of the GNU Lesser General Public
18     License along with this library; if not, write to the Free Software     License along with this library; if not, write to the Free Software
19     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20    
# Line 28  Line 28 
28    
29  // Local prototypes.  // Local prototypes.
30    
31  static void _lscp_client_set_result (lscp_client_t *pClient, char *pszResult, int iErrno);  static void             _lscp_client_evt_proc       (void *pvClient);
 static void _lscp_client_udp_proc   (void *pvClient);  
32    
33    static lscp_status_t    _lscp_client_evt_connect    (lscp_client_t *pClient);
34  //-------------------------------------------------------------------------  static lscp_status_t    _lscp_client_evt_request    (lscp_client_t *pClient, int iSubscribe, lscp_event_t event);
 // Helper functions.  
   
 // Result buffer internal settler.  
 static void _lscp_client_set_result ( lscp_client_t *pClient, char *pszResult, int iErrno )  
 {  
     if (pClient->pszResult)  
         free(pClient->pszResult);  
     pClient->pszResult = NULL;  
   
     pClient->iErrno = iErrno;  
   
     if (pszResult)  
         pClient->pszResult = strdup(lscp_ltrim(pszResult));  
 }  
35    
36    
37  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
38  // UDP service (datagram oriented).  // Event service (datagram oriented).
39    
40  static void _lscp_client_udp_proc ( void *pvClient )  static void _lscp_client_evt_proc ( void *pvClient )
41  {  {
42      lscp_client_t *pClient = (lscp_client_t *) pvClient;      lscp_client_t *pClient = (lscp_client_t *) pvClient;
     struct sockaddr_in addr;  
     int   cAddr;  
     char  achBuffer[LSCP_BUFSIZ];  
     int   cchBuffer;  
     const char *pszSeps = " \r\n";  
     char *pszToken;  
     char *pch;  
43    
44  #ifdef DEBUG      fd_set fds;                         // File descriptor list for select().
45      fprintf(stderr, "_lscp_client_udp_proc: Client waiting for events.\n");      int    fd, fdmax;                   // Maximum file descriptor number.
46  #endif      struct timeval tv;                  // For specifying a timeout value.
47        int    iSelect;                     // Holds select return status.
48        int    iTimeout;
49    
50        char   achBuffer[LSCP_BUFSIZ];
51        int    cchBuffer;
52        const char *pszSeps = ":\r\n";
53        char * pszToken;
54        char * pch;
55        int     cchToken;
56        lscp_event_t event;
57    
     while (pClient->udp.iState) {  
         cAddr = sizeof(struct sockaddr_in);  
         cchBuffer = recvfrom(pClient->udp.sock, achBuffer, sizeof(achBuffer), 0, (struct sockaddr *) &addr, &cAddr);  
         if (cchBuffer > 0) {  
58  #ifdef DEBUG  #ifdef DEBUG
59              lscp_socket_trace("_lscp_client_udp_proc: recvfrom", &addr, achBuffer, cchBuffer);      fprintf(stderr, "_lscp_client_evt_proc: Client waiting for events.\n");
60  #endif  #endif
61              if (strncasecmp(achBuffer, "PING ", 5) == 0) {  
62        while (pClient->evt.iState) {
63    
64            // Prepare for waiting on select...
65            fd = (int) pClient->evt.sock;
66            FD_ZERO(&fds);
67            FD_SET((unsigned int) fd, &fds);
68            fdmax = fd;
69    
70            // Use the timeout (x10) select feature ...
71            iTimeout = 10 * pClient->iTimeout;
72            if (iTimeout > 1000) {
73                tv.tv_sec = iTimeout / 1000;
74                iTimeout -= tv.tv_sec * 1000;
75            }
76            else tv.tv_sec = 0;
77            tv.tv_usec = iTimeout * 1000;
78    
79            // Wait for event...
80            iSelect = select(fdmax + 1, &fds, NULL, NULL, &tv);
81            if (iSelect > 0 && FD_ISSET(fd, &fds)) {
82                // May recv now...
83                cchBuffer = recv(pClient->evt.sock, achBuffer, sizeof(achBuffer), 0);
84                if (cchBuffer > 0) {
85                  // Make sure received buffer it's null terminated.                  // Make sure received buffer it's null terminated.
86                  achBuffer[cchBuffer] = (char) 0;                  achBuffer[cchBuffer] = (char) 0;
87                  lscp_strtok(achBuffer, pszSeps, &(pch));       // Skip "PING"                  // Parse for the notification event message...
88                  lscp_strtok(NULL, pszSeps, &(pch));            // Skip port (must be the same as in addr)                  pszToken = lscp_strtok(achBuffer, pszSeps, &(pch)); // Have "NOTIFY".
89                  pszToken = lscp_strtok(NULL, pszSeps, &(pch)); // Have session-id.                  if (strcasecmp(pszToken, "NOTIFY") == 0) {
90                  if (pszToken) {                      pszToken = lscp_strtok(NULL, pszSeps, &(pch));
91                      // Set now client's session-id, if not already                      event    = lscp_event_from_text(pszToken);
92                      if (pClient->sessid == NULL)                      // And pick the rest of data...
93                          pClient->sessid = strdup(pszToken);                      pszToken = lscp_strtok(NULL, pszSeps, &(pch));
94                      if (pClient->sessid && strcmp(pszToken, pClient->sessid) == 0) {                      cchToken = (pszToken == NULL ? 0 : strlen(pszToken));
95                          sprintf(achBuffer, "PONG %s\r\n", pClient->sessid);                      // Double-check if we're really up to it...
96                          cchBuffer = strlen(achBuffer);                      if (pClient->events & event) {
97                          if (sendto(pClient->udp.sock, achBuffer, cchBuffer, 0, (struct sockaddr *) &addr, cAddr) < cchBuffer)                          // Invoke the client event callback...
98                              lscp_socket_perror("_lscp_client_udp_proc: sendto");                          if ((*pClient->pfnCallback)(
99  #ifdef DEBUG                                  pClient,
100                          fprintf(stderr, "> %s", achBuffer);                                  event,
101  #endif                                  pszToken,
102                                    cchToken,
103                                    pClient->pvData) != LSCP_OK) {
104                                pClient->evt.iState = 0;
105                            }
106                      }                      }
107                  }                  }
                 // Done with life proof.  
108              } else {              } else {
109                  //                  lscp_socket_perror("_lscp_client_evt_proc: recv");
110                  if ((*pClient->pfnCallback)(                  pClient->evt.iState = 0;
                         pClient,  
                         achBuffer,  
                         cchBuffer,  
                         pClient->pvData) != LSCP_OK) {  
                     pClient->udp.iState = 0;  
                 }  
111              }              }
112          } else {          }   // Check if select has in error.
113              lscp_socket_perror("_lscp_client_udp_proc: recvfrom");          else if (iSelect < 0) {
114              pClient->udp.iState = 0;              lscp_socket_perror("_lscp_client_evt_proc: select");
115                pClient->evt.iState = 0;
116          }          }
117    
118            // Finally, always signal the event.
119            lscp_cond_signal(pClient->cond);
120      }      }
121    
122  #ifdef DEBUG  #ifdef DEBUG
123      fprintf(stderr, "_lscp_client_udp_proc: Client closing.\n");      fprintf(stderr, "_lscp_client_evt_proc: Client closing.\n");
124  #endif  #endif
125  }  }
126    
127    
128  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
129    // Event subscription helpers.
130    
131    // Open the event service socket connection.
132    static lscp_status_t _lscp_client_evt_connect ( lscp_client_t *pClient )
133    {
134        lscp_socket_t sock;
135        struct sockaddr_in addr;
136        int cAddr;
137    #if defined(WIN32)
138        int iSockOpt = (-1);
139    #endif
140    
141        // Prepare the event connection socket...
142        sock = socket(AF_INET, SOCK_STREAM, 0);
143        if (sock == INVALID_SOCKET) {
144            lscp_socket_perror("_lscp_client_evt_connect: socket");
145            return LSCP_FAILED;
146        }
147    
148    #if defined(WIN32)
149        if (setsockopt(sock, SOL_SOCKET, SO_DONTLINGER, (char *) &iSockOpt, sizeof(int)) == SOCKET_ERROR)
150            lscp_socket_perror("lscp_client_evt_connect: setsockopt(SO_DONTLINGER)");
151    #endif
152    
153    #ifdef DEBUG
154        lscp_socket_getopts("_lscp_client_evt_connect:", sock);
155    #endif
156    
157        // Use same address of the command connection.
158        cAddr = sizeof(struct sockaddr_in);
159        memmove((char *) &addr, &(pClient->cmd.addr), cAddr);
160    
161        // Start the connection...
162        if (connect(sock, (struct sockaddr *) &addr, cAddr) == SOCKET_ERROR) {
163            lscp_socket_perror("_lscp_client_evt_connect: connect");
164            closesocket(sock);
165            return LSCP_FAILED;
166        }
167    
168        // Set our socket agent struct...
169        lscp_socket_agent_init(&(pClient->evt), sock, &addr, cAddr);
170    
171        // And finally the service thread...
172        return lscp_socket_agent_start(&(pClient->evt), _lscp_client_evt_proc, pClient, 0);
173    }
174    
175    
176    // Subscribe to a single event.
177    static lscp_status_t _lscp_client_evt_request ( lscp_client_t *pClient, int iSubscribe, lscp_event_t event )
178    {
179        const char *pszEvent;
180        char  szQuery[LSCP_BUFSIZ];
181        int   cchQuery;
182    
183        if (pClient == NULL)
184            return LSCP_FAILED;
185    
186        // Which (single) event?
187        pszEvent = lscp_event_to_text(event);
188        if (pszEvent == NULL)
189            return LSCP_FAILED;
190    
191        // Build the query string...
192        cchQuery = sprintf(szQuery, "%sSUBSCRIBE %s\n\n", (iSubscribe == 0 ? "UN" : ""), pszEvent);
193        // Just send data, forget result...
194        if (send(pClient->evt.sock, szQuery, cchQuery, 0) < cchQuery) {
195            lscp_socket_perror("_lscp_client_evt_request: send");
196            return LSCP_FAILED;
197        }
198    
199        // Wait on response.
200        lscp_cond_wait(pClient->cond, pClient->mutex);
201    
202        // Update as naively as we can...
203        if (iSubscribe)
204            pClient->events |=  event;
205        else
206            pClient->events &= ~event;
207    
208        return LSCP_OK;
209    }
210    
211    
212    //-------------------------------------------------------------------------
213  // Client versioning teller fuunction.  // Client versioning teller fuunction.
214    
215    
# Line 155  lscp_client_t* lscp_client_create ( cons Line 247  lscp_client_t* lscp_client_create ( cons
247      lscp_socket_t sock;      lscp_socket_t sock;
248      struct sockaddr_in addr;      struct sockaddr_in addr;
249      int cAddr;      int cAddr;
250    #if defined(WIN32)
251      int iSockOpt = (-1);      int iSockOpt = (-1);
252    #endif
253    
254      if (pfnCallback == NULL) {      if (pfnCallback == NULL) {
255          fprintf(stderr, "lscp_client_create: Invalid client callback function.\n");          fprintf(stderr, "lscp_client_create: Invalid client callback function.\n");
# Line 184  lscp_client_t* lscp_client_create ( cons Line 278  lscp_client_t* lscp_client_create ( cons
278      fprintf(stderr, "lscp_client_create: pClient=%p: pszHost=%s iPort=%d.\n", pClient, pszHost, iPort);      fprintf(stderr, "lscp_client_create: pClient=%p: pszHost=%s iPort=%d.\n", pClient, pszHost, iPort);
279  #endif  #endif
280    
281      // Prepare the TCP connection socket...      // Prepare the command connection socket...
282    
283      sock = socket(AF_INET, SOCK_STREAM, 0);      sock = socket(AF_INET, SOCK_STREAM, 0);
284      if (sock == INVALID_SOCKET) {      if (sock == INVALID_SOCKET) {
285          lscp_socket_perror("lscp_client_create: tcp: socket");          lscp_socket_perror("lscp_client_create: cmd: socket");
286          free(pClient);          free(pClient);
287          return NULL;          return NULL;
288      }      }
289    
290  #if defined(WIN32)  #if defined(WIN32)
291      if (setsockopt(sock, SOL_SOCKET, SO_DONTLINGER, (char *) &iSockOpt, sizeof(int)) == SOCKET_ERROR)      if (setsockopt(sock, SOL_SOCKET, SO_DONTLINGER, (char *) &iSockOpt, sizeof(int)) == SOCKET_ERROR)
292          lscp_socket_perror("lscp_client_create: tcp: setsockopt(SO_DONTLINGER)");          lscp_socket_perror("lscp_client_create: cmd: setsockopt(SO_DONTLINGER)");
293  #endif  #endif
294    
295  #ifdef DEBUG  #ifdef DEBUG
296      lscp_socket_getopts("lscp_client_create: tcp", sock);      lscp_socket_getopts("lscp_client_create: cmd", sock);
297  #endif  #endif
298    
299      cAddr = sizeof(struct sockaddr_in);      cAddr = sizeof(struct sockaddr_in);
# Line 209  lscp_client_t* lscp_client_create ( cons Line 303  lscp_client_t* lscp_client_create ( cons
303      addr.sin_port = htons((short) iPort);      addr.sin_port = htons((short) iPort);
304    
305      if (connect(sock, (struct sockaddr *) &addr, cAddr) == SOCKET_ERROR) {      if (connect(sock, (struct sockaddr *) &addr, cAddr) == SOCKET_ERROR) {
306          lscp_socket_perror("lscp_client_create: tcp: connect");          lscp_socket_perror("lscp_client_create: cmd: connect");
307          closesocket(sock);          closesocket(sock);
308          free(pClient);          free(pClient);
309          return NULL;          return NULL;
310      }      }
311    
312      lscp_socket_agent_init(&(pClient->tcp), sock, &addr, cAddr);      // Initialize the command socket agent struct...
313        lscp_socket_agent_init(&(pClient->cmd), sock, &addr, cAddr);
314    
315  #ifdef DEBUG  #ifdef DEBUG
316      fprintf(stderr, "lscp_client_create: tcp: pClient=%p: sock=%d addr=%s port=%d.\n", pClient, pClient->tcp.sock, inet_ntoa(pClient->tcp.addr.sin_addr), ntohs(pClient->tcp.addr.sin_port));      fprintf(stderr, "lscp_client_create: cmd: pClient=%p: sock=%d addr=%s port=%d.\n", pClient, pClient->cmd.sock, inet_ntoa(pClient->cmd.addr.sin_addr), ntohs(pClient->cmd.addr.sin_port));
317  #endif  #endif
318    
319      // Prepare the UDP datagram service socket...      // Initialize the event service socket struct...
320        lscp_socket_agent_init(&(pClient->evt), INVALID_SOCKET, NULL, 0);
321      sock = socket(AF_INET, SOCK_DGRAM, 0);      // No events subscribed, yet.
322      if (sock == INVALID_SOCKET) {      pClient->events = LSCP_EVENT_NONE;
         lscp_socket_perror("lscp_client_create: udp: socket");  
         lscp_socket_agent_free(&(pClient->tcp));  
         free(pClient);  
         return NULL;  
     }  
   
     if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &iSockOpt, sizeof(int)) == SOCKET_ERROR)  
         lscp_socket_perror("lscp_client_create: udp: setsockopt(SO_REUSEADDR)");  
   
 #ifdef DEBUG  
     lscp_socket_getopts("lscp_client_create: udp", sock);  
 #endif  
   
     cAddr = sizeof(struct sockaddr_in);  
     memset((char *) &addr, 0, cAddr);  
     addr.sin_family = AF_INET;  
     addr.sin_addr.s_addr = htonl(INADDR_ANY);  
     addr.sin_port = htons(0);  
   
     if (bind(sock, (const struct sockaddr *) &addr, cAddr) == SOCKET_ERROR) {  
         lscp_socket_perror("lscp_client_create: udp: bind");  
         lscp_socket_agent_free(&(pClient->tcp));  
         closesocket(sock);  
         free(pClient);  
         return NULL;  
     }  
   
     if (getsockname(sock, (struct sockaddr *) &addr, &cAddr) == SOCKET_ERROR) {  
         lscp_socket_perror("lscp_client_create: udp: getsockname");  
         lscp_socket_agent_free(&(pClient->tcp));  
         closesocket(sock);  
         free(pClient);  
         return NULL;  
     }  
   
     lscp_socket_agent_init(&(pClient->udp), sock, &addr, cAddr);  
   
 #ifdef DEBUG  
     fprintf(stderr, "lscp_client_create: udp: pClient=%p: sock=%d addr=%s port=%d.\n", pClient, pClient->udp.sock, inet_ntoa(pClient->udp.addr.sin_addr), ntohs(pClient->udp.addr.sin_port));  
 #endif  
   
     // No session id, yet.  
     pClient->sessid = NULL;  
323      // Initialize cached members.      // Initialize cached members.
324      pClient->audio_drivers = NULL;      pClient->audio_drivers = NULL;
325      pClient->midi_drivers = NULL;      pClient->midi_drivers = NULL;
326        pClient->audio_devices = NULL;
327        pClient->midi_devices = NULL;
328      pClient->engines = NULL;      pClient->engines = NULL;
329      lscp_driver_info_init(&(pClient->audio_info));      pClient->channels = NULL;
330      lscp_driver_info_init(&(pClient->midi_info));      lscp_driver_info_init(&(pClient->audio_driver_info));
331        lscp_driver_info_init(&(pClient->midi_driver_info));
332        lscp_device_info_init(&(pClient->audio_device_info));
333        lscp_device_info_init(&(pClient->midi_device_info));
334        lscp_param_info_init(&(pClient->audio_param_info));
335        lscp_param_info_init(&(pClient->midi_param_info));
336        lscp_device_port_info_init(&(pClient->audio_channel_info));
337        lscp_device_port_info_init(&(pClient->midi_port_info));
338        lscp_param_info_init(&(pClient->audio_channel_param_info));
339        lscp_param_info_init(&(pClient->midi_port_param_info));
340        lscp_server_info_init(&(pClient->server_info));
341      lscp_engine_info_init(&(pClient->engine_info));      lscp_engine_info_init(&(pClient->engine_info));
342      lscp_channel_info_init(&(pClient->channel_info));      lscp_channel_info_init(&(pClient->channel_info));
343      // Initialize error stuff.      // Initialize error stuff.
# Line 284  lscp_client_t* lscp_client_create ( cons Line 348  lscp_client_t* lscp_client_create ( cons
348      pClient->iStreamCount = 0;      pClient->iStreamCount = 0;
349      // Default timeout value.      // Default timeout value.
350      pClient->iTimeout = LSCP_TIMEOUT_MSECS;      pClient->iTimeout = LSCP_TIMEOUT_MSECS;
351        pClient->iTimeoutCount = 0;
352    
353      // Initialize the transaction mutex.      // Initialize the transaction mutex.
354      lscp_mutex_init(pClient->mutex);      lscp_mutex_init(pClient->mutex);
355        lscp_cond_init(pClient->cond);
     // Now's finally time to startup threads...  
     // UDP service thread...  
     if (lscp_socket_agent_start(&(pClient->udp), _lscp_client_udp_proc, pClient, 0) != LSCP_OK) {  
         lscp_socket_agent_free(&(pClient->tcp));  
         lscp_socket_agent_free(&(pClient->udp));  
         lscp_mutex_destroy(pClient->mutex);  
         free(pClient);  
         return NULL;  
     }  
356    
357      // Finally we've some success...      // Finally we've some success...
358      return pClient;      return pClient;
# Line 317  lscp_status_t lscp_client_join ( lscp_cl Line 373  lscp_status_t lscp_client_join ( lscp_cl
373      fprintf(stderr, "lscp_client_join: pClient=%p.\n", pClient);      fprintf(stderr, "lscp_client_join: pClient=%p.\n", pClient);
374  #endif  #endif
375    
376  //  lscp_socket_agent_join(&(pClient->udp));  //  lscp_socket_agent_join(&(pClient->evt));
377      lscp_socket_agent_join(&(pClient->tcp));      lscp_socket_agent_join(&(pClient->cmd));
378    
379      return LSCP_OK;      return LSCP_OK;
380  }  }
# Line 340  lscp_status_t lscp_client_destroy ( lscp Line 396  lscp_status_t lscp_client_destroy ( lscp
396      fprintf(stderr, "lscp_client_destroy: pClient=%p.\n", pClient);      fprintf(stderr, "lscp_client_destroy: pClient=%p.\n", pClient);
397  #endif  #endif
398    
399      // Free session-id, if any.      // Lock this section up.
400      if (pClient->sessid)      lscp_mutex_lock(pClient->mutex);
401          free(pClient->sessid);  
     pClient->sessid = NULL;  
402      // Free up all cached members.      // Free up all cached members.
403      lscp_channel_info_reset(&(pClient->channel_info));      lscp_channel_info_free(&(pClient->channel_info));
404      lscp_engine_info_reset(&(pClient->engine_info));      lscp_engine_info_free(&(pClient->engine_info));
405      lscp_driver_info_reset(&(pClient->midi_info));      lscp_server_info_free(&(pClient->server_info));
406      lscp_driver_info_reset(&(pClient->audio_info));      lscp_param_info_free(&(pClient->midi_port_param_info));
407        lscp_param_info_free(&(pClient->audio_channel_param_info));
408        lscp_device_port_info_free(&(pClient->midi_port_info));
409        lscp_device_port_info_free(&(pClient->audio_channel_info));
410        lscp_param_info_free(&(pClient->midi_param_info));
411        lscp_param_info_free(&(pClient->audio_param_info));
412        lscp_device_info_free(&(pClient->midi_device_info));
413        lscp_device_info_free(&(pClient->audio_device_info));
414        lscp_driver_info_free(&(pClient->midi_driver_info));
415        lscp_driver_info_free(&(pClient->audio_driver_info));
416      // Free available engine table.      // Free available engine table.
417      lscp_szsplit_destroy(pClient->audio_drivers);      lscp_szsplit_destroy(pClient->audio_drivers);
418      lscp_szsplit_destroy(pClient->midi_drivers);      lscp_szsplit_destroy(pClient->midi_drivers);
419        lscp_isplit_destroy(pClient->audio_devices);
420        lscp_isplit_destroy(pClient->midi_devices);
421      lscp_szsplit_destroy(pClient->engines);      lscp_szsplit_destroy(pClient->engines);
422        lscp_isplit_destroy(pClient->channels);
423      // Make them null.      // Make them null.
424      pClient->audio_drivers = NULL;      pClient->audio_drivers = NULL;
425      pClient->midi_drivers = NULL;      pClient->midi_drivers = NULL;
426      pClient->engines = NULL;      pClient->engines = NULL;
427      // Free result error stuff.      // Free result error stuff.
428      _lscp_client_set_result(pClient, NULL, 0);      lscp_client_set_result(pClient, NULL, 0);
429      // Frre stream usage stuff.      // Free stream usage stuff.
430      if (pClient->buffer_fill)      if (pClient->buffer_fill)
431          free(pClient->buffer_fill);          free(pClient->buffer_fill);
432      pClient->buffer_fill = NULL;      pClient->buffer_fill = NULL;
# Line 367  lscp_status_t lscp_client_destroy ( lscp Line 434  lscp_status_t lscp_client_destroy ( lscp
434      pClient->iTimeout = 0;      pClient->iTimeout = 0;
435    
436      // Free socket agents.      // Free socket agents.
437      lscp_socket_agent_free(&(pClient->udp));      lscp_socket_agent_free(&(pClient->evt));
438      lscp_socket_agent_free(&(pClient->tcp));      lscp_socket_agent_free(&(pClient->cmd));
439    
440      // Last but not least, free good ol'transaction mutex.      // Last but not least, free good ol'transaction mutex.
441        lscp_mutex_unlock(pClient->mutex);
442      lscp_mutex_destroy(pClient->mutex);      lscp_mutex_destroy(pClient->mutex);
443        lscp_cond_destroy(pClient->cond);
444    
445      free(pClient);      free(pClient);
446    
# Line 418  int lscp_client_get_timeout ( lscp_clien Line 487  int lscp_client_get_timeout ( lscp_clien
487  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
488  // Client common protocol functions.  // Client common protocol functions.
489    
   
490  /**  /**
491   *  Submit a command query line string to the server. The query string   *  Submit a command query line string to the server. The query string
492   *  must be cr/lf and null terminated. Besides the return code, the   *  must be cr/lf and null terminated. Besides the return code, the
# Line 434  int lscp_client_get_timeout ( lscp_clien Line 502  int lscp_client_get_timeout ( lscp_clien
502   */   */
503  lscp_status_t lscp_client_query ( lscp_client_t *pClient, const char *pszQuery )  lscp_status_t lscp_client_query ( lscp_client_t *pClient, const char *pszQuery )
504  {  {
505      fd_set fds;                         // File descriptor list for select().      lscp_status_t ret;
     int    fd, fdmax;                   // Maximum file descriptor number.  
     struct timeval tv;                  // For specifying a timeout value.  
     int    iSelect;                     // Holds select return status.  
     int    iTimeout;  
     int    cchQuery;  
     char   achResult[LSCP_BUFSIZ];  
     int    cchResult;  
     const  char *pszSeps = ":[]";  
     char  *pszResult;  
     char  *pszToken;  
     char  *pch;  
     int    iErrno;  
   
     lscp_status_t ret = LSCP_FAILED;  
   
     if (pClient == NULL)  
         return ret;  
506    
507      // Lock this section up.      // Lock this section up.
508      lscp_mutex_lock(pClient->mutex);      lscp_mutex_lock(pClient->mutex);
509    
510      pszResult = NULL;      // Just make the now guarded call.
511      iErrno = -1;      ret = lscp_client_call(pClient, pszQuery);
512    
513      // Send data, and then, wait for the result...      // Unlock this section down.
     cchQuery = strlen(pszQuery);  
     if (send(pClient->tcp.sock, pszQuery, cchQuery, 0) < cchQuery) {  
         lscp_socket_perror("lscp_client_query: send");  
         lscp_mutex_unlock(pClient->mutex);  
         return ret;  
     }  
   
     // Prepare for waiting on select...  
     fd = (int) pClient->tcp.sock;  
     FD_ZERO(&fds);  
     FD_SET((unsigned int) fd, &fds);  
     fdmax = fd;  
   
     // Use the timeout select feature...  
     iTimeout = pClient->iTimeout;  
     if (iTimeout > 1000) {  
         tv.tv_sec = iTimeout / 1000;  
         iTimeout -= tv.tv_sec * 1000;  
     }  
     else tv.tv_sec = 0;  
     tv.tv_usec = iTimeout * 1000;  
   
     // Wait for event...  
     iSelect = select(fdmax + 1, &fds, NULL, NULL, &tv);  
     if (iSelect > 0 && FD_ISSET(fd, &fds)) {  
         // May recv now...  
         cchResult = recv(pClient->tcp.sock, achResult, sizeof(achResult), 0);  
         if (cchResult > 0) {  
             // Assume early success.  
             ret = LSCP_OK;  
             // Always force the result to be null terminated (and trim trailing CRLFs)!  
             while (cchResult > 0 && (achResult[cchResult - 1] == '\n' || achResult[cchResult- 1] == '\r'))  
                 cchResult--;  
             achResult[cchResult] = (char) 0;  
             // Check if the response it's an error or warning message.  
             if (strncasecmp(achResult, "WRN:", 4) == 0)  
                 ret = LSCP_WARNING;  
             else if (strncasecmp(achResult, "ERR:", 4) == 0)  
                 ret = LSCP_ERROR;  
             // So we got a result...  
             if (ret == LSCP_OK) {  
                 // Reset errno in case of success.  
                 iErrno = 0;  
                 // Is it a special successful response?  
                 if (strncasecmp(achResult, "OK[", 3) == 0) {  
                     // Parse the OK message, get the return string under brackets...  
                     pszToken = lscp_strtok(achResult, pszSeps, &(pch));  
                     if (pszToken)  
                         pszResult = lscp_strtok(NULL, pszSeps, &(pch));  
                 }  
                 else pszResult = achResult;  
                 // The result string is now set to the command response, if any.  
             } else {  
                 // Parse the error/warning message, skip first colon...  
                 pszToken = lscp_strtok(achResult, pszSeps, &(pch));  
                 if (pszToken) {  
                     // Get the error number...  
                     pszToken = lscp_strtok(NULL, pszSeps, &(pch));  
                     if (pszToken) {  
                         iErrno = atoi(pszToken);  
                         // And make the message text our final result.  
                         pszResult = lscp_strtok(NULL, pszSeps, &(pch));  
                     }  
                 }  
                 // The result string is set to the error/warning message text.  
             }  
         }  
         else if (cchResult == 0) {  
             // Fake a result message.  
             pszResult = "Server terminated the connection";  
             ret = LSCP_QUIT;  
         }  
         else lscp_socket_perror("lscp_client_query: recv");  
     }   // Check if select has timed out.  
     else if (iSelect == 0) {  
         // Fake a result message.  
         pszResult = "Timeout during receive operation";  
         ret = LSCP_TIMEOUT;  
     }  
     else lscp_socket_perror("lscp_client_query: select");  
   
     // Make the result official...  
     _lscp_client_set_result(pClient, pszResult, iErrno);  
   
     // Can go on with it...  
514      lscp_mutex_unlock(pClient->mutex);      lscp_mutex_unlock(pClient->mutex);
515    
516      return ret;      return ret;
517  }  }
518    
   
519  /**  /**
520   *  Get the last received result string. In case of error or warning,   *  Get the last received result string. In case of error or warning,
521   *  this is the text of the error or warning message issued.   *  this is the text of the error or warning message issued.
# Line 590  int lscp_client_get_errno ( lscp_client_ Line 555  int lscp_client_get_errno ( lscp_client_
555  // Client registration protocol functions.  // Client registration protocol functions.
556    
557  /**  /**
558   *  Register frontend for receiving UDP event messages:   *  Register frontend for receiving event messages:
559   *  SUBSCRIBE NOTIFICATION <udp-port>   *  SUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL
560     *      | CHANNEL_INFO | MISCELLANEOUS
561   *   *
562   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
563     *  @param events   Bit-wise OR'ed event flags to subscribe.
564   *   *
565   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
566   */   */
567  lscp_status_t lscp_client_subscribe ( lscp_client_t *pClient )  lscp_status_t lscp_client_subscribe ( lscp_client_t *pClient, lscp_event_t events )
568  {  {
569      lscp_status_t ret;      lscp_status_t ret = LSCP_FAILED;
     char szQuery[LSCP_BUFSIZ];  
     const char *pszResult;  
     const char *pszSeps = "[]";  
     char *pszToken;  
     char *pch;  
570    
571      if (pClient == NULL || pClient->sessid)      if (pClient == NULL)
572          return LSCP_FAILED;          return LSCP_FAILED;
573    
574      sprintf(szQuery, "SUBSCRIBE NOTIFICATION %d\r\n", ntohs(pClient->udp.addr.sin_port));      // Lock this section up.
575      ret = lscp_client_query(pClient, szQuery);      lscp_mutex_lock(pClient->mutex);
576      if (ret == LSCP_OK) {  
577          pszResult = lscp_client_get_result(pClient);      // If applicable, start the alternate connection...
578  #ifdef DEBUG      if (pClient->events == LSCP_EVENT_NONE)
579          fprintf(stderr, "lscp_client_subscribe: %s\n", pszResult);          ret = _lscp_client_evt_connect(pClient);
580  #endif  
581          // Check for the session-id on "OK[sessid]" response.      // Send the subscription commands.
582          pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));      if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_COUNT))
583          if (pszToken && strcasecmp(pszToken, "OK") == 0) {          ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_COUNT);
584              pszToken = lscp_strtok(NULL, pszSeps, &(pch));      if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT))
585              if (pszToken)          ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_VOICE_COUNT);
586                  pClient->sessid = strdup(pszToken);      if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT))
587          }          ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_STREAM_COUNT);
588      }      if (ret == LSCP_OK && (events & LSCP_EVENT_BUFFER_FILL))
589            ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_BUFFER_FILL);
590        if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO))
591            ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_CHANNEL_INFO);
592        if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))
593            ret = _lscp_client_evt_request(pClient, 1, LSCP_EVENT_MISCELLANEOUS);
594    
595        // Unlock this section down.
596        lscp_mutex_unlock(pClient->mutex);
597    
598      return ret;      return ret;
599  }  }
600    
601    
602  /**  /**
603   *  Deregister frontend for not receiving UDP event messages anymore:   *  Deregister frontend from receiving UDP event messages anymore:
604   *  UNSUBSCRIBE NOTIFICATION <session-id>   *  SUBSCRIBE CHANNEL_COUNT | VOICE_COUNT | STREAM_COUNT | BUFFER_FILL
605     *      | CHANNEL_INFO | MISCELLANEOUS
606   *   *
607   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
608     *  @param events   Bit-wise OR'ed event flags to unsubscribe.
609   *   *
610   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
611   */   */
612  lscp_status_t lscp_client_unsubscribe ( lscp_client_t *pClient )  lscp_status_t lscp_client_unsubscribe ( lscp_client_t *pClient, lscp_event_t events )
613  {  {
614      lscp_status_t ret;      lscp_status_t ret = LSCP_OK;
     char szQuery[LSCP_BUFSIZ];  
615    
616      if (pClient == NULL)      if (pClient == NULL)
617          return LSCP_FAILED;          return LSCP_FAILED;
     if (pClient->sessid == NULL)  
         return LSCP_FAILED;  
618    
619      sprintf(szQuery, "UNSUBSCRIBE NOTIFICATION %s\n\n", pClient->sessid);      // Lock this section up.
620      ret = lscp_client_query(pClient, szQuery);      lscp_mutex_lock(pClient->mutex);
621      if (ret == LSCP_OK) {  
622  #ifdef DEBUG      // Send the unsubscription commands.
623          fprintf(stderr, "lscp_client_unsubscribe: %s\n", lscp_client_get_result(pClient));      if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_COUNT))
624  #endif          ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_COUNT);
625          // Bail out session-id string.      if (ret == LSCP_OK && (events & LSCP_EVENT_VOICE_COUNT))
626          free(pClient->sessid);          ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_VOICE_COUNT);
627          pClient->sessid = NULL;      if (ret == LSCP_OK && (events & LSCP_EVENT_STREAM_COUNT))
628      }          ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_STREAM_COUNT);
629        if (ret == LSCP_OK && (events & LSCP_EVENT_BUFFER_FILL))
630            ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_BUFFER_FILL);
631        if (ret == LSCP_OK && (events & LSCP_EVENT_CHANNEL_INFO))
632            ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_CHANNEL_INFO);
633        if (ret == LSCP_OK && (events & LSCP_EVENT_MISCELLANEOUS))
634            ret = _lscp_client_evt_request(pClient, 0, LSCP_EVENT_MISCELLANEOUS);
635    
636        // If necessary, close the alternate connection...
637        if (pClient->events == LSCP_EVENT_NONE)
638            lscp_socket_agent_free(&(pClient->evt));
639    
640        // Unlock this section down.
641        lscp_mutex_unlock(pClient->mutex);
642    
643      return ret;      return ret;
644  }  }
645    
646    
647    /**
648     *  Getting current subscribed events.
649     *
650     *  @param pClient  Pointer to client instance structure.
651     *
652     *  @returns The current subscrived bit-wise OR'ed event flags.
653     */
654    lscp_event_t lscp_client_get_events ( lscp_client_t *pClient )
655    {
656        if (pClient == NULL)
657            return LSCP_EVENT_NONE;
658    
659        return pClient->events;
660    }
661    
662    
663  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
664  // Client command protocol functions.  // Client command protocol functions.
665    
# Line 683  lscp_status_t lscp_load_instrument ( lsc Line 681  lscp_status_t lscp_load_instrument ( lsc
681      if (pszFileName == NULL || iSamplerChannel < 0)      if (pszFileName == NULL || iSamplerChannel < 0)
682          return LSCP_FAILED;          return LSCP_FAILED;
683    
684      sprintf(szQuery, "LOAD INSTRUMENT %s %d %d\r\n", pszFileName, iInstrIndex, iSamplerChannel);      sprintf(szQuery, "LOAD INSTRUMENT '%s' %d %d\r\n", pszFileName, iInstrIndex, iSamplerChannel);
685        return lscp_client_query(pClient, szQuery);
686    }
687    
688    
689    /**
690     *  Loading an instrument in the background (non modal):
691     *  LOAD INSTRUMENT NON_MODAL <filename> <instr-index> <sampler-channel>
692     *
693     *  @param pClient          Pointer to client instance structure.
694     *  @param pszFileName      Instrument file name.
695     *  @param iInstrIndex      Instrument index number.
696     *  @param iSamplerChannel  Sampler Channel.
697     *
698     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
699     */
700    lscp_status_t lscp_load_instrument_non_modal ( lscp_client_t *pClient, const char *pszFileName, int iInstrIndex, int iSamplerChannel )
701    {
702        char szQuery[LSCP_BUFSIZ];
703    
704        if (pszFileName == NULL || iSamplerChannel < 0)
705            return LSCP_FAILED;
706    
707        sprintf(szQuery, "LOAD INSTRUMENT NON_MODAL '%s' %d %d\r\n", pszFileName, iInstrIndex, iSamplerChannel);
708      return lscp_client_query(pClient, szQuery);      return lscp_client_query(pClient, szQuery);
709  }  }
710    
# Line 722  lscp_status_t lscp_load_engine ( lscp_cl Line 743  lscp_status_t lscp_load_engine ( lscp_cl
743  int lscp_get_channels ( lscp_client_t *pClient )  int lscp_get_channels ( lscp_client_t *pClient )
744  {  {
745      int iChannels = -1;      int iChannels = -1;
746      if (lscp_client_query(pClient, "GET CHANNELS\r\n") == LSCP_OK)  
747        // Lock this section up.
748        lscp_mutex_lock(pClient->mutex);
749    
750        if (lscp_client_call(pClient, "GET CHANNELS\r\n") == LSCP_OK)
751          iChannels = atoi(lscp_client_get_result(pClient));          iChannels = atoi(lscp_client_get_result(pClient));
752    
753        // Unlock this section doen.
754        lscp_mutex_unlock(pClient->mutex);
755    
756      return iChannels;      return iChannels;
757  }  }
758    
759    
760  /**  /**
761     *  List current sampler channels number identifiers:
762     *  LIST CHANNELS
763     *
764     *  @param pClient  Pointer to client instance structure.
765     *
766     *  @returns An array of the sampler channels identifiers as positive integers,
767     *  terminated with -1 on success, NULL otherwise.
768     */
769    int *lscp_list_channels ( lscp_client_t *pClient )
770    {
771        const char *pszSeps = ",";
772    
773        if (pClient == NULL)
774            return NULL;
775    
776        // Lock this section up.
777        lscp_mutex_lock(pClient->mutex);
778    
779        if (pClient->channels) {
780            lscp_isplit_destroy(pClient->channels);
781            pClient->channels = NULL;
782        }
783    
784        if (lscp_client_call(pClient, "LIST CHANNELS\r\n") == LSCP_OK)
785            pClient->channels = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps);
786    
787        // Unlock this section down.
788        lscp_mutex_unlock(pClient->mutex);
789    
790        return pClient->channels;
791    }
792    
793    
794    /**
795   *  Adding a new sampler channel:   *  Adding a new sampler channel:
796   *  ADD CHANNEL   *  ADD CHANNEL
797   *   *
# Line 740  int lscp_get_channels ( lscp_client_t *p Line 803  int lscp_get_channels ( lscp_client_t *p
803  int lscp_add_channel ( lscp_client_t *pClient )  int lscp_add_channel ( lscp_client_t *pClient )
804  {  {
805      int iSamplerChannel = -1;      int iSamplerChannel = -1;
806      if (lscp_client_query(pClient, "ADD CHANNEL\r\n") == LSCP_OK)  
807        // Lock this section up.
808        lscp_mutex_lock(pClient->mutex);
809    
810        if (lscp_client_call(pClient, "ADD CHANNEL\r\n") == LSCP_OK)
811          iSamplerChannel = atoi(lscp_client_get_result(pClient));          iSamplerChannel = atoi(lscp_client_get_result(pClient));
812    
813        // Unlock this section down.
814        lscp_mutex_unlock(pClient->mutex);
815    
816      return iSamplerChannel;      return iSamplerChannel;
817  }  }
818    
# Line 768  lscp_status_t lscp_remove_channel ( lscp Line 839  lscp_status_t lscp_remove_channel ( lscp
839    
840    
841  /**  /**
842   *  Getting all available engines:   *  Getting all available engines count:
843   *  GET AVAILABLE_ENGINES   *  GET AVAILABLE_ENGINES
844   *   *
845   *  @param pClient  Pointer to client instance structure.   *  @param pClient  Pointer to client instance structure.
846   *   *
847     *  @returns The current total number of sampler engines on success,
848     *  -1 otherwise.
849     */
850    int lscp_get_available_engines ( lscp_client_t *pClient )
851    {
852        int iAvailableEngines = -1;
853    
854        // Lock this section up.
855        lscp_mutex_lock(pClient->mutex);
856    
857        if (lscp_client_call(pClient, "GET AVAILABLE_ENGINES\r\n") == LSCP_OK)
858            iAvailableEngines = atoi(lscp_client_get_result(pClient));
859    
860        // Unlock this section down.
861        lscp_mutex_unlock(pClient->mutex);
862    
863        return iAvailableEngines;
864    }
865    
866    
867    /**
868     *  Getting all available engines:
869     *  LIST AVAILABLE_ENGINES
870     *
871     *  @param pClient  Pointer to client instance structure.
872     *
873   *  @returns A NULL terminated array of engine name strings,   *  @returns A NULL terminated array of engine name strings,
874   *  or NULL in case of failure.   *  or NULL in case of failure.
875   */   */
876  const char **lscp_get_available_engines ( lscp_client_t *pClient )  const char **lscp_list_available_engines ( lscp_client_t *pClient )
877  {  {
878      const char *pszSeps = ",";      const char *pszSeps = ",";
879    
880        // Lock this section up.
881        lscp_mutex_lock(pClient->mutex);
882    
883      if (pClient->engines) {      if (pClient->engines) {
884          lscp_szsplit_destroy(pClient->engines);          lscp_szsplit_destroy(pClient->engines);
885          pClient->engines = NULL;          pClient->engines = NULL;
886      }      }
887    
888      if (lscp_client_query(pClient, "GET AVAILABLE_ENGINES\r\n") == LSCP_OK)      if (lscp_client_call(pClient, "LIST AVAILABLE_ENGINES\r\n") == LSCP_OK)
889          pClient->engines = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps);          pClient->engines = lscp_szsplit_create(lscp_client_get_result(pClient), pszSeps);
890    
891        // Unlock this section down.
892        lscp_mutex_unlock(pClient->mutex);
893    
894      return (const char **) pClient->engines;      return (const char **) pClient->engines;
895  }  }
896    
# Line 815  lscp_engine_info_t *lscp_get_engine_info Line 918  lscp_engine_info_t *lscp_get_engine_info
918      if (pszEngineName == NULL)      if (pszEngineName == NULL)
919          return NULL;          return NULL;
920    
921        // Lock this section up.
922        lscp_mutex_lock(pClient->mutex);
923    
924      pEngineInfo = &(pClient->engine_info);      pEngineInfo = &(pClient->engine_info);
925      lscp_engine_info_reset(pEngineInfo);      lscp_engine_info_reset(pEngineInfo);
926    
927      sprintf(szQuery, "GET ENGINE INFO %s\r\n", pszEngineName);      sprintf(szQuery, "GET ENGINE INFO %s\r\n", pszEngineName);
928      if (lscp_client_query(pClient, szQuery) != LSCP_OK)      if (lscp_client_call(pClient, szQuery) == LSCP_OK) {
929          return NULL;          pszResult = lscp_client_get_result(pClient);
930            pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
931      pszResult = lscp_client_get_result(pClient);          while (pszToken) {
932      pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));              if (strcasecmp(pszToken, "DESCRIPTION") == 0) {
933      while (pszToken) {                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
934          if (strcasecmp(pszToken, "DESCRIPTION") == 0) {                  if (pszToken)
935              pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                      lscp_unquote_dup(&(pEngineInfo->description), &pszToken);
936              if (pszToken)              }
937                  pEngineInfo->description = lscp_unquote(&pszToken, 1);              else if (strcasecmp(pszToken, "VERSION") == 0) {
938          }                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
939          else if (strcasecmp(pszToken, "VERSION") == 0) {                  if (pszToken)
940              pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                      lscp_unquote_dup(&(pEngineInfo->version), &pszToken);
941              if (pszToken)              }
942                  pEngineInfo->version = lscp_unquote(&pszToken, 1);              pszToken = lscp_strtok(NULL, pszSeps, &(pch));
943          }          }
         pszToken = lscp_strtok(NULL, pszSeps, &(pch));  
944      }      }
945        else pEngineInfo = NULL;
946    
947        // Unlock this section down.
948        lscp_mutex_unlock(pClient->mutex);
949    
950      return pEngineInfo;      return pEngineInfo;
951  }  }
# Line 865  lscp_channel_info_t *lscp_get_channel_in Line 974  lscp_channel_info_t *lscp_get_channel_in
974      if (iSamplerChannel < 0)      if (iSamplerChannel < 0)
975          return NULL;          return NULL;
976    
977        // Lock this section up.
978        lscp_mutex_lock(pClient->mutex);
979    
980      pChannelInfo = &(pClient->channel_info);      pChannelInfo = &(pClient->channel_info);
981      lscp_channel_info_reset(pChannelInfo);      lscp_channel_info_reset(pChannelInfo);
982    
983      sprintf(szQuery, "GET CHANNEL INFO %d\r\n", iSamplerChannel);      sprintf(szQuery, "GET CHANNEL INFO %d\r\n", iSamplerChannel);
984      if (lscp_client_query(pClient, szQuery) != LSCP_OK)      if (lscp_client_call(pClient, szQuery) == LSCP_OK) {
985          return NULL;          pszResult = lscp_client_get_result(pClient);
986            pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
987      pszResult = lscp_client_get_result(pClient);          while (pszToken) {
988      pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));              if (strcasecmp(pszToken, "ENGINE_NAME") == 0) {
989      while (pszToken) {                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
990          if (strcasecmp(pszToken, "ENGINE_NAME") == 0) {                  if (pszToken)
991              pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                      lscp_unquote_dup(&(pChannelInfo->engine_name), &pszToken);
992              if (pszToken)              }
993                  pChannelInfo->engine_name = lscp_unquote(&pszToken, 1);              else if (strcasecmp(pszToken, "AUDIO_OUTPUT_DEVICE") == 0) {
994          }                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
995          else if (strcasecmp(pszToken, "AUDIO_OUTPUT_DEVICE") == 0) {                  if (pszToken)
996              pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                      pChannelInfo->audio_device = atoi(lscp_ltrim(pszToken));
997              if (pszToken)              }
998                  pChannelInfo->audio_device = atoi(lscp_ltrim(pszToken));              else if (strcasecmp(pszToken, "AUDIO_OUTPUT_CHANNELS") == 0) {
999          }                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1000          else if (strcasecmp(pszToken, "AUDIO_OUTPUT_CHANNELS") == 0) {                  if (pszToken)
1001              pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                      pChannelInfo->audio_channels = atoi(lscp_ltrim(pszToken));
1002              if (pszToken)              }
1003                  pChannelInfo->audio_channels = atoi(lscp_ltrim(pszToken));              else if (strcasecmp(pszToken, "AUDIO_OUTPUT_ROUTING") == 0) {
1004          }                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1005          else if (strcasecmp(pszToken, "AUDIO_OUTPUT_ROUTING") == 0) {                  if (pszToken) {
1006              pszToken = lscp_strtok(NULL, pszCrlf, &(pch));                      if (pChannelInfo->audio_routing)
1007              if (pszToken)                          lscp_szsplit_destroy(pChannelInfo->audio_routing);
1008                  pChannelInfo->audio_routing = lscp_szsplit_create(pszToken, ",");                      pChannelInfo->audio_routing = lscp_szsplit_create(pszToken, ",");
1009          }                  }
1010          else if (strcasecmp(pszToken, "INSTRUMENT_FILE") == 0) {              }
1011              pszToken = lscp_strtok(NULL, pszCrlf, &(pch));              else if (strcasecmp(pszToken, "INSTRUMENT_FILE") == 0) {
1012              if (pszToken)                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1013                  pChannelInfo->instrument_file = lscp_unquote(&pszToken, 1);                  if (pszToken)
1014          }                      lscp_unquote_dup(&(pChannelInfo->instrument_file), &pszToken);
1015          else if (strcasecmp(pszToken, "INSTRUMENT_NR") == 0) {              }
1016              pszToken = lscp_strtok(NULL, pszCrlf, &(pch));              else if (strcasecmp(pszToken, "INSTRUMENT_NR") == 0) {
1017              if (pszToken)                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1018                  pChannelInfo->instrument_nr = atoi(lscp_ltrim(pszToken));                  if (pszToken)
1019          }                      pChannelInfo->instrument_nr = atoi(lscp_ltrim(pszToken));
1020          else if (strcasecmp(pszToken, "MIDI_INPUT_DEVICE") == 0) {              }
1021              pszToken = lscp_strtok(NULL, pszCrlf, &(pch));              else if (strcasecmp(pszToken, "INSTRUMENT_NAME") == 0) {
1022              if (pszToken)                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1023                  pChannelInfo->midi_device = atoi(lscp_ltrim(pszToken));                  if (pszToken)
1024          }                      lscp_unquote_dup(&(pChannelInfo->instrument_name), &pszToken);
1025          else if (strcasecmp(pszToken, "MIDI_INPUT_PORT") == 0) {              }
1026              pszToken = lscp_strtok(NULL, pszCrlf, &(pch));              else if (strcasecmp(pszToken, "INSTRUMENT_STATUS") == 0) {
1027              if (pszToken)                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1028                  pChannelInfo->midi_port = atoi(lscp_ltrim(pszToken));                  if (pszToken)
1029          }                      pChannelInfo->instrument_status = atoi(lscp_ltrim(pszToken));
1030          else if (strcasecmp(pszToken, "MIDI_INPUT_CHANNEL") == 0) {              }
1031              pszToken = lscp_strtok(NULL, pszCrlf, &(pch));              else if (strcasecmp(pszToken, "MIDI_INPUT_DEVICE") == 0) {
1032              if (pszToken)                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1033                  pChannelInfo->midi_channel = atoi(lscp_ltrim(pszToken));                  if (pszToken)
1034          }                      pChannelInfo->midi_device = atoi(lscp_ltrim(pszToken));
1035          else if (strcasecmp(pszToken, "VOLUME") == 0) {              }
1036              pszToken = lscp_strtok(NULL, pszCrlf, &(pch));              else if (strcasecmp(pszToken, "MIDI_INPUT_PORT") == 0) {
1037              if (pszToken)                  pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1038                  pChannelInfo->volume = (float) atof(lscp_ltrim(pszToken));                  if (pszToken)
1039                        pChannelInfo->midi_port = atoi(lscp_ltrim(pszToken));
1040                }
1041                else if (strcasecmp(pszToken, "MIDI_INPUT_CHANNEL") == 0) {
1042                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1043                    if (pszToken) {
1044                        pszToken = lscp_ltrim(pszToken);
1045                        if (strcasecmp(pszToken, "ALL") == 0)
1046                            pChannelInfo->midi_channel = LSCP_MIDI_CHANNEL_ALL;
1047                        else
1048                            pChannelInfo->midi_channel = atoi(pszToken);
1049                    }
1050                }
1051                else if (strcasecmp(pszToken, "VOLUME") == 0) {
1052                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1053                    if (pszToken)
1054                        pChannelInfo->volume = (float) atof(lscp_ltrim(pszToken));
1055                }
1056                pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1057          }          }
         pszToken = lscp_strtok(NULL, pszSeps, &(pch));  
1058      }      }
1059        else pChannelInfo = NULL;
1060    
1061        // Unlock this section up.
1062        lscp_mutex_unlock(pClient->mutex);
1063    
1064      return pChannelInfo;      return pChannelInfo;
1065  }  }
# Line 949  int lscp_get_channel_voice_count ( lscp_ Line 1082  int lscp_get_channel_voice_count ( lscp_
1082      if (iSamplerChannel < 0)      if (iSamplerChannel < 0)
1083          return iVoiceCount;          return iVoiceCount;
1084    
1085        // Lock this section up.
1086        lscp_mutex_lock(pClient->mutex);
1087    
1088      sprintf(szQuery, "GET CHANNEL VOICE_COUNT %d\r\n", iSamplerChannel);      sprintf(szQuery, "GET CHANNEL VOICE_COUNT %d\r\n", iSamplerChannel);
1089      if (lscp_client_query(pClient, szQuery) == LSCP_OK)      if (lscp_client_call(pClient, szQuery) == LSCP_OK)
1090          iVoiceCount = atoi(lscp_client_get_result(pClient));          iVoiceCount = atoi(lscp_client_get_result(pClient));
1091    
1092        // Unlock this section down.
1093        lscp_mutex_unlock(pClient->mutex);
1094    
1095      return iVoiceCount;      return iVoiceCount;
1096  }  }
1097    
# Line 961  int lscp_get_channel_voice_count ( lscp_ Line 1100  int lscp_get_channel_voice_count ( lscp_
1100   *  Current number of active disk streams:   *  Current number of active disk streams:
1101   *  GET CHANNEL STREAM_COUNT <sampler-channel>   *  GET CHANNEL STREAM_COUNT <sampler-channel>
1102   *   *
1103     *  @param pClient          Pointer to client instance structure.
1104     *  @param iSamplerChannel  Sampler channel number.
1105     *
1106   *  @returns The number of active disk streams on success, -1 otherwise.   *  @returns The number of active disk streams on success, -1 otherwise.
1107   */   */
1108  int lscp_get_channel_stream_count ( lscp_client_t *pClient, int iSamplerChannel )  int lscp_get_channel_stream_count ( lscp_client_t *pClient, int iSamplerChannel )
# Line 971  int lscp_get_channel_stream_count ( lscp Line 1113  int lscp_get_channel_stream_count ( lscp
1113      if (iSamplerChannel < 0)      if (iSamplerChannel < 0)
1114          return iStreamCount;          return iStreamCount;
1115    
1116        // Lock this section up.
1117        lscp_mutex_lock(pClient->mutex);
1118    
1119      sprintf(szQuery, "GET CHANNEL STREAM_COUNT %d\r\n", iSamplerChannel);      sprintf(szQuery, "GET CHANNEL STREAM_COUNT %d\r\n", iSamplerChannel);
1120      if (lscp_client_query(pClient, szQuery) == LSCP_OK)      if (lscp_client_call(pClient, szQuery) == LSCP_OK)
1121          iStreamCount = atoi(lscp_client_get_result(pClient));          iStreamCount = atoi(lscp_client_get_result(pClient));
1122    
1123        // Unlock this section down.
1124        lscp_mutex_unlock(pClient->mutex);
1125    
1126      return iStreamCount;      return iStreamCount;
1127  }  }
1128    
1129    
1130  /**  /**
1131     *  Current least usage of active disk streams.
1132     *
1133     *  @param pClient          Pointer to client instance structure.
1134     *  @param iSamplerChannel  Sampler channel number.
1135     *
1136     *  @returns The usage percentage of the least filled active disk stream
1137     *  on success, -1 otherwise.
1138     */
1139    int lscp_get_channel_stream_usage ( lscp_client_t *pClient, int iSamplerChannel )
1140    {
1141        char szQuery[LSCP_BUFSIZ];
1142        int  iStreamUsage = -1;
1143        const char *pszResult;
1144        const char *pszSeps = "[]%,";
1145        char *pszToken;
1146        char *pch;
1147        int   iStream;
1148        int   iPercent;
1149    
1150        if (iSamplerChannel < 0)
1151            return iStreamUsage;
1152    
1153        // Lock this section up.
1154        lscp_mutex_lock(pClient->mutex);
1155    
1156        iStream = 0;
1157        sprintf(szQuery, "GET CHANNEL BUFFER_FILL PERCENTAGE %d\r\n", iSamplerChannel);
1158        if (lscp_client_call(pClient, szQuery) == LSCP_OK) {
1159            pszResult = lscp_client_get_result(pClient);
1160            pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
1161            while (pszToken) {
1162                if (*pszToken) {
1163                    // Skip stream id.
1164                    pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1165                    if (pszToken == NULL)
1166                        break;
1167                    // Get least buffer fill percentage.
1168                    iPercent = atol(pszToken);
1169                    if (iStreamUsage > iPercent || iStream == 0)
1170                        iStreamUsage = iPercent;
1171                    iStream++;
1172                }
1173                pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1174            }
1175        }
1176    
1177        // Unlock this section down.
1178        lscp_mutex_unlock(pClient->mutex);
1179    
1180        return iStreamUsage;
1181    }
1182    
1183    
1184    /**
1185   *  Current fill state of disk stream buffers:   *  Current fill state of disk stream buffers:
1186   *  GET CHANNEL BUFFER_FILL {BYTES|PERCENTAGE} <sampler-channel>   *  GET CHANNEL BUFFER_FILL {BYTES|PERCENTAGE} <sampler-channel>
1187   *   *
# Line 1005  lscp_buffer_fill_t *lscp_get_channel_buf Line 1207  lscp_buffer_fill_t *lscp_get_channel_buf
1207      char *pch;      char *pch;
1208      int   iStream;      int   iStream;
1209    
1210        // Retrieve a channel stream estimation.
1211      iStreamCount = lscp_get_channel_stream_count(pClient, iSamplerChannel);      iStreamCount = lscp_get_channel_stream_count(pClient, iSamplerChannel);
1212        if (pClient->iStreamCount < 0)
1213            return NULL;
1214    
1215        // Lock this section up.
1216        lscp_mutex_lock(pClient->mutex);
1217    
1218        // Check if we need to reallocate the stream usage array.
1219      if (pClient->iStreamCount != iStreamCount) {      if (pClient->iStreamCount != iStreamCount) {
1220          if (pClient->buffer_fill)          if (pClient->buffer_fill)
1221              free(pClient->buffer_fill);              free(pClient->buffer_fill);
# Line 1016  lscp_buffer_fill_t *lscp_get_channel_buf Line 1226  lscp_buffer_fill_t *lscp_get_channel_buf
1226          pClient->iStreamCount = iStreamCount;          pClient->iStreamCount = iStreamCount;
1227      }      }
1228    
     if (pClient->iStreamCount < 1)  
         return NULL;  
   
     iStream = 0;  
     pBufferFill = pClient->buffer_fill;  
   
1229      // Get buffer fill usage...      // Get buffer fill usage...
1230      sprintf(szQuery, "GET CHANNEL BUFFER_FILL %s %d\r\n", pszUsageType, iSamplerChannel);      pBufferFill = pClient->buffer_fill;
1231      if (lscp_client_query(pClient, szQuery) == LSCP_OK) {      if (pBufferFill && iStreamCount > 0) {
1232          pszResult = lscp_client_get_result(pClient);          iStream = 0;
1233          pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));          pBufferFill = pClient->buffer_fill;
1234          while (pszToken && iStream < pClient->iStreamCount) {          sprintf(szQuery, "GET CHANNEL BUFFER_FILL %s %d\r\n", pszUsageType, iSamplerChannel);
1235              if (*pszToken) {          if (lscp_client_call(pClient, szQuery) == LSCP_OK) {
1236                  pBufferFill[iStream].stream_id = atol(pszToken);              pszResult = lscp_client_get_result(pClient);
1237                pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
1238                while (pszToken && iStream < pClient->iStreamCount) {
1239                    if (*pszToken) {
1240                        pBufferFill[iStream].stream_id = atol(pszToken);
1241                        pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1242                        if (pszToken == NULL)
1243                            break;
1244                        pBufferFill[iStream].stream_usage = atol(pszToken);
1245                        iStream++;
1246                    }
1247                  pszToken = lscp_strtok(NULL, pszSeps, &(pch));                  pszToken = lscp_strtok(NULL, pszSeps, &(pch));
                 if (pszToken == NULL)  
                     break;  
                 pBufferFill[iStream].stream_usage = atol(pszToken);  
                 iStream++;  
1248              }              }
1249              pszToken = lscp_strtok(NULL, pszSeps, &(pch));          }   // Reset the usage, whatever it was before.
1250          }          else while (iStream < pClient->iStreamCount)
1251      }   // Reset the usage, whatever it was before.              pBufferFill[iStream++].stream_usage = 0;
1252      else while (iStream < pClient->iStreamCount)      }
1253          pBufferFill[iStream++].stream_usage = 0;  
1254        // Unlock this section down.
1255        lscp_mutex_unlock(pClient->mutex);
1256    
1257      return pBufferFill;      return pBufferFill;
1258  }  }
# Line 1067  lscp_status_t lscp_set_channel_audio_typ Line 1279  lscp_status_t lscp_set_channel_audio_typ
1279    
1280    
1281  /**  /**
1282     *  Setting audio output device:
1283     *  SET CHANNEL AUDIO_OUTPUT_DEVICE <sampler-channel> <device-id>
1284     *
1285     *  @param pClient          Pointer to client instance structure.
1286     *  @param iSamplerChannel  Sampler channel number.
1287     *  @param iAudioDevice     Audio output device number identifier.
1288     */
1289    lscp_status_t lscp_set_channel_audio_device ( lscp_client_t *pClient, int iSamplerChannel, int iAudioDevice )
1290    {
1291        char szQuery[LSCP_BUFSIZ];
1292    
1293        if (iSamplerChannel < 0 || iAudioDevice < 0)
1294            return LSCP_FAILED;
1295    
1296        sprintf(szQuery, "SET CHANNEL AUDIO_OUTPUT_DEVICE %d %d\r\n", iSamplerChannel, iAudioDevice);
1297        return lscp_client_query(pClient, szQuery);
1298    }
1299    
1300    
1301    /**
1302   *  Setting audio output channel:   *  Setting audio output channel:
1303   *  SET CHANNEL AUDIO_OUTPUT_CHANNEL <sampler-channel> <audio-output-chan> <audio-input-chan>   *  SET CHANNEL AUDIO_OUTPUT_CHANNEL <sampler-channel> <audio-output-chan> <audio-input-chan>
1304   *   *
# Line 1084  lscp_status_t lscp_set_channel_audio_cha Line 1316  lscp_status_t lscp_set_channel_audio_cha
1316      if (iSamplerChannel < 0 || iAudioOut < 0 || iAudioIn < 0)      if (iSamplerChannel < 0 || iAudioOut < 0 || iAudioIn < 0)
1317          return LSCP_FAILED;          return LSCP_FAILED;
1318    
1319      sprintf(szQuery, "SET CHANNEL AUDIO_OUTPUT_CHANNELS %d %d %d\r\n", iSamplerChannel, iAudioOut, iAudioIn);      sprintf(szQuery, "SET CHANNEL AUDIO_OUTPUT_CHANNEL %d %d %d\r\n", iSamplerChannel, iAudioOut, iAudioIn);
1320      return lscp_client_query(pClient, szQuery);      return lscp_client_query(pClient, szQuery);
1321  }  }
1322    
# Line 1112  lscp_status_t lscp_set_channel_midi_type Line 1344  lscp_status_t lscp_set_channel_midi_type
1344    
1345    
1346  /**  /**
1347     *  Setting MIDI input device:
1348     *  SET CHANNEL MIDI_INPUT_DEVICE <sampler-channel> <device-id>
1349     *
1350     *  @param pClient          Pointer to client instance structure.
1351     *  @param iSamplerChannel  Sampler channel number.
1352     *  @param iMidiDevice      MIDI input device number identifier.
1353     */
1354    lscp_status_t lscp_set_channel_midi_device ( lscp_client_t *pClient, int iSamplerChannel, int iMidiDevice )
1355    {
1356        char szQuery[LSCP_BUFSIZ];
1357    
1358        if (iSamplerChannel < 0 || iMidiDevice < 0)
1359            return LSCP_FAILED;
1360    
1361        sprintf(szQuery, "SET CHANNEL MIDI_INPUT_DEVICE %d %d\r\n", iSamplerChannel, iMidiDevice);
1362        return lscp_client_query(pClient, szQuery);
1363    }
1364    
1365    
1366    /**
1367   *  Setting MIDI input port:   *  Setting MIDI input port:
1368   *  SET CHANNEL MIDI_INPUT_PORT <sampler-channel> <midi-input-port>   *  SET CHANNEL MIDI_INPUT_PORT <sampler-channel> <midi-input-port>
1369   *   *
# Line 1139  lscp_status_t lscp_set_channel_midi_port Line 1391  lscp_status_t lscp_set_channel_midi_port
1391   *   *
1392   *  @param pClient          Pointer to client instance structure.   *  @param pClient          Pointer to client instance structure.
1393   *  @param iSamplerChannel  Sampler channel number.   *  @param iSamplerChannel  Sampler channel number.
1394   *  @param iMidiChannel     MIDI channel number to listen (1-16) or   *  @param iMidiChannel     MIDI channel address number to listen (0-15) or
1395   *                          zero (0) to listen on all channels.   *                          LSCP_MIDI_CHANNEL_ALL (16) to listen on all channels.
1396   *   *
1397   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.   *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1398   */   */
# Line 1151  lscp_status_t lscp_set_channel_midi_chan Line 1403  lscp_status_t lscp_set_channel_midi_chan
1403      if (iSamplerChannel < 0 || iMidiChannel < 0 || iMidiChannel > 16)      if (iSamplerChannel < 0 || iMidiChannel < 0 || iMidiChannel > 16)
1404          return LSCP_FAILED;          return LSCP_FAILED;
1405    
1406      if (iMidiChannel > 0)      if (iMidiChannel == LSCP_MIDI_CHANNEL_ALL)
         sprintf(szQuery, "SET CHANNEL MIDI_INPUT_CHANNEL %d %d\r\n", iSamplerChannel, iMidiChannel);  
     else  
1407          sprintf(szQuery, "SET CHANNEL MIDI_INPUT_CHANNEL %d ALL\r\n", iSamplerChannel);          sprintf(szQuery, "SET CHANNEL MIDI_INPUT_CHANNEL %d ALL\r\n", iSamplerChannel);
1408        else
1409            sprintf(szQuery, "SET CHANNEL MIDI_INPUT_CHANNEL %d %d\r\n", iSamplerChannel, iMidiChannel);
1410      return lscp_client_query(pClient, szQuery);      return lscp_client_query(pClient, szQuery);
1411  }  }
1412    
# Line 1204  lscp_status_t lscp_reset_channel ( lscp_ Line 1456  lscp_status_t lscp_reset_channel ( lscp_
1456  }  }
1457    
1458    
1459    /**
1460     *  Resetting the sampler:
1461     *  RESET
1462     *
1463     *  @param pClient  Pointer to client instance structure.
1464     *
1465     *  @returns LSCP_OK on success, LSCP_FAILED otherwise.
1466     */
1467    lscp_status_t lscp_reset_sampler ( lscp_client_t *pClient )
1468    {
1469        return lscp_client_query(pClient, "RESET\r\n");
1470    }
1471    
1472    
1473    /**
1474     *  Getting information about the server.
1475     *  GET SERVER INFO
1476     *
1477     *  @param pClient  Pointer to client instance structure.
1478     *
1479     *  @returns A pointer to a @ref lscp_server_info_t structure, with all the
1480     *  information of the current connected server, or NULL in case of failure.
1481     */
1482    lscp_server_info_t *lscp_get_server_info ( lscp_client_t *pClient )
1483    {
1484        lscp_server_info_t *pServerInfo;
1485        const char *pszResult;
1486        const char *pszSeps = ":";
1487        const char *pszCrlf = "\r\n";
1488        char *pszToken;
1489        char *pch;
1490    
1491        // Lock this section up.
1492        lscp_mutex_lock(pClient->mutex);
1493    
1494        pServerInfo = &(pClient->server_info);
1495        lscp_server_info_reset(pServerInfo);
1496    
1497        if (lscp_client_call(pClient, "GET SERVER INFO\r\n") == LSCP_OK) {
1498            pszResult = lscp_client_get_result(pClient);
1499            pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch));
1500            while (pszToken) {
1501                if (strcasecmp(pszToken, "DESCRIPTION") == 0) {
1502                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1503                    if (pszToken)
1504                        lscp_unquote_dup(&(pServerInfo->description), &pszToken);
1505                }
1506                else if (strcasecmp(pszToken, "VERSION") == 0) {
1507                    pszToken = lscp_strtok(NULL, pszCrlf, &(pch));
1508                    if (pszToken)
1509                        lscp_unquote_dup(&(pServerInfo->version), &pszToken);
1510                }
1511                pszToken = lscp_strtok(NULL, pszSeps, &(pch));
1512            }
1513        }
1514        else pServerInfo = NULL;
1515    
1516        // Unlock this section down.
1517        lscp_mutex_unlock(pClient->mutex);
1518    
1519        return pServerInfo;
1520    }
1521    
1522    
1523  // end of client.c  // end of client.c

Legend:
Removed from v.114  
changed lines
  Added in v.623

  ViewVC Help
Powered by ViewVC