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 |
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; |
136 |
// Send data, and then, wait for the result... |
// Send data, and then, wait for the result... |
137 |
cchQuery = strlen(pszQuery); |
cchQuery = strlen(pszQuery); |
138 |
if (send(pClient->cmd.sock, pszQuery, cchQuery, 0) < cchQuery) { |
if (send(pClient->cmd.sock, pszQuery, cchQuery, 0) < cchQuery) { |
139 |
lscp_socket_perror("_lscp_client_call: send"); |
lscp_socket_perror("lscp_client_call: send"); |
140 |
pszResult = "Failure during send operation"; |
pszResult = "Failure during send operation"; |
141 |
lscp_client_set_result(pClient, pszResult, iErrno); |
lscp_client_set_result(pClient, pszResult, iErrno); |
142 |
return ret; |
return ret; |
143 |
} |
} |
144 |
|
|
145 |
// Prepare for waiting on select... |
// Wait for receive event... |
146 |
fd = (int) pClient->cmd.sock; |
cchResult = sizeof(achResult); |
147 |
FD_ZERO(&fds); |
ret = lscp_client_recv(pClient, achResult, &cchResult, pClient->iTimeout); |
148 |
FD_SET((unsigned int) fd, &fds); |
|
149 |
fdmax = fd; |
switch (ret) { |
150 |
|
|
151 |
// Use the timeout select feature... |
case LSCP_OK: |
152 |
iTimeout = pClient->iTimeout; |
// Always force the result to be null terminated (and trim trailing CRLFs)! |
153 |
if (iTimeout > 1000) { |
while (cchResult > 0 && (achResult[cchResult - 1] == '\n' || achResult[cchResult- 1] == '\r')) |
154 |
tv.tv_sec = iTimeout / 1000; |
cchResult--; |
155 |
iTimeout -= tv.tv_sec * 1000; |
achResult[cchResult] = (char) 0; |
156 |
} |
// Check if the response it's an error or warning message. |
157 |
else tv.tv_sec = 0; |
if (strncasecmp(achResult, "WRN:", 4) == 0) |
158 |
tv.tv_usec = iTimeout * 1000; |
ret = LSCP_WARNING; |
159 |
|
else if (strncasecmp(achResult, "ERR:", 4) == 0) |
160 |
// Wait for event... |
ret = LSCP_ERROR; |
161 |
iSelect = select(fdmax + 1, &fds, NULL, NULL, &tv); |
// So we got a result... |
162 |
if (iSelect > 0 && FD_ISSET(fd, &fds)) { |
if (ret == LSCP_OK) { |
163 |
// May recv now... |
// Reset errno in case of success. |
164 |
cchResult = recv(pClient->cmd.sock, achResult, sizeof(achResult), 0); |
iErrno = 0; |
165 |
if (cchResult > 0) { |
// Is it a special successful response? |
166 |
// Assume early success. |
if (strncasecmp(achResult, "OK[", 3) == 0) { |
167 |
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... |
|
168 |
pszToken = lscp_strtok(achResult, pszSeps, &(pch)); |
pszToken = lscp_strtok(achResult, pszSeps, &(pch)); |
169 |
|
if (pszToken) |
170 |
|
pszResult = lscp_strtok(NULL, pszSeps, &(pch)); |
171 |
|
} |
172 |
|
else pszResult = achResult; |
173 |
|
// The result string is now set to the command response, if any. |
174 |
|
} else { |
175 |
|
// Parse the error/warning message, skip first colon... |
176 |
|
pszToken = lscp_strtok(achResult, pszSeps, &(pch)); |
177 |
|
if (pszToken) { |
178 |
|
// Get the error number... |
179 |
|
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
180 |
if (pszToken) { |
if (pszToken) { |
181 |
// Get the error number... |
iErrno = atoi(pszToken); |
182 |
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
// And make the message text our final result. |
183 |
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)); |
|
|
} |
|
184 |
} |
} |
|
// The result string is set to the error/warning message text. |
|
185 |
} |
} |
186 |
|
// The result string is set to the error/warning message text. |
187 |
} |
} |
188 |
else if (cchResult == 0) { |
break; |
189 |
// Damn, server disconnected, we better free everything down here. |
|
190 |
lscp_socket_agent_free(&(pClient->evt)); |
case LSCP_TIMEOUT: |
|
lscp_socket_agent_free(&(pClient->cmd)); |
|
|
// Fake a result message. |
|
|
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) { |
|
191 |
// Fake a result message. |
// Fake a result message. |
|
ret = LSCP_TIMEOUT; |
|
192 |
pszResult = "Timeout during receive operation"; |
pszResult = "Timeout during receive operation"; |
193 |
iErrno = (int) ret; |
iErrno = (int) ret; |
194 |
} |
break; |
195 |
else lscp_socket_perror("_lscp_client_call: select"); |
|
196 |
|
case LSCP_QUIT: |
197 |
|
// Fake a result message. |
198 |
|
pszResult = "Server terminated the connection"; |
199 |
|
iErrno = (int) ret; |
200 |
|
break; |
201 |
|
|
202 |
|
case LSCP_FAILED: |
203 |
|
default: |
204 |
|
// What's down? |
205 |
|
pszResult = "Failure during receive operation"; |
206 |
|
break; |
207 |
|
} |
208 |
|
|
209 |
// Make the result official... |
// Make the result official... |
210 |
lscp_client_set_result(pClient, pszResult, iErrno); |
lscp_client_set_result(pClient, pszResult, iErrno); |
257 |
return psz; |
return psz; |
258 |
} |
} |
259 |
|
|
260 |
|
// Unquote and make a duplicate of an in-split string. |
261 |
|
void lscp_unquote_dup ( char **ppszDst, char **ppszSrc ) |
262 |
|
{ |
263 |
|
// Free desteny string, if already there. |
264 |
|
if (*ppszDst) |
265 |
|
free(*ppszDst); |
266 |
|
*ppszDst = NULL; |
267 |
|
// Unquote and duplicate. |
268 |
|
if (*ppszSrc) |
269 |
|
*ppszDst = lscp_unquote(ppszSrc, 1); |
270 |
|
} |
271 |
|
|
272 |
|
|
273 |
// Custom tokenizer. |
// Custom tokenizer. |
274 |
char *lscp_strtok ( char *pchBuffer, const char *pszSeps, char **ppch ) |
char *lscp_strtok ( char *pchBuffer, const char *pszSeps, char **ppch ) |
329 |
--pch; |
--pch; |
330 |
*pch = (char) 0; |
*pch = (char) 0; |
331 |
// Make it official. |
// Make it official. |
332 |
ppszSplit[i++] = lscp_unquote(&pszHead, 0); |
ppszSplit[i] = lscp_unquote(&pszHead, 0); |
333 |
// Do we need to grow? |
// Do we need to grow? |
334 |
if (i >= iSize) { |
if (++i >= iSize) { |
335 |
// Yes, but only grow in chunks. |
// Yes, but only grow in chunks. |
336 |
iSize += LSCP_SPLIT_CHUNK1; |
iSize += LSCP_SPLIT_CHUNK1; |
337 |
// Allocate and copy to new split array. |
// Allocate and copy to new split array. |
392 |
int iSize, i, j, cchSeps; |
int iSize, i, j, cchSeps; |
393 |
int *piSplit, *piNewSplit; |
int *piSplit, *piNewSplit; |
394 |
|
|
395 |
|
// Get it clean first. |
396 |
|
pchHead = lscp_ltrim((char *) pszCsv); |
397 |
|
if (*pchHead == (char) 0) |
398 |
|
return NULL; |
399 |
|
|
400 |
// Initial size is one chunk away. |
// Initial size is one chunk away. |
401 |
iSize = LSCP_SPLIT_CHUNK1; |
iSize = LSCP_SPLIT_CHUNK1; |
402 |
// Allocate and split... |
// Allocate and split... |
406 |
|
|
407 |
// Make a copy of the original string. |
// Make a copy of the original string. |
408 |
i = 0; |
i = 0; |
|
pchHead = (char *) pszCsv; |
|
409 |
if ((piSplit[i++] = atoi(pchHead)) < 0) { |
if ((piSplit[i++] = atoi(pchHead)) < 0) { |
410 |
free(piSplit); |
free(piSplit); |
411 |
return NULL; |
return NULL; |
417 |
// Pre-advance to next item. |
// Pre-advance to next item. |
418 |
pchHead = pch + cchSeps; |
pchHead = pch + cchSeps; |
419 |
// Make it official. |
// Make it official. |
420 |
piSplit[i++] = atoi(pchHead); |
piSplit[i] = atoi(pchHead); |
421 |
// Do we need to grow? |
// Do we need to grow? |
422 |
if (i >= iSize) { |
if (++i >= iSize) { |
423 |
// Yes, but only grow in chunks. |
// Yes, but only grow in chunks. |
424 |
iSize += LSCP_SPLIT_CHUNK1; |
iSize += LSCP_SPLIT_CHUNK1; |
425 |
// Allocate and copy to new split array. |
// Allocate and copy to new split array. |
581 |
{ |
{ |
582 |
lscp_param_t *pParams; |
lscp_param_t *pParams; |
583 |
int i; |
int i; |
584 |
|
|
585 |
if (ppList) { |
if (ppList) { |
586 |
if (*ppList) { |
if (*ppList) { |
587 |
pParams = *ppList; |
pParams = *ppList; |
603 |
lscp_param_t *pNewParams; |
lscp_param_t *pNewParams; |
604 |
int iSize, iNewSize; |
int iSize, iNewSize; |
605 |
int i = 0; |
int i = 0; |
606 |
|
|
607 |
if (ppList && *ppList) { |
if (ppList && *ppList) { |
608 |
pParams = *ppList; |
pParams = *ppList; |
609 |
while (pParams[i].key) |
while (pParams[i].key) { |
610 |
|
if (strcasecmp(pParams[i].key, pszKey) == 0) { |
611 |
|
if (pParams[i].value) |
612 |
|
free(pParams[i].value); |
613 |
|
pParams[i].value = strdup(pszValue); |
614 |
|
return; |
615 |
|
} |
616 |
i++; |
i++; |
617 |
|
} |
618 |
iSize = LSCP_SPLIT_SIZE(i); |
iSize = LSCP_SPLIT_SIZE(i); |
619 |
pParams[i].key = strdup(pszKey); |
pParams[i].key = strdup(pszKey); |
620 |
pParams[i].value = strdup(pszValue); |
pParams[i].value = strdup(pszValue); |
622 |
iNewSize = iSize + LSCP_SPLIT_CHUNK1; |
iNewSize = iSize + LSCP_SPLIT_CHUNK1; |
623 |
pNewParams = (lscp_param_t *) malloc(iNewSize * sizeof(lscp_param_t)); |
pNewParams = (lscp_param_t *) malloc(iNewSize * sizeof(lscp_param_t)); |
624 |
for (i = 0; i < iSize; i++) { |
for (i = 0; i < iSize; i++) { |
625 |
pParams[i].key = pParams[i].key; |
pNewParams[i].key = pParams[i].key; |
626 |
pParams[i].value = pParams[i].value; |
pNewParams[i].value = pParams[i].value; |
627 |
} |
} |
628 |
for ( ; i < iNewSize; i++) { |
for ( ; i < iNewSize; i++) { |
629 |
pNewParams[i].key = NULL; |
pNewParams[i].key = NULL; |
635 |
} |
} |
636 |
} |
} |
637 |
|
|
638 |
|
#ifdef LSCP_PLIST_COUNT |
639 |
|
|
640 |
// Compute a parameter list valid item count. |
// Compute a parameter list valid item count. |
641 |
int lscp_plist_count ( lscp_param_t **ppList ) |
int lscp_plist_count ( lscp_param_t **ppList ) |
650 |
return i; |
return i; |
651 |
} |
} |
652 |
|
|
|
|
|
653 |
// Compute the legal parameter list size. |
// Compute the legal parameter list size. |
654 |
int lscp_plist_size ( lscp_param_t **ppList ) |
int lscp_plist_size ( lscp_param_t **ppList ) |
655 |
{ |
{ |
656 |
return LSCP_SPLIT_SIZE(lscp_plist_count(ppList)); |
return LSCP_SPLIT_SIZE(lscp_plist_count(ppList)); |
657 |
} |
} |
658 |
|
|
659 |
|
#endif // LSCP_PLIST_COUNT |
660 |
|
|
661 |
|
|
662 |
|
//------------------------------------------------------------------------- |
663 |
|
// Server info struct helper functions. |
664 |
|
|
665 |
|
void lscp_server_info_init ( lscp_server_info_t *pServerInfo ) |
666 |
|
{ |
667 |
|
pServerInfo->description = NULL; |
668 |
|
pServerInfo->version = NULL; |
669 |
|
} |
670 |
|
|
671 |
|
void lscp_server_info_free ( lscp_server_info_t *pServerInfo ) |
672 |
|
{ |
673 |
|
if (pServerInfo->description) |
674 |
|
free(pServerInfo->description); |
675 |
|
if (pServerInfo->version) |
676 |
|
free(pServerInfo->version); |
677 |
|
} |
678 |
|
|
679 |
|
void lscp_server_info_reset ( lscp_server_info_t *pServerInfo ) |
680 |
|
{ |
681 |
|
lscp_server_info_free(pServerInfo); |
682 |
|
lscp_server_info_init(pServerInfo); |
683 |
|
} |
684 |
|
|
685 |
|
|
686 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
692 |
pEngineInfo->version = NULL; |
pEngineInfo->version = NULL; |
693 |
} |
} |
694 |
|
|
695 |
void lscp_engine_info_reset ( lscp_engine_info_t *pEngineInfo ) |
void lscp_engine_info_free ( lscp_engine_info_t *pEngineInfo ) |
696 |
{ |
{ |
697 |
if (pEngineInfo->description) |
if (pEngineInfo->description) |
698 |
free(pEngineInfo->description); |
free(pEngineInfo->description); |
699 |
if (pEngineInfo->version) |
if (pEngineInfo->version) |
700 |
free(pEngineInfo->version); |
free(pEngineInfo->version); |
701 |
|
} |
702 |
|
|
703 |
|
void lscp_engine_info_reset ( lscp_engine_info_t *pEngineInfo ) |
704 |
|
{ |
705 |
|
lscp_engine_info_free(pEngineInfo); |
706 |
lscp_engine_info_init(pEngineInfo); |
lscp_engine_info_init(pEngineInfo); |
707 |
} |
} |
708 |
|
|
718 |
pChannelInfo->audio_routing = NULL; |
pChannelInfo->audio_routing = NULL; |
719 |
pChannelInfo->instrument_file = NULL; |
pChannelInfo->instrument_file = NULL; |
720 |
pChannelInfo->instrument_nr = 0; |
pChannelInfo->instrument_nr = 0; |
721 |
|
pChannelInfo->instrument_name = NULL; |
722 |
pChannelInfo->instrument_status = 0; |
pChannelInfo->instrument_status = 0; |
723 |
pChannelInfo->midi_device = 0; |
pChannelInfo->midi_device = 0; |
724 |
pChannelInfo->midi_port = 0; |
pChannelInfo->midi_port = 0; |
726 |
pChannelInfo->volume = 0.0; |
pChannelInfo->volume = 0.0; |
727 |
} |
} |
728 |
|
|
729 |
void lscp_channel_info_reset ( lscp_channel_info_t *pChannelInfo ) |
void lscp_channel_info_free ( lscp_channel_info_t *pChannelInfo ) |
730 |
{ |
{ |
731 |
if (pChannelInfo->engine_name) |
if (pChannelInfo->engine_name) |
732 |
free(pChannelInfo->engine_name); |
free(pChannelInfo->engine_name); |
734 |
lscp_szsplit_destroy(pChannelInfo->audio_routing); |
lscp_szsplit_destroy(pChannelInfo->audio_routing); |
735 |
if (pChannelInfo->instrument_file) |
if (pChannelInfo->instrument_file) |
736 |
free(pChannelInfo->instrument_file); |
free(pChannelInfo->instrument_file); |
737 |
|
if (pChannelInfo->instrument_name) |
738 |
|
free(pChannelInfo->instrument_name); |
739 |
|
} |
740 |
|
|
741 |
|
void lscp_channel_info_reset ( lscp_channel_info_t *pChannelInfo ) |
742 |
|
{ |
743 |
|
lscp_channel_info_free(pChannelInfo); |
744 |
lscp_channel_info_init(pChannelInfo); |
lscp_channel_info_init(pChannelInfo); |
745 |
} |
} |
746 |
|
|
755 |
pDriverInfo->parameters = NULL; |
pDriverInfo->parameters = NULL; |
756 |
} |
} |
757 |
|
|
758 |
void lscp_driver_info_reset ( lscp_driver_info_t *pDriverInfo ) |
void lscp_driver_info_free ( lscp_driver_info_t *pDriverInfo ) |
759 |
{ |
{ |
760 |
if (pDriverInfo->description) |
if (pDriverInfo->description) |
761 |
free(pDriverInfo->description); |
free(pDriverInfo->description); |
762 |
if (pDriverInfo->version) |
if (pDriverInfo->version) |
763 |
free(pDriverInfo->version); |
free(pDriverInfo->version); |
764 |
lscp_szsplit_destroy(pDriverInfo->parameters); |
lscp_szsplit_destroy(pDriverInfo->parameters); |
765 |
|
} |
766 |
|
|
767 |
|
void lscp_driver_info_reset ( lscp_driver_info_t *pDriverInfo ) |
768 |
|
{ |
769 |
|
lscp_driver_info_free(pDriverInfo); |
770 |
lscp_driver_info_init(pDriverInfo); |
lscp_driver_info_init(pDriverInfo); |
771 |
} |
} |
772 |
|
|
780 |
lscp_plist_alloc(&(pDeviceInfo->params)); |
lscp_plist_alloc(&(pDeviceInfo->params)); |
781 |
} |
} |
782 |
|
|
783 |
void lscp_device_info_reset ( lscp_device_info_t *pDeviceInfo ) |
void lscp_device_info_free ( lscp_device_info_t *pDeviceInfo ) |
784 |
{ |
{ |
785 |
if (pDeviceInfo->driver) |
if (pDeviceInfo->driver) |
786 |
free(pDeviceInfo->driver); |
free(pDeviceInfo->driver); |
787 |
lscp_plist_free(&(pDeviceInfo->params)); |
lscp_plist_free(&(pDeviceInfo->params)); |
788 |
|
} |
789 |
|
|
790 |
|
void lscp_device_info_reset ( lscp_device_info_t *pDeviceInfo ) |
791 |
|
{ |
792 |
|
lscp_device_info_free(pDeviceInfo); |
793 |
lscp_device_info_init(pDeviceInfo); |
lscp_device_info_init(pDeviceInfo); |
794 |
} |
} |
795 |
|
|
803 |
lscp_plist_alloc(&(pDevicePortInfo->params)); |
lscp_plist_alloc(&(pDevicePortInfo->params)); |
804 |
} |
} |
805 |
|
|
806 |
void lscp_device_port_info_reset ( lscp_device_port_info_t *pDevicePortInfo ) |
void lscp_device_port_info_free ( lscp_device_port_info_t *pDevicePortInfo ) |
807 |
{ |
{ |
808 |
if (pDevicePortInfo->name) |
if (pDevicePortInfo->name) |
809 |
free(pDevicePortInfo->name); |
free(pDevicePortInfo->name); |
810 |
lscp_plist_free(&(pDevicePortInfo->params)); |
lscp_plist_free(&(pDevicePortInfo->params)); |
811 |
|
} |
812 |
|
|
813 |
|
void lscp_device_port_info_reset ( lscp_device_port_info_t *pDevicePortInfo ) |
814 |
|
{ |
815 |
|
lscp_device_port_info_free(pDevicePortInfo); |
816 |
lscp_device_port_info_init(pDevicePortInfo); |
lscp_device_port_info_init(pDevicePortInfo); |
817 |
} |
} |
818 |
|
|
834 |
pParamInfo->possibilities = NULL; |
pParamInfo->possibilities = NULL; |
835 |
} |
} |
836 |
|
|
837 |
void lscp_param_info_reset ( lscp_param_info_t *pParamInfo ) |
void lscp_param_info_free ( lscp_param_info_t *pParamInfo ) |
838 |
{ |
{ |
839 |
if (pParamInfo->description) |
if (pParamInfo->description) |
840 |
free(pParamInfo->description); |
free(pParamInfo->description); |
846 |
if (pParamInfo->range_max) |
if (pParamInfo->range_max) |
847 |
free(pParamInfo->range_max); |
free(pParamInfo->range_max); |
848 |
lscp_szsplit_destroy(pParamInfo->possibilities); |
lscp_szsplit_destroy(pParamInfo->possibilities); |
849 |
|
} |
850 |
|
|
851 |
|
void lscp_param_info_reset ( lscp_param_info_t *pParamInfo ) |
852 |
|
{ |
853 |
|
lscp_param_info_free(pParamInfo); |
854 |
lscp_param_info_init(pParamInfo); |
lscp_param_info_init(pParamInfo); |
855 |
} |
} |
856 |
|
|
863 |
{ |
{ |
864 |
int cchBuffer, cchParam, i; |
int cchBuffer, cchParam, i; |
865 |
|
|
866 |
if (pszBuffer == NULL || pParams == NULL) |
if (pszBuffer == NULL) |
867 |
return 0; |
return 0; |
868 |
|
|
869 |
cchBuffer = strlen(pszBuffer); |
cchBuffer = strlen(pszBuffer); |
870 |
for (i = 0; pParams[i].key && pParams[i].value; i++) { |
for (i = 0; pParams && pParams[i].key && pParams[i].value; i++) { |
871 |
cchParam = strlen(pParams[i].key) + strlen(pParams[i].value) + 4; |
cchParam = strlen(pParams[i].key) + strlen(pParams[i].value) + 4; |
872 |
if (cchBuffer + cchParam + 2 < cchMaxBuffer) { |
if (cchBuffer + cchParam + 2 < cchMaxBuffer) { |
873 |
sprintf(pszBuffer + cchBuffer, " %s='%s'", pParams[i].key, pParams[i].value); |
sprintf(pszBuffer + cchBuffer, " %s='%s'", pParams[i].key, pParams[i].value); |
878 |
if (cchBuffer + 2 < cchMaxBuffer) { |
if (cchBuffer + 2 < cchMaxBuffer) { |
879 |
pszBuffer[cchBuffer++] = '\r'; |
pszBuffer[cchBuffer++] = '\r'; |
880 |
pszBuffer[cchBuffer++] = '\n'; |
pszBuffer[cchBuffer++] = '\n'; |
881 |
|
pszBuffer[cchBuffer ] = (char) 0; |
882 |
} |
} |
883 |
|
|
884 |
return cchBuffer; |
return cchBuffer; |