506 |
#endif // LSCP_PSPLIT_COUNT |
#endif // LSCP_PSPLIT_COUNT |
507 |
|
|
508 |
|
|
509 |
|
// Allocate a parameter list, optionally copying an existing one. |
510 |
|
void lscp_plist_alloc (lscp_param_t **ppList) |
511 |
|
{ |
512 |
|
lscp_param_t *pParams; |
513 |
|
int iSize, i; |
514 |
|
|
515 |
|
if (ppList) { |
516 |
|
iSize = LSCP_SPLIT_CHUNK1; |
517 |
|
pParams = (lscp_param_t *) malloc(iSize * sizeof(lscp_param_t)); |
518 |
|
if (pParams) { |
519 |
|
for (i = 0 ; i < iSize; i++) { |
520 |
|
pParams[i].key = NULL; |
521 |
|
pParams[i].value = NULL; |
522 |
|
} |
523 |
|
} |
524 |
|
*ppList = pParams; |
525 |
|
} |
526 |
|
} |
527 |
|
|
528 |
|
|
529 |
|
// Destroy a parameter list, including all it's contents. |
530 |
|
void lscp_plist_free ( lscp_param_t **ppList ) |
531 |
|
{ |
532 |
|
lscp_param_t *pParams; |
533 |
|
int i; |
534 |
|
|
535 |
|
if (ppList) { |
536 |
|
if (*ppList) { |
537 |
|
pParams = *ppList; |
538 |
|
for (i = 0; pParams && pParams[i].key; i++) { |
539 |
|
free(pParams[i].key); |
540 |
|
free(pParams[i].value); |
541 |
|
} |
542 |
|
free(pParams); |
543 |
|
} |
544 |
|
*ppList = NULL; |
545 |
|
} |
546 |
|
} |
547 |
|
|
548 |
|
|
549 |
|
// Add an item to a parameter list, growing it as fit. |
550 |
|
void lscp_plist_append ( lscp_param_t **ppList, const char *pszKey, const char *pszValue ) |
551 |
|
{ |
552 |
|
lscp_param_t *pParams; |
553 |
|
lscp_param_t *pNewParams; |
554 |
|
int iSize, iNewSize; |
555 |
|
int i = 0; |
556 |
|
|
557 |
|
if (ppList && *ppList) { |
558 |
|
pParams = *ppList; |
559 |
|
while (pParams[i].key) |
560 |
|
i++; |
561 |
|
iSize = LSCP_SPLIT_SIZE(i); |
562 |
|
pParams[i].key = strdup(pszKey); |
563 |
|
pParams[i].value = strdup(pszValue); |
564 |
|
if (++i >= iSize) { |
565 |
|
iNewSize = iSize + LSCP_SPLIT_CHUNK1; |
566 |
|
pNewParams = (lscp_param_t *) malloc(iNewSize * sizeof(lscp_param_t)); |
567 |
|
for (i = 0; i < iSize; i++) { |
568 |
|
pParams[i].key = pParams[i].key; |
569 |
|
pParams[i].value = pParams[i].value; |
570 |
|
} |
571 |
|
for ( ; i < iNewSize; i++) { |
572 |
|
pNewParams[i].key = NULL; |
573 |
|
pNewParams[i].value = NULL; |
574 |
|
} |
575 |
|
free(pParams); |
576 |
|
*ppList = pNewParams; |
577 |
|
} |
578 |
|
} |
579 |
|
} |
580 |
|
|
581 |
|
|
582 |
|
// Compute a parameter list valid item count. |
583 |
|
int lscp_plist_count ( lscp_param_t **ppList ) |
584 |
|
{ |
585 |
|
lscp_param_t *pParams; |
586 |
|
int i = 0; |
587 |
|
if (ppList && *ppList) { |
588 |
|
pParams = *ppList; |
589 |
|
while (pParams[i].key) |
590 |
|
i++; |
591 |
|
} |
592 |
|
return i; |
593 |
|
} |
594 |
|
|
595 |
|
|
596 |
|
// Compute the legal parameter list size. |
597 |
|
int lscp_plist_size ( lscp_param_t **ppList ) |
598 |
|
{ |
599 |
|
return LSCP_SPLIT_SIZE(lscp_plist_count(ppList)); |
600 |
|
} |
601 |
|
|
602 |
|
|
603 |
|
|
604 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
605 |
// Engine info struct helper functions. |
// Engine info struct helper functions. |
606 |
|
|
675 |
|
|
676 |
|
|
677 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
678 |
|
// Device info struct functions. |
679 |
|
|
680 |
|
void lscp_device_info_init ( lscp_device_info_t *pDeviceInfo ) |
681 |
|
{ |
682 |
|
pDeviceInfo->driver = NULL; |
683 |
|
lscp_plist_alloc(&(pDeviceInfo->params)); |
684 |
|
} |
685 |
|
|
686 |
|
void lscp_device_info_reset ( lscp_device_info_t *pDeviceInfo ) |
687 |
|
{ |
688 |
|
if (pDeviceInfo->driver) |
689 |
|
free(pDeviceInfo->driver); |
690 |
|
lscp_plist_free(&(pDeviceInfo->params)); |
691 |
|
|
692 |
|
lscp_device_info_init(pDeviceInfo); |
693 |
|
} |
694 |
|
|
695 |
|
|
696 |
|
//------------------------------------------------------------------------- |
697 |
|
// Device channel/port info struct functions. |
698 |
|
|
699 |
|
void lscp_device_port_info_init ( lscp_device_port_info_t *pDevicePortInfo ) |
700 |
|
{ |
701 |
|
pDevicePortInfo->name = NULL; |
702 |
|
lscp_plist_alloc(&(pDevicePortInfo->params)); |
703 |
|
} |
704 |
|
|
705 |
|
void lscp_device_port_info_reset ( lscp_device_port_info_t *pDevicePortInfo ) |
706 |
|
{ |
707 |
|
if (pDevicePortInfo->name) |
708 |
|
free(pDevicePortInfo->name); |
709 |
|
lscp_plist_free(&(pDevicePortInfo->params)); |
710 |
|
|
711 |
|
lscp_device_port_info_init(pDevicePortInfo); |
712 |
|
} |
713 |
|
|
714 |
|
|
715 |
|
//------------------------------------------------------------------------- |
716 |
// Parameter struct helper functions. |
// Parameter struct helper functions. |
717 |
|
|
718 |
void lscp_param_info_init ( lscp_param_info_t *pParamInfo ) |
void lscp_param_info_init ( lscp_param_info_t *pParamInfo ) |
747 |
|
|
748 |
|
|
749 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
750 |
// Concatenate a parameter list (key='value'...) into a string. |
// Concatenate a parameter list (key='value'...) into a string, |
751 |
|
// appending a crlf terminator. |
752 |
|
|
753 |
int lscp_param_concat ( char *pszBuffer, int cchMaxBuffer, lscp_param_t *pParams ) |
int lscp_param_concat ( char *pszBuffer, int cchMaxBuffer, lscp_param_t *pParams ) |
754 |
{ |
{ |
760 |
cchBuffer = strlen(pszBuffer); |
cchBuffer = strlen(pszBuffer); |
761 |
for (i = 0; pParams[i].key && pParams[i].value; i++) { |
for (i = 0; pParams[i].key && pParams[i].value; i++) { |
762 |
cchParam = strlen(pParams[i].key) + strlen(pParams[i].value) + 4; |
cchParam = strlen(pParams[i].key) + strlen(pParams[i].value) + 4; |
763 |
if (cchBuffer + cchParam < cchMaxBuffer) { |
if (cchBuffer + cchParam + 2 < cchMaxBuffer) { |
764 |
sprintf(pszBuffer + cchBuffer, " %s='%s'", pParams[i].key, pParams[i].value); |
sprintf(pszBuffer + cchBuffer, " %s='%s'", pParams[i].key, pParams[i].value); |
765 |
cchBuffer += cchParam; |
cchBuffer += cchParam; |
766 |
} |
} |
767 |
} |
} |
768 |
|
|
769 |
|
if (cchBuffer + 2 < cchMaxBuffer) { |
770 |
|
pszBuffer[cchBuffer++] = '\r'; |
771 |
|
pszBuffer[cchBuffer++] = '\n'; |
772 |
|
} |
773 |
|
|
774 |
return cchBuffer; |
return cchBuffer; |
775 |
} |
} |
776 |
|
|