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

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

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

revision 171 by capela, Mon Jul 5 16:26:44 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 49  void lscp_client_set_result ( lscp_clien Line 49  void lscp_client_set_result ( lscp_clien
49          pClient->pszResult = strdup(lscp_ltrim(pszResult));          pClient->pszResult = strdup(lscp_ltrim(pszResult));
50  }  }
51    
52  // The main client requester call executive.  
53  lscp_status_t lscp_client_call ( lscp_client_t *pClient, const char *pszQuery )  // The common client receiver executive.
54    lscp_status_t lscp_client_recv ( lscp_client_t *pClient, char *pchBuffer, int *pcchBuffer, int iTimeout )
55  {  {
56      fd_set fds;                         // File descriptor list for select().      fd_set fds;                         // File descriptor list for select().
57      int    fd, fdmax;                   // Maximum file descriptor number.      int    fd, fdmax;                   // Maximum file descriptor number.
58      struct timeval tv;                  // For specifying a timeout value.      struct timeval tv;                  // For specifying a timeout value.
59      int    iSelect;                     // Holds select return status.      int    iSelect;                     // Holds select return status.
60      int    iTimeout;  
61        lscp_status_t ret = LSCP_FAILED;
62    
63        if (pClient == NULL)
64            return ret;
65    
66        // Prepare for waiting on select...
67        fd = (int) pClient->cmd.sock;
68        FD_ZERO(&fds);
69        FD_SET((unsigned int) fd, &fds);
70        fdmax = fd;
71    
72        // Use the timeout select feature...
73        if (iTimeout < 1)
74            iTimeout = pClient->iTimeout;
75        if (iTimeout > 1000) {
76            tv.tv_sec = iTimeout / 1000;
77            iTimeout -= tv.tv_sec * 1000;
78        }
79        else tv.tv_sec = 0;
80        tv.tv_usec = iTimeout * 1000;
81    
82        // Wait for event...
83        iSelect = select(fdmax + 1, &fds, NULL, NULL, &tv);
84        if (iSelect > 0 && FD_ISSET(fd, &fds)) {
85            // May recv now...
86            *pcchBuffer = recv(pClient->cmd.sock, pchBuffer, *pcchBuffer, 0);
87            if (*pcchBuffer > 0)
88                ret = LSCP_OK;
89            else if (*pcchBuffer < 0)
90                lscp_socket_perror("lscp_client_recv: recv");
91            else if (*pcchBuffer == 0) {
92                // Damn, server probably disconnected,
93                // we better free everything down here.
94                lscp_socket_agent_free(&(pClient->evt));
95                lscp_socket_agent_free(&(pClient->cmd));
96                // Fake a result message.
97                ret = LSCP_QUIT;
98            }
99        }   // Check if select has timed out.
100        else if (iSelect == 0)
101            ret = LSCP_TIMEOUT;
102        else
103            lscp_socket_perror("lscp_client_recv: select");
104    
105        return ret;
106    }
107    
108    
109    // The main client requester call executive.
110    lscp_status_t lscp_client_call ( lscp_client_t *pClient, const char *pszQuery )
111    {
112      int    cchQuery;      int    cchQuery;
113      char   achResult[LSCP_BUFSIZ];      char   achResult[LSCP_BUFSIZ];
114      int    cchResult;      int    cchResult;
# Line 81  lscp_status_t lscp_client_call ( lscp_cl Line 133  lscp_status_t lscp_client_call ( lscp_cl
133          return ret;          return ret;
134      }      }
135    
136            // Check if last transaction has timed out, in which case
137            // we'll retry wait and flush for some pending garbage...
138            if (pClient->iTimeoutCount > 0) {
139                    cchResult = sizeof(achResult);
140                    ret = lscp_client_recv(pClient, achResult, &cchResult, pClient->iTimeout);
141                    if (ret == LSCP_OK) {
142                            // We've got rid of timeout trouble (hopefully).
143                            pClient->iTimeoutCount = 0;
144                    } else {
145                            // Things are worse than before. Fake a result message.
146                            iErrno = (int) ret;
147                            pszResult = "Failure during flush timeout operation";
148                            lscp_client_set_result(pClient, pszResult, iErrno);
149                            return ret;
150                    }
151            }
152    
153      // Send data, and then, wait for the result...      // Send data, and then, wait for the result...
154      cchQuery = strlen(pszQuery);      cchQuery = strlen(pszQuery);
155      if (send(pClient->cmd.sock, pszQuery, cchQuery, 0) < cchQuery) {      if (send(pClient->cmd.sock, pszQuery, cchQuery, 0) < cchQuery) {
156          lscp_socket_perror("_lscp_client_call: send");          lscp_socket_perror("lscp_client_call: send");
157          pszResult = "Failure during send operation";          pszResult = "Failure during send operation";
158          lscp_client_set_result(pClient, pszResult, iErrno);          lscp_client_set_result(pClient, pszResult, iErrno);
159          return ret;          return ret;
160      }      }
161    
162      // Prepare for waiting on select...      // Wait for receive event...
163      fd = (int) pClient->cmd.sock;      cchResult = sizeof(achResult);
164      FD_ZERO(&fds);      ret = lscp_client_recv(pClient, achResult, &cchResult, pClient->iTimeout);
165      FD_SET((unsigned int) fd, &fds);  
166      fdmax = fd;      switch (ret) {
167    
168      // Use the timeout select feature...        case LSCP_OK:
169      iTimeout = pClient->iTimeout;          // Always force the result to be null terminated (and trim trailing CRLFs)!
170      if (iTimeout > 1000) {          while (cchResult > 0 && (achResult[cchResult - 1] == '\n' || achResult[cchResult- 1] == '\r'))
171          tv.tv_sec = iTimeout / 1000;              cchResult--;
172          iTimeout -= tv.tv_sec * 1000;          achResult[cchResult] = (char) 0;
173      }          // Check if the response it's an error or warning message.
174      else tv.tv_sec = 0;          if (strncasecmp(achResult, "WRN:", 4) == 0)
175      tv.tv_usec = iTimeout * 1000;              ret = LSCP_WARNING;
176            else if (strncasecmp(achResult, "ERR:", 4) == 0)
177      // Wait for event...              ret = LSCP_ERROR;
178      iSelect = select(fdmax + 1, &fds, NULL, NULL, &tv);          // So we got a result...
179      if (iSelect > 0 && FD_ISSET(fd, &fds)) {          if (ret == LSCP_OK) {
180          // May recv now...              // Reset errno in case of success.
181          cchResult = recv(pClient->cmd.sock, achResult, sizeof(achResult), 0);              iErrno = 0;
182          if (cchResult > 0) {              // Is it a special successful response?
183              // Assume early success.              if (strncasecmp(achResult, "OK[", 3) == 0) {
184              ret = LSCP_OK;                  // Parse the OK message, get the return string under brackets...
             // 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...  
185                  pszToken = lscp_strtok(achResult, pszSeps, &(pch));                  pszToken = lscp_strtok(achResult, pszSeps, &(pch));
186                    if (pszToken)
187                        pszResult = lscp_strtok(NULL, pszSeps, &(pch));
188                }
189                else pszResult = achResult;
190                // The result string is now set to the command response, if any.
191            } else {
192                // Parse the error/warning message, skip first colon...
193                pszToken = lscp_strtok(achResult, pszSeps, &(pch));
194                if (pszToken) {
195                    // Get the error number...
196                    pszToken = lscp_strtok(NULL, pszSeps, &(pch));
197                  if (pszToken) {                  if (pszToken) {
198                      // Get the error number...                      iErrno = atoi(pszToken);
199                      pszToken = lscp_strtok(NULL, pszSeps, &(pch));                      // And make the message text our final result.
200                      if (pszToken) {                      pszResult = lscp_strtok(NULL, pszSeps, &(pch));
                         iErrno = atoi(pszToken);  
                         // And make the message text our final result.  
                         pszResult = lscp_strtok(NULL, pszSeps, &(pch));  
                     }  
201                  }                  }
                 // The result string is set to the error/warning message text.  
202              }              }
203                // The result string is set to the error/warning message text.
204          }          }
205          else if (cchResult == 0) {          break;
206              // Damn, server disconnected, we better free everything down here.  
207              lscp_socket_agent_free(&(pClient->evt));        case LSCP_TIMEOUT:
208              lscp_socket_agent_free(&(pClient->cmd));                  // We have trouble...
209              // Fake a result message.          pClient->iTimeoutCount++;
             ret = LSCP_QUIT;  
             pszResult = "Server terminated the connection";  
             iErrno = (int) ret;  
         } else {  
             // What's down?  
             lscp_socket_perror("_lscp_client_call: recv");  
             pszResult = "Failure during receive operation";  
         }  
     }   // Check if select has timed out.  
     else if (iSelect == 0) {  
210          // Fake a result message.          // Fake a result message.
         ret = LSCP_TIMEOUT;  
211          pszResult = "Timeout during receive operation";          pszResult = "Timeout during receive operation";
212          iErrno = (int) ret;          iErrno = (int) ret;
213     }          break;
214      else lscp_socket_perror("_lscp_client_call: select");  
215          case LSCP_QUIT:
216            // Fake a result message.
217            pszResult = "Server terminated the connection";
218            iErrno = (int) ret;
219            break;
220    
221          case LSCP_FAILED:
222          default:
223            // What's down?
224            pszResult = "Failure during receive operation";
225            break;
226        }
227    
228      // Make the result official...      // Make the result official...
229      lscp_client_set_result(pClient, pszResult, iErrno);      lscp_client_set_result(pClient, pszResult, iErrno);
# Line 223  char *lscp_unquote ( char **ppsz, int du Line 276  char *lscp_unquote ( char **ppsz, int du
276      return psz;      return psz;
277  }  }
278    
279    // Unquote and make a duplicate of an in-split string.
280    void lscp_unquote_dup ( char **ppszDst, char **ppszSrc )
281    {
282         // Free desteny string, if already there.
283         if (*ppszDst)
284             free(*ppszDst);
285         *ppszDst = NULL;
286         // Unquote and duplicate.
287         if (*ppszSrc)
288             *ppszDst = lscp_unquote(ppszSrc, 1);
289    }
290    
291    
292  // Custom tokenizer.  // Custom tokenizer.
293  char *lscp_strtok ( char *pchBuffer, const char *pszSeps, char **ppch )  char *lscp_strtok ( char *pchBuffer, const char *pszSeps, char **ppch )
# Line 283  char **lscp_szsplit_create ( const char Line 348  char **lscp_szsplit_create ( const char
348              --pch;              --pch;
349          *pch = (char) 0;          *pch = (char) 0;
350          // Make it official.          // Make it official.
351          ppszSplit[i++] = lscp_unquote(&pszHead, 0);          ppszSplit[i] = lscp_unquote(&pszHead, 0);
352          // Do we need to grow?          // Do we need to grow?
353          if (i >= iSize) {          if (++i >= iSize) {
354              // Yes, but only grow in chunks.              // Yes, but only grow in chunks.
355              iSize += LSCP_SPLIT_CHUNK1;              iSize += LSCP_SPLIT_CHUNK1;
356              // Allocate and copy to new split array.              // Allocate and copy to new split array.
# Line 346  int *lscp_isplit_create ( const char *ps Line 411  int *lscp_isplit_create ( const char *ps
411      int iSize, i, j, cchSeps;      int iSize, i, j, cchSeps;
412      int *piSplit, *piNewSplit;      int *piSplit, *piNewSplit;
413    
414        // Get it clean first.
415        pchHead = lscp_ltrim((char *) pszCsv);
416        if (*pchHead == (char) 0)
417            return NULL;
418    
419      // Initial size is one chunk away.      // Initial size is one chunk away.
420      iSize = LSCP_SPLIT_CHUNK1;      iSize = LSCP_SPLIT_CHUNK1;
421      // Allocate and split...      // Allocate and split...
# Line 355  int *lscp_isplit_create ( const char *ps Line 425  int *lscp_isplit_create ( const char *ps
425    
426      // Make a copy of the original string.      // Make a copy of the original string.
427      i = 0;      i = 0;
     pchHead = (char *) pszCsv;  
428      if ((piSplit[i++] = atoi(pchHead)) < 0) {      if ((piSplit[i++] = atoi(pchHead)) < 0) {
429          free(piSplit);          free(piSplit);
430          return NULL;          return NULL;
# Line 367  int *lscp_isplit_create ( const char *ps Line 436  int *lscp_isplit_create ( const char *ps
436          // Pre-advance to next item.          // Pre-advance to next item.
437          pchHead = pch + cchSeps;          pchHead = pch + cchSeps;
438          // Make it official.          // Make it official.
439          piSplit[i++] = atoi(pchHead);          piSplit[i] = atoi(pchHead);
440          // Do we need to grow?          // Do we need to grow?
441          if (i >= iSize) {          if (++i >= iSize) {
442              // Yes, but only grow in chunks.              // Yes, but only grow in chunks.
443              iSize += LSCP_SPLIT_CHUNK1;              iSize += LSCP_SPLIT_CHUNK1;
444              // Allocate and copy to new split array.              // Allocate and copy to new split array.
# Line 531  void lscp_plist_free ( lscp_param_t **pp Line 600  void lscp_plist_free ( lscp_param_t **pp
600  {  {
601      lscp_param_t *pParams;      lscp_param_t *pParams;
602      int i;      int i;
603        
604      if (ppList) {      if (ppList) {
605          if (*ppList) {          if (*ppList) {
606              pParams = *ppList;              pParams = *ppList;
# Line 553  void lscp_plist_append ( lscp_param_t ** Line 622  void lscp_plist_append ( lscp_param_t **
622      lscp_param_t *pNewParams;      lscp_param_t *pNewParams;
623      int iSize, iNewSize;      int iSize, iNewSize;
624      int i = 0;      int i = 0;
625        
626      if (ppList && *ppList) {      if (ppList && *ppList) {
627          pParams = *ppList;          pParams = *ppList;
628          while (pParams[i].key)          while (pParams[i].key) {
629                if (strcasecmp(pParams[i].key, pszKey) == 0) {
630                    if (pParams[i].value)
631                        free(pParams[i].value);
632                    pParams[i].value = strdup(pszValue);
633                    return;
634                }
635              i++;              i++;
636            }
637          iSize = LSCP_SPLIT_SIZE(i);          iSize = LSCP_SPLIT_SIZE(i);
638          pParams[i].key   = strdup(pszKey);          pParams[i].key   = strdup(pszKey);
639          pParams[i].value = strdup(pszValue);          pParams[i].value = strdup(pszValue);
# Line 565  void lscp_plist_append ( lscp_param_t ** Line 641  void lscp_plist_append ( lscp_param_t **
641              iNewSize   = iSize + LSCP_SPLIT_CHUNK1;              iNewSize   = iSize + LSCP_SPLIT_CHUNK1;
642              pNewParams = (lscp_param_t *) malloc(iNewSize * sizeof(lscp_param_t));              pNewParams = (lscp_param_t *) malloc(iNewSize * sizeof(lscp_param_t));
643              for (i = 0; i < iSize; i++) {              for (i = 0; i < iSize; i++) {
644                  pParams[i].key   = pParams[i].key;                  pNewParams[i].key   = pParams[i].key;
645                  pParams[i].value = pParams[i].value;                  pNewParams[i].value = pParams[i].value;
646              }              }
647              for ( ; i < iNewSize; i++) {              for ( ; i < iNewSize; i++) {
648                  pNewParams[i].key   = NULL;                  pNewParams[i].key   = NULL;
# Line 578  void lscp_plist_append ( lscp_param_t ** Line 654  void lscp_plist_append ( lscp_param_t **
654      }      }
655  }  }
656    
657    #ifdef LSCP_PLIST_COUNT
658    
659  // Compute a parameter list valid item count.  // Compute a parameter list valid item count.
660  int lscp_plist_count ( lscp_param_t **ppList )  int lscp_plist_count ( lscp_param_t **ppList )
# Line 592  int lscp_plist_count ( lscp_param_t **pp Line 669  int lscp_plist_count ( lscp_param_t **pp
669      return i;      return i;
670  }  }
671    
   
672  // Compute the legal parameter list size.  // Compute the legal parameter list size.
673  int lscp_plist_size ( lscp_param_t **ppList )  int lscp_plist_size ( lscp_param_t **ppList )
674  {  {
675      return LSCP_SPLIT_SIZE(lscp_plist_count(ppList));      return LSCP_SPLIT_SIZE(lscp_plist_count(ppList));
676  }  }
677    
678    #endif // LSCP_PLIST_COUNT
679    
680    
681    //-------------------------------------------------------------------------
682    // Server info struct helper functions.
683    
684    void lscp_server_info_init ( lscp_server_info_t *pServerInfo )
685    {
686        pServerInfo->description = NULL;
687        pServerInfo->version     = NULL;
688    }
689    
690    void lscp_server_info_free ( lscp_server_info_t *pServerInfo )
691    {
692        if (pServerInfo->description)
693            free(pServerInfo->description);
694        if (pServerInfo->version)
695            free(pServerInfo->version);
696    }
697    
698    void lscp_server_info_reset ( lscp_server_info_t *pServerInfo )
699    {
700        lscp_server_info_free(pServerInfo);
701        lscp_server_info_init(pServerInfo);
702    }
703    
704    
705  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
# Line 610  void lscp_engine_info_init ( lscp_engine Line 711  void lscp_engine_info_init ( lscp_engine
711      pEngineInfo->version     = NULL;      pEngineInfo->version     = NULL;
712  }  }
713    
714  void lscp_engine_info_reset ( lscp_engine_info_t *pEngineInfo )  void lscp_engine_info_free ( lscp_engine_info_t *pEngineInfo )
715  {  {
716      if (pEngineInfo->description)      if (pEngineInfo->description)
717          free(pEngineInfo->description);          free(pEngineInfo->description);
718      if (pEngineInfo->version)      if (pEngineInfo->version)
719          free(pEngineInfo->version);          free(pEngineInfo->version);
720    }
721    
722    void lscp_engine_info_reset ( lscp_engine_info_t *pEngineInfo )
723    {
724        lscp_engine_info_free(pEngineInfo);
725      lscp_engine_info_init(pEngineInfo);      lscp_engine_info_init(pEngineInfo);
726  }  }
727    
# Line 632  void lscp_channel_info_init ( lscp_chann Line 737  void lscp_channel_info_init ( lscp_chann
737      pChannelInfo->audio_routing     = NULL;      pChannelInfo->audio_routing     = NULL;
738      pChannelInfo->instrument_file   = NULL;      pChannelInfo->instrument_file   = NULL;
739      pChannelInfo->instrument_nr     = 0;      pChannelInfo->instrument_nr     = 0;
740        pChannelInfo->instrument_name   = NULL;
741      pChannelInfo->instrument_status = 0;      pChannelInfo->instrument_status = 0;
742      pChannelInfo->midi_device       = 0;      pChannelInfo->midi_device       = 0;
743      pChannelInfo->midi_port         = 0;      pChannelInfo->midi_port         = 0;
# Line 639  void lscp_channel_info_init ( lscp_chann Line 745  void lscp_channel_info_init ( lscp_chann
745      pChannelInfo->volume            = 0.0;      pChannelInfo->volume            = 0.0;
746  }  }
747    
748  void lscp_channel_info_reset ( lscp_channel_info_t *pChannelInfo )  void lscp_channel_info_free ( lscp_channel_info_t *pChannelInfo )
749  {  {
750      if (pChannelInfo->engine_name)      if (pChannelInfo->engine_name)
751          free(pChannelInfo->engine_name);          free(pChannelInfo->engine_name);
# Line 647  void lscp_channel_info_reset ( lscp_chan Line 753  void lscp_channel_info_reset ( lscp_chan
753          lscp_szsplit_destroy(pChannelInfo->audio_routing);          lscp_szsplit_destroy(pChannelInfo->audio_routing);
754      if (pChannelInfo->instrument_file)      if (pChannelInfo->instrument_file)
755          free(pChannelInfo->instrument_file);          free(pChannelInfo->instrument_file);
756        if (pChannelInfo->instrument_name)
757            free(pChannelInfo->instrument_name);
758    }
759    
760    void lscp_channel_info_reset ( lscp_channel_info_t *pChannelInfo )
761    {
762        lscp_channel_info_free(pChannelInfo);
763      lscp_channel_info_init(pChannelInfo);      lscp_channel_info_init(pChannelInfo);
764  }  }
765    
# Line 662  void lscp_driver_info_init ( lscp_driver Line 774  void lscp_driver_info_init ( lscp_driver
774      pDriverInfo->parameters  = NULL;      pDriverInfo->parameters  = NULL;
775  }  }
776    
777  void lscp_driver_info_reset ( lscp_driver_info_t *pDriverInfo )  void lscp_driver_info_free ( lscp_driver_info_t *pDriverInfo )
778  {  {
779      if (pDriverInfo->description)      if (pDriverInfo->description)
780          free(pDriverInfo->description);          free(pDriverInfo->description);
781      if (pDriverInfo->version)      if (pDriverInfo->version)
782          free(pDriverInfo->version);          free(pDriverInfo->version);
783      lscp_szsplit_destroy(pDriverInfo->parameters);      lscp_szsplit_destroy(pDriverInfo->parameters);
784    }
785    
786    void lscp_driver_info_reset ( lscp_driver_info_t *pDriverInfo )
787    {
788        lscp_driver_info_free(pDriverInfo);
789      lscp_driver_info_init(pDriverInfo);      lscp_driver_info_init(pDriverInfo);
790  }  }
791    
# Line 683  void lscp_device_info_init ( lscp_device Line 799  void lscp_device_info_init ( lscp_device
799      lscp_plist_alloc(&(pDeviceInfo->params));      lscp_plist_alloc(&(pDeviceInfo->params));
800  }  }
801    
802  void lscp_device_info_reset ( lscp_device_info_t *pDeviceInfo )  void lscp_device_info_free ( lscp_device_info_t *pDeviceInfo )
803  {  {
804      if (pDeviceInfo->driver)      if (pDeviceInfo->driver)
805          free(pDeviceInfo->driver);          free(pDeviceInfo->driver);
806      lscp_plist_free(&(pDeviceInfo->params));      lscp_plist_free(&(pDeviceInfo->params));
807    }
808    
809    void lscp_device_info_reset ( lscp_device_info_t *pDeviceInfo )
810    {
811        lscp_device_info_free(pDeviceInfo);
812      lscp_device_info_init(pDeviceInfo);      lscp_device_info_init(pDeviceInfo);
813  }  }
814    
# Line 702  void lscp_device_port_info_init ( lscp_d Line 822  void lscp_device_port_info_init ( lscp_d
822      lscp_plist_alloc(&(pDevicePortInfo->params));      lscp_plist_alloc(&(pDevicePortInfo->params));
823  }  }
824    
825  void lscp_device_port_info_reset ( lscp_device_port_info_t *pDevicePortInfo )  void lscp_device_port_info_free ( lscp_device_port_info_t *pDevicePortInfo )
826  {  {
827      if (pDevicePortInfo->name)      if (pDevicePortInfo->name)
828          free(pDevicePortInfo->name);          free(pDevicePortInfo->name);
829      lscp_plist_free(&(pDevicePortInfo->params));      lscp_plist_free(&(pDevicePortInfo->params));
830    }
831    
832    void lscp_device_port_info_reset ( lscp_device_port_info_t *pDevicePortInfo )
833    {
834        lscp_device_port_info_free(pDevicePortInfo);
835      lscp_device_port_info_init(pDevicePortInfo);      lscp_device_port_info_init(pDevicePortInfo);
836  }  }
837    
# Line 729  void lscp_param_info_init ( lscp_param_i Line 853  void lscp_param_info_init ( lscp_param_i
853      pParamInfo->possibilities = NULL;      pParamInfo->possibilities = NULL;
854  }  }
855    
856  void lscp_param_info_reset ( lscp_param_info_t *pParamInfo )  void lscp_param_info_free ( lscp_param_info_t *pParamInfo )
857  {  {
858      if (pParamInfo->description)      if (pParamInfo->description)
859          free(pParamInfo->description);          free(pParamInfo->description);
# Line 741  void lscp_param_info_reset ( lscp_param_ Line 865  void lscp_param_info_reset ( lscp_param_
865      if (pParamInfo->range_max)      if (pParamInfo->range_max)
866          free(pParamInfo->range_max);          free(pParamInfo->range_max);
867      lscp_szsplit_destroy(pParamInfo->possibilities);      lscp_szsplit_destroy(pParamInfo->possibilities);
868        }
869    
870    void lscp_param_info_reset ( lscp_param_info_t *pParamInfo )
871    {
872        lscp_param_info_free(pParamInfo);
873      lscp_param_info_init(pParamInfo);      lscp_param_info_init(pParamInfo);
874  }  }
875    
# Line 754  int lscp_param_concat ( char *pszBuffer, Line 882  int lscp_param_concat ( char *pszBuffer,
882  {  {
883      int cchBuffer, cchParam, i;      int cchBuffer, cchParam, i;
884    
885      if (pszBuffer == NULL || pParams == NULL)      if (pszBuffer == NULL)
886          return 0;          return 0;
887    
888      cchBuffer = strlen(pszBuffer);      cchBuffer = strlen(pszBuffer);
889      for (i = 0; pParams[i].key && pParams[i].value; i++) {      for (i = 0; pParams && pParams[i].key && pParams[i].value; i++) {
890          cchParam = strlen(pParams[i].key) + strlen(pParams[i].value) + 4;          cchParam = strlen(pParams[i].key) + strlen(pParams[i].value) + 4;
891          if (cchBuffer + cchParam + 2 < cchMaxBuffer) {          if (cchBuffer + cchParam + 2 < cchMaxBuffer) {
892              sprintf(pszBuffer + cchBuffer, " %s='%s'", pParams[i].key, pParams[i].value);              sprintf(pszBuffer + cchBuffer, " %s='%s'", pParams[i].key, pParams[i].value);
# Line 769  int lscp_param_concat ( char *pszBuffer, Line 897  int lscp_param_concat ( char *pszBuffer,
897      if (cchBuffer + 2 < cchMaxBuffer) {      if (cchBuffer + 2 < cchMaxBuffer) {
898          pszBuffer[cchBuffer++] = '\r';          pszBuffer[cchBuffer++] = '\r';
899          pszBuffer[cchBuffer++] = '\n';          pszBuffer[cchBuffer++] = '\n';
900            pszBuffer[cchBuffer ]  = (char) 0;
901      }      }
902            
903      return cchBuffer;      return cchBuffer;

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

  ViewVC Help
Powered by ViewVC