Initial setup for CLion

This commit is contained in:
2026-03-28 16:54:11 +11:00
parent 239cc02591
commit 7b4134133c
1136 changed files with 811916 additions and 0 deletions

181
MediaClient/bm/base64.cpp Normal file
View File

@@ -0,0 +1,181 @@
/***************************************************************************************
*
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
*
* By downloading, copying, installing or using the software you agree to this license.
* If you do not agree to this license, do not download, install,
* copy or use the software.
*
* Copyright (C) 2014-2024, Happytimesoft Corporation, all rights reserved.
*
* Redistribution and use in binary forms, with or without modification, are permitted.
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************************/
#include "sys_inc.h"
#include "base64.h"
const char *BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
void base64_encode_triple(uint8 triple[3], char result[4])
{
int tripleValue, i;
tripleValue = triple[0];
tripleValue *= 256;
tripleValue += triple[1];
tripleValue *= 256;
tripleValue += triple[2];
for (i=0; i<4; i++)
{
result[3-i] = BASE64_CHARS[tripleValue % 64];
tripleValue /= 64;
}
}
/**
* encode an array of bytes using Base64 (RFC 3548)
*
* @param source the source buffer
* @param sourcelen the length of the source buffer
* @param target the target buffer
* @param targetlen the length of the target buffer
* @return 1 on success, 0 otherwise
*/
HT_API int base64_encode(uint8 *source, uint32 sourcelen, char *target, uint32 targetlen)
{
/* check if the result will fit in the target buffer */
if ((sourcelen+2)/3*4 > targetlen-1)
{
return 0;
}
/* encode all full triples */
while (sourcelen >= 3)
{
base64_encode_triple(source, target);
sourcelen -= 3;
source += 3;
target += 4;
}
/* encode the last one or two characters */
if (sourcelen > 0)
{
uint8 temp[3];
memset(temp, 0, sizeof(temp));
memcpy(temp, source, sourcelen);
base64_encode_triple(temp, target);
target[3] = '=';
if (sourcelen == 1)
{
target[2] = '=';
}
target += 4;
}
/* terminate the string */
target[0] = 0;
return 1;
}
/**
* decode base64 encoded data
*
* @param source the encoded data (zero terminated)
* @param target pointer to the target buffer
* @param targetlen length of the target buffer
* @return length of converted data on success, -1 otherwise
*/
HT_API int base64_decode(const char *source, uint32 sourcelen, uint8 *target, uint32 targetlen)
{
const char *cur;
const char *max_src;
uint8 *dest, *max_dest;
int d, dlast, phase;
uint8 c;
static int table[256] = {
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 00-0F */
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 10-1F */
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63, /* 20-2F */
52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1, /* 30-3F */
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14, /* 40-4F */
15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1, /* 50-5F */
-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40, /* 60-6F */
41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1, /* 70-7F */
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 80-8F */
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 90-9F */
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* A0-AF */
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* B0-BF */
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* C0-CF */
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* D0-DF */
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* E0-EF */
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 /* F0-FF */
};
d = dlast = phase = 0;
dest = target;
max_dest = dest+targetlen;
max_src = source + sourcelen;
for (cur = source; *cur != '\0' && cur<max_src && dest<max_dest; ++cur)
{
if (*cur == '=')
{
dlast = phase = 0;
continue;
}
d = table[(int)*cur];
if (d != -1)
{
switch(phase)
{
case 0:
++phase;
break;
case 1:
c = (uint8)(((dlast << 2) | ((d & 0x30) >> 4)));
*dest++ = c;
++phase;
break;
case 2:
c = (((dlast & 0xf) << 4) | ((d & 0x3c) >> 2));
*dest++ = c;
++phase;
break;
case 3:
c = (uint8)((((dlast & 0x03 ) << 6) | d));
*dest++ = c;
phase = 0;
break;
}
dlast = d;
}
}
/* we decoded the whole buffer */
if (*cur == '\0' || cur == max_src)
{
return (int)(dest-target);
}
/* we did not convert the whole data, buffer was to small */
return -1;
}

37
MediaClient/bm/base64.h Normal file
View File

@@ -0,0 +1,37 @@
/***************************************************************************************
*
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
*
* By downloading, copying, installing or using the software you agree to this license.
* If you do not agree to this license, do not download, install,
* copy or use the software.
*
* Copyright (C) 2014-2024, Happytimesoft Corporation, all rights reserved.
*
* Redistribution and use in binary forms, with or without modification, are permitted.
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************************/
#ifndef BASE64_H
#define BASE64_H
#ifdef __cplusplus
extern "C" {
#endif
HT_API int base64_encode(uint8 *source, uint32 sourcelen, char *target, uint32 targetlen);
HT_API int base64_decode(const char *source, uint32 sourcelen, uint8 *target, uint32 targetlen);
#ifdef __cplusplus
}
#endif
#endif /* BASE64_H */

386
MediaClient/bm/hqueue.cpp Normal file
View File

@@ -0,0 +1,386 @@
/***************************************************************************************
*
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
*
* By downloading, copying, installing or using the software you agree to this license.
* If you do not agree to this license, do not download, install,
* copy or use the software.
*
* Copyright (C) 2014-2024, Happytimesoft Corporation, all rights reserved.
*
* Redistribution and use in binary forms, with or without modification, are permitted.
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************************/
#include "sys_inc.h"
#include "hqueue.h"
/***************************************************************************************/
HT_API HQUEUE * hqCreate(uint32 unit_num, uint32 unit_size, uint32 queue_mode)
{
uint32 q_len = unit_num * unit_size + sizeof(HQUEUE);
HQUEUE *phq = (HQUEUE *)malloc(q_len);
if (phq == NULL)
{
log_print(HT_LOG_ERR, "%s, malloc HQUEUE fail\r\n", __FUNCTION__);
return NULL;
}
phq->queue_mode = queue_mode;
phq->unit_size = unit_size;
phq->unit_num = unit_num;
phq->front = 0;
phq->rear = 0;
phq->count_put_full = 0;
phq->queue_buffer = sizeof(HQUEUE);
if (queue_mode & HQ_NO_EVENT)
{
phq->queue_nnulEvent = NULL;
phq->queue_nfulEvent = NULL;
phq->queue_putMutex = NULL;
}
else
{
phq->queue_nnulEvent = sys_os_create_sig();
phq->queue_nfulEvent = sys_os_create_sig();
phq->queue_putMutex = sys_os_create_mutex();
}
return phq;
}
HT_API void hqDelete(HQUEUE * phq)
{
if (phq == NULL)
{
return;
}
if (phq->queue_mode & HQ_NO_EVENT)
{
}
else
{
sys_os_destroy_sig_mutex(phq->queue_nnulEvent);
sys_os_destroy_sig_mutex(phq->queue_nfulEvent);
sys_os_destroy_sig_mutex(phq->queue_putMutex);
}
free(phq);
}
/***************************************************************************************/
void hqPutMutexEnter(HQUEUE * phq)
{
if ((phq->queue_mode & HQ_NO_EVENT) == 0)
{
sys_os_mutex_enter(phq->queue_putMutex);
}
}
void hqPutMutexLeave(HQUEUE * phq)
{
if ((phq->queue_mode & HQ_NO_EVENT) == 0)
{
sys_os_mutex_leave(phq->queue_putMutex);
}
}
HT_API BOOL hqBufPut(HQUEUE * phq, char * buf)
{
uint32 real_rear, queue_count;
char * ptr;
if (phq == NULL || buf == NULL)
{
return FALSE;
}
hqPutMutexEnter(phq);
hqBufPut_start:
queue_count = phq->rear - phq->front;
if (queue_count == (phq->unit_num - 1))
{
if ((phq->queue_mode & HQ_NO_EVENT) == 0)
{
if (phq->queue_mode & HQ_PUT_WAIT)
{
sys_os_sig_wait(phq->queue_nfulEvent);
goto hqBufPut_start;
}
else
{
phq->count_put_full++;
hqPutMutexLeave(phq);
// log_print(HT_LOG_ERR, "%s, queue_count=%d,full!!!\r\n", __FUNCTION__, queue_count);
return FALSE;
}
}
else
{
hqPutMutexLeave(phq);
return FALSE;
}
}
real_rear = phq->rear % phq->unit_num;
ptr = ((char *)phq) + phq->queue_buffer + real_rear*phq->unit_size;
memcpy((char *)ptr, buf, phq->unit_size);
phq->rear++;
if ((phq->queue_mode & HQ_NO_EVENT) == 0)
{
sys_os_sig_sign(phq->queue_nnulEvent);
}
hqPutMutexLeave(phq);
return TRUE;
}
HT_API BOOL hqBufGet(HQUEUE * phq, char * buf)
{
uint32 real_front;
if (phq == NULL || buf == NULL)
{
return FALSE;
}
hqBufGet_start:
if (phq->front == phq->rear)
{
if ((phq->queue_mode & HQ_NO_EVENT) == 0)
{
if (phq->queue_mode & HQ_GET_WAIT)
{
sys_os_sig_wait(phq->queue_nnulEvent);
goto hqBufGet_start;
}
else
{
return FALSE;
}
}
else
{
return FALSE;
}
}
real_front = phq->front % phq->unit_num;
memcpy(buf, ((char *)phq) + phq->queue_buffer + real_front*phq->unit_size, phq->unit_size);
phq->front++;
if ((phq->queue_mode & HQ_NO_EVENT) == 0)
{
sys_os_sig_sign(phq->queue_nfulEvent);
}
return TRUE;
}
HT_API BOOL hqBufIsEmpty(HQUEUE * phq)
{
if (phq == NULL)
{
return TRUE;
}
if (phq->front == phq->rear)
{
return TRUE;
}
return FALSE;
}
HT_API BOOL hqBufIsFull(HQUEUE * phq)
{
uint32 queue_count;
if (phq == NULL)
{
return FALSE;
}
queue_count = phq->rear - phq->front;
if (queue_count == (phq->unit_num - 1))
{
return TRUE;
}
return FALSE;
}
HT_API char * hqBufGetWait(HQUEUE * phq)
{
uint32 real_front;
char * ptr = NULL;
if (phq == NULL)
{
return NULL;
}
hqBufGet_start:
if (phq->front == phq->rear)
{
if ((phq->queue_mode & HQ_NO_EVENT) == 0)
{
if (phq->queue_mode & HQ_GET_WAIT)
{
sys_os_sig_wait(phq->queue_nnulEvent);
goto hqBufGet_start;
}
else
{
return NULL;
}
}
else
{
return NULL;
}
}
real_front = phq->front % phq->unit_num;
ptr = ((char *)phq) + phq->queue_buffer + real_front*phq->unit_size;
return ptr;
}
HT_API void hqBufGetWaitPost(HQUEUE * phq)
{
if (phq == NULL)
{
return;
}
phq->front++;
if ((phq->queue_mode & HQ_NO_EVENT) == 0)
{
sys_os_sig_sign(phq->queue_nfulEvent);
}
}
HT_API char * hqBufPutPtrWait(HQUEUE * phq)
{
uint32 real_rear,queue_count;
char * ptr;
if (phq == NULL)
{
return NULL;
}
hqPutMutexEnter(phq);
hqBufPutPtr_start:
queue_count = phq->rear - phq->front;
if (queue_count == (phq->unit_num - 1))
{
if ((phq->queue_mode & HQ_NO_EVENT) == 0)
{
if (phq->queue_mode & HQ_PUT_WAIT)
{
sys_os_sig_wait(phq->queue_nfulEvent);
goto hqBufPutPtr_start;
}
else
{
phq->count_put_full++;
hqPutMutexLeave(phq);
return FALSE;
}
}
else
{
hqPutMutexLeave(phq);
return FALSE;
}
}
real_rear = phq->rear % phq->unit_num;
ptr = ((char *)phq) + phq->queue_buffer + real_rear*phq->unit_size;
return ptr;
}
HT_API void hqBufPutPtrWaitPost(HQUEUE * phq, BOOL bPutFinish)
{
if (phq == NULL)
{
return;
}
if (bPutFinish)
{
phq->rear++;
}
if ((phq->queue_mode & HQ_NO_EVENT) == 0)
{
sys_os_sig_sign(phq->queue_nnulEvent);
}
hqPutMutexLeave(phq);
}
HT_API BOOL hqBufPeek(HQUEUE * phq, char * buf)
{
uint32 real_front;
if (phq == NULL || buf == NULL)
{
return FALSE;
}
hqBufPeek_start:
if (phq->front == phq->rear)
{
if ((phq->queue_mode & HQ_NO_EVENT) == 0)
{
if (phq->queue_mode & HQ_GET_WAIT)
{
sys_os_sig_wait(phq->queue_nnulEvent);
goto hqBufPeek_start;
}
else
{
return FALSE;
}
}
else
{
return FALSE;
}
}
real_front = phq->front % phq->unit_num;
memcpy(buf, ((char *)phq) + phq->queue_buffer + real_front*phq->unit_size, phq->unit_size);
return TRUE;
}

74
MediaClient/bm/hqueue.h Normal file
View File

@@ -0,0 +1,74 @@
/***************************************************************************************
*
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
*
* By downloading, copying, installing or using the software you agree to this license.
* If you do not agree to this license, do not download, install,
* copy or use the software.
*
* Copyright (C) 2014-2024, Happytimesoft Corporation, all rights reserved.
*
* Redistribution and use in binary forms, with or without modification, are permitted.
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************************/
#ifndef HQUEUE_H
#define HQUEUE_H
/***********************************************************/
#define HQ_PUT_WAIT 0x00000001
#define HQ_GET_WAIT 0x00000002
#define HQ_NO_EVENT 0x00000004
/***********************************************************/
typedef struct h_queue
{
uint32 queue_mode;
uint32 unit_num;
uint32 unit_size;
uint32 front;
uint32 rear;
uint32 queue_buffer;
uint32 count_put_full;
void * queue_putMutex;
void * queue_nnulEvent;
void * queue_nfulEvent;
} HQUEUE;
#ifdef __cplusplus
extern "C" {
#endif
/***********************************************************/
HT_API HQUEUE * hqCreate(uint32 unit_num, uint32 unit_size, uint32 queue_mode);
HT_API void hqDelete(HQUEUE * phq);
HT_API BOOL hqBufPut(HQUEUE * phq,char * buf);
HT_API BOOL hqBufGet(HQUEUE * phq,char * buf);
HT_API BOOL hqBufIsEmpty(HQUEUE * phq);
HT_API BOOL hqBufIsFull(HQUEUE * phq);
HT_API char * hqBufGetWait(HQUEUE * phq);
HT_API void hqBufGetWaitPost(HQUEUE * phq);
HT_API char * hqBufPutPtrWait(HQUEUE * phq);
HT_API void hqBufPutPtrWaitPost(HQUEUE * phq, BOOL bPutFinish);
HT_API BOOL hqBufPeek(HQUEUE * phq,char * buf);
#ifdef __cplusplus
}
#endif
#endif // HQUEUE_H

View File

@@ -0,0 +1,632 @@
/***************************************************************************************
*
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
*
* By downloading, copying, installing or using the software you agree to this license.
* If you do not agree to this license, do not download, install,
* copy or use the software.
*
* Copyright (C) 2014-2024, Happytimesoft Corporation, all rights reserved.
*
* Redistribution and use in binary forms, with or without modification, are permitted.
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************************/
#include "sys_inc.h"
#include "linked_list.h"
/************************************************************************************/
HT_API LINKED_LIST * h_list_create(BOOL bNeedMutex)
{
LINKED_LIST * p_linked_list;
p_linked_list = (LINKED_LIST*) malloc(sizeof(LINKED_LIST));
if (p_linked_list == NULL)
{
return NULL;
}
p_linked_list->p_first_node = NULL;
p_linked_list->p_last_node = NULL;
if (bNeedMutex)
{
p_linked_list->list_semMutex = sys_os_create_mutex();
}
else
{
p_linked_list->list_semMutex = NULL;
}
return p_linked_list;
}
/************************************************************************************/
HT_API void h_list_get_ownership(LINKED_LIST * p_linked_list)
{
if (p_linked_list->list_semMutex)
{
sys_os_mutex_enter(p_linked_list->list_semMutex);
}
}
HT_API void h_list_giveup_ownership(LINKED_LIST * p_linked_list)
{
if (p_linked_list->list_semMutex)
{
sys_os_mutex_leave(p_linked_list->list_semMutex);
}
}
/************************************************************************************/
HT_API void h_list_free_container(LINKED_LIST * p_linked_list)
{
LINKED_NODE * p_node;
LINKED_NODE * p_next_node;
if (p_linked_list == NULL)
{
return;
}
h_list_get_ownership(p_linked_list);
p_node = p_linked_list->p_first_node;
while (p_node != NULL)
{
void * p_free;
p_next_node = p_node->p_next;
p_free = p_node->p_data;
if (p_free != NULL)
{
free(p_free);
}
free (p_node);
p_node = p_next_node;
}
h_list_giveup_ownership(p_linked_list);
if (p_linked_list->list_semMutex)
{
sys_os_destroy_sig_mutex(p_linked_list->list_semMutex);
}
free (p_linked_list);
}
/************************************************************************************/
HT_API void h_list_free_all_node(LINKED_LIST * p_linked_list)
{
LINKED_NODE * p_node;
LINKED_NODE * p_next_node;
if (p_linked_list == NULL)
{
return;
}
h_list_get_ownership(p_linked_list);
p_node = p_linked_list->p_first_node;
while (p_node != NULL)
{
p_next_node = p_node->p_next;
if (p_node->p_data != NULL)
{
free(p_node->p_data);
}
free (p_node);
p_node = p_next_node;
}
p_linked_list->p_first_node = NULL;
p_linked_list->p_last_node = NULL;
h_list_giveup_ownership(p_linked_list);
}
/************************************************************************************/
HT_API BOOL h_list_add_at_front(LINKED_LIST * p_linked_list, void * p_item)
{
LINKED_NODE * p_node;
LINKED_NODE * p_next_node;
if (p_linked_list == NULL)
{
return FALSE;
}
if (p_item == NULL)
{
return FALSE;
}
p_node = (LINKED_NODE*) malloc(sizeof(LINKED_NODE));
if (p_node == NULL)
{
return FALSE;
}
p_node->p_next = NULL;
p_node->p_previous = NULL;
p_node->p_data = p_item;
h_list_get_ownership(p_linked_list);
if (p_linked_list->p_first_node == NULL)
{
p_linked_list->p_first_node = p_node;
p_linked_list->p_last_node = p_node;
p_node->p_previous = NULL;
p_node->p_next = NULL;
}
else
{
p_next_node = p_linked_list->p_first_node;
p_node->p_next = p_next_node;
p_node->p_previous = NULL;
p_next_node->p_previous = p_node;
p_linked_list->p_first_node = p_node;
}
h_list_giveup_ownership(p_linked_list);
return TRUE;
}
/************************************************************************************/
HT_API void h_list_remove_from_front(LINKED_LIST * p_linked_list)
{
LINKED_NODE * p_node_to_remove;
if (p_linked_list == NULL)
{
return;
}
h_list_get_ownership(p_linked_list);
p_node_to_remove = p_linked_list->p_first_node;
if (p_node_to_remove == NULL)
{
h_list_giveup_ownership(p_linked_list);
return;
}
if (p_linked_list->p_first_node == p_linked_list->p_last_node)
{
p_linked_list->p_first_node = NULL;
p_linked_list->p_last_node = NULL;
}
else
{
p_linked_list->p_first_node = p_node_to_remove->p_next;
p_linked_list->p_first_node->p_previous = NULL;
}
free(p_node_to_remove);
h_list_giveup_ownership(p_linked_list);
}
HT_API void h_list_remove_from_front_no_lock(LINKED_LIST * p_linked_list)
{
LINKED_NODE * p_node_to_remove;
if (p_linked_list == NULL)
{
return;
}
p_node_to_remove = p_linked_list->p_first_node;
if (p_node_to_remove == NULL)
{
return;
}
if (p_linked_list->p_first_node == p_linked_list->p_last_node)
{
p_linked_list->p_first_node = NULL;
p_linked_list->p_last_node = NULL;
}
else
{
p_linked_list->p_first_node = p_node_to_remove->p_next;
p_linked_list->p_first_node->p_previous = NULL;
}
free (p_node_to_remove);
}
/************************************************************************************/
HT_API BOOL h_list_add_at_back(LINKED_LIST * p_linked_list, void * p_item)
{
LINKED_NODE * p_node;
LINKED_NODE * p_previous_node;
if (p_linked_list == NULL)
{
return FALSE;
}
if (p_item == NULL)
{
return FALSE;
}
p_node = (LINKED_NODE*) malloc(sizeof(LINKED_NODE));
if (p_node == NULL)
{
return FALSE;
}
p_node->p_next = NULL;
p_node->p_previous = NULL;
p_node->p_data = (void*) p_item;
h_list_get_ownership(p_linked_list);
if (p_linked_list->p_last_node == NULL)
{
p_linked_list->p_last_node = p_node;
p_linked_list->p_first_node = p_node;
p_node->p_next = NULL;
p_node->p_previous = NULL;
}
else
{
p_previous_node = p_linked_list->p_last_node;
p_node->p_next = NULL;
p_node->p_previous = p_previous_node;
p_previous_node->p_next = p_node;
p_linked_list->p_last_node = p_node;
}
h_list_giveup_ownership(p_linked_list);
return TRUE;
}
/************************************************************************************/
HT_API void h_list_remove_from_back(LINKED_LIST * p_linked_list)
{
LINKED_NODE * p_node_to_remove;
if (p_linked_list == NULL)
{
return;
}
h_list_get_ownership(p_linked_list);
if (p_linked_list->p_last_node == NULL)
{
h_list_giveup_ownership(p_linked_list);
return;
}
if (p_linked_list->p_first_node == p_linked_list->p_last_node)
{
p_node_to_remove = p_linked_list->p_first_node;
p_linked_list->p_first_node = NULL;
p_linked_list->p_last_node = NULL;
free(p_node_to_remove);
h_list_giveup_ownership(p_linked_list);
return;
}
p_node_to_remove = p_linked_list->p_last_node;
p_linked_list->p_last_node = p_node_to_remove->p_previous;
p_linked_list->p_last_node->p_next = NULL;
free(p_node_to_remove);
p_node_to_remove = NULL;
h_list_giveup_ownership(p_linked_list);
}
HT_API BOOL h_list_remove(LINKED_LIST * p_linked_list, LINKED_NODE * p_node)
{
LINKED_NODE * p_previous_node;
LINKED_NODE * p_next_node;
if ((p_linked_list == NULL) || (p_node == NULL))
{
return FALSE;
}
p_previous_node = p_node->p_previous;
p_next_node = p_node->p_next;
if (p_previous_node != NULL)
{
p_previous_node->p_next = p_next_node;
}
else
{
p_linked_list->p_first_node = p_next_node;
}
if (p_next_node != NULL)
{
p_next_node->p_previous = p_previous_node;
}
else
{
p_linked_list->p_last_node = p_previous_node;
}
free (p_node);
return TRUE;
}
HT_API BOOL h_list_remove_data(LINKED_LIST * p_linked_list, void * p_data)
{
LINKED_NODE * p_previous_node;
LINKED_NODE * p_next_node;
LINKED_NODE * p_node;
if ((p_linked_list == NULL) || (p_data == NULL))
{
return FALSE;
}
h_list_get_ownership(p_linked_list);
p_node = p_linked_list->p_first_node;
while (p_node != NULL)
{
if (p_data == p_node->p_data)
{
break;
}
p_node = p_node->p_next;
}
if (p_node == NULL)
{
h_list_giveup_ownership(p_linked_list);
return FALSE;
}
p_previous_node = p_node->p_previous;
p_next_node = p_node->p_next;
if (p_previous_node != NULL)
{
p_previous_node->p_next = p_next_node;
}
else
{
p_linked_list->p_first_node = p_next_node;
}
if (p_next_node != NULL)
{
p_next_node->p_previous = p_previous_node;
}
else
{
p_linked_list->p_last_node = p_previous_node;
}
free(p_node);
h_list_giveup_ownership(p_linked_list);
return TRUE;
}
/************************************************************************************/
HT_API uint32 h_list_get_number_of_nodes(LINKED_LIST * p_linked_list)
{
uint32 number_of_nodes;
LINKED_NODE * p_node;
if (NULL == p_linked_list)
{
return 0;
}
h_list_get_ownership(p_linked_list);
p_node = p_linked_list->p_first_node;
number_of_nodes = 0;
while (p_node != NULL)
{
++ number_of_nodes;
p_node = p_node->p_next;
}
h_list_giveup_ownership(p_linked_list);
return number_of_nodes;
}
/************************************************************************************/
HT_API BOOL h_list_insert(LINKED_LIST * p_linked_list, LINKED_NODE * p_pre_node, void *p_item)
{
if ((p_linked_list == NULL) || (p_item == NULL))
{
return FALSE;
}
if (p_pre_node == NULL)
{
h_list_add_at_front(p_linked_list, p_item);
}
else
{
if (p_pre_node->p_next == NULL)
{
h_list_add_at_back(p_linked_list, p_item);
}
else
{
LINKED_NODE * p_node = (LINKED_NODE *)malloc(sizeof(LINKED_NODE));
if (NULL == p_node)
{
return FALSE;
}
h_list_get_ownership(p_linked_list);
p_node->p_data = p_item;
p_node->p_next = p_pre_node->p_next;
p_node->p_previous = p_pre_node;
p_pre_node->p_next->p_previous = p_node;
p_pre_node->p_next = p_node;
h_list_giveup_ownership(p_linked_list);
}
}
return TRUE;
}
/***********************************************************************/
HT_API LINKED_NODE * h_list_lookup_start(LINKED_LIST * p_linked_list)
{
if (p_linked_list == NULL)
{
return NULL;
}
h_list_get_ownership(p_linked_list);
if (p_linked_list->p_first_node)
{
return p_linked_list->p_first_node;
}
return NULL;
}
HT_API LINKED_NODE * h_list_lookup_next(LINKED_LIST * p_linked_list, LINKED_NODE * p_node)
{
if (p_node == NULL)
{
return NULL;
}
return p_node->p_next;
}
HT_API void h_list_lookup_end(LINKED_LIST * p_linked_list)
{
if (p_linked_list == NULL)
{
return;
}
h_list_giveup_ownership(p_linked_list);
}
HT_API LINKED_NODE * h_list_lookback_start(LINKED_LIST * p_linked_list)
{
if (p_linked_list == NULL)
{
return NULL;
}
h_list_get_ownership(p_linked_list);
if (p_linked_list->p_last_node)
{
return p_linked_list->p_last_node;
}
return NULL;
}
HT_API LINKED_NODE * h_list_lookback_next(LINKED_LIST * p_linked_list, LINKED_NODE * p_node)
{
if (p_node == NULL)
{
return NULL;
}
return p_node->p_previous;
}
HT_API void h_list_lookback_end(LINKED_LIST * p_linked_list)
{
if (p_linked_list == NULL)
{
return;
}
h_list_giveup_ownership(p_linked_list);
}
HT_API LINKED_NODE * h_list_get_from_front(LINKED_LIST * p_list)
{
if (p_list == NULL)
{
return NULL;
}
return p_list->p_first_node;
}
HT_API LINKED_NODE * h_list_get_from_back(LINKED_LIST * p_list)
{
if (p_list == NULL)
{
return NULL;
}
return p_list->p_last_node;
}
HT_API BOOL h_list_is_empty(LINKED_LIST * p_list)
{
if (p_list == NULL)
{
return TRUE;
}
return (p_list->p_first_node == NULL);
}

View File

@@ -0,0 +1,83 @@
/***************************************************************************************
*
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
*
* By downloading, copying, installing or using the software you agree to this license.
* If you do not agree to this license, do not download, install,
* copy or use the software.
*
* Copyright (C) 2014-2024, Happytimesoft Corporation, all rights reserved.
*
* Redistribution and use in binary forms, with or without modification, are permitted.
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************************/
#ifndef LINKED_LIST_H
#define LINKED_LIST_H
/************************************************************************************/
typedef struct LINKED_NODE
{
struct LINKED_NODE * p_next;
struct LINKED_NODE * p_previous;
void * p_data;
} LINKED_NODE;
/************************************************************************************/
typedef struct LINKED_LIST
{
LINKED_NODE * p_first_node;
LINKED_NODE * p_last_node;
void * list_semMutex;
} LINKED_LIST;
#ifdef __cplusplus
extern "C" {
#endif
HT_API LINKED_LIST* h_list_create(BOOL bNeedMutex);
HT_API void h_list_free_container(LINKED_LIST * p_linked_list);
HT_API void h_list_free_all_node(LINKED_LIST * p_linked_list);
HT_API void h_list_get_ownership(LINKED_LIST * p_linked_list);
HT_API void h_list_giveup_ownership(LINKED_LIST * p_linked_list);
HT_API BOOL h_list_remove(LINKED_LIST * p_linked_list, LINKED_NODE * p_node);
HT_API BOOL h_list_remove_data(LINKED_LIST * p_linked_list, void * p_data);
HT_API void h_list_remove_from_front(LINKED_LIST * p_linked_list);
HT_API void h_list_remove_from_front_no_lock(LINKED_LIST * p_linked_list);
HT_API void h_list_remove_from_back(LINKED_LIST * p_linked_list);
HT_API BOOL h_list_add_at_front(LINKED_LIST * p_linked_list, void * p_item);
HT_API BOOL h_list_add_at_back(LINKED_LIST * p_linked_list, void * p_item);
HT_API uint32 h_list_get_number_of_nodes(LINKED_LIST * p_linked_list);
HT_API BOOL h_list_insert(LINKED_LIST * p_linked_list, LINKED_NODE * p_pre_node, void * p_item);
HT_API LINKED_NODE* h_list_lookup_start(LINKED_LIST * p_linked_list);
HT_API LINKED_NODE* h_list_lookup_next(LINKED_LIST * p_linked_list, LINKED_NODE * p_node);
HT_API void h_list_lookup_end(LINKED_LIST * p_linked_list);
HT_API LINKED_NODE* h_list_lookback_start(LINKED_LIST * p_linked_list);
HT_API LINKED_NODE* h_list_lookback_next(LINKED_LIST * p_linked_list, LINKED_NODE * p_node);
HT_API void h_list_lookback_end(LINKED_LIST * p_linked_list);
HT_API BOOL h_list_is_empty(LINKED_LIST * p_list);
HT_API LINKED_NODE* h_list_get_from_front(LINKED_LIST * p_list);
HT_API LINKED_NODE* h_list_get_from_back(LINKED_LIST * p_list);
#ifdef __cplusplus
}
#endif
#endif // LINKED_LIST_H

1109
MediaClient/bm/ppstack.cpp Normal file

File diff suppressed because it is too large Load Diff

110
MediaClient/bm/ppstack.h Normal file
View File

@@ -0,0 +1,110 @@
/***************************************************************************************
*
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
*
* By downloading, copying, installing or using the software you agree to this license.
* If you do not agree to this license, do not download, install,
* copy or use the software.
*
* Copyright (C) 2014-2024, Happytimesoft Corporation, all rights reserved.
*
* Redistribution and use in binary forms, with or without modification, are permitted.
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************************/
#ifndef PPSTACK_H
#define PPSTACK_H
/***************************************************************************************/
typedef struct PPSN // ppstack_node
{
unsigned long prev_node;
unsigned long next_node;
unsigned long node_flag; // 0:idle 1:in FreeList 2:in UsedList
} PPSN;
typedef struct PPSN_CTX
{
char * fl_base;
uint32 head_node;
uint32 tail_node;
uint32 node_num;
uint32 low_offset;
uint32 high_offset;
uint32 unit_size;
void * ctx_mutex;
uint32 pop_cnt;
uint32 push_cnt;
} PPSN_CTX;
#ifdef __cplusplus
extern "C" {
#endif
/***************************************************************************************/
HT_API PPSN_CTX * pps_ctx_fl_init(unsigned long node_num, unsigned long content_size, BOOL bNeedMutex);
HT_API PPSN_CTX * pps_ctx_fl_init_assign(char * mem_addr, unsigned long mem_len, unsigned long node_num, unsigned long content_size, BOOL bNeedMutex);
HT_API void pps_fl_free(PPSN_CTX * fl_ctx);
HT_API void pps_fl_reinit(PPSN_CTX * fl_ctx);
HT_API BOOL pps_fl_push(PPSN_CTX * pps_ctx, void * content_ptr);
HT_API BOOL pps_fl_push_tail(PPSN_CTX * pps_ctx, void * content_ptr);
HT_API void * pps_fl_pop(PPSN_CTX * pps_ctx);
HT_API PPSN_CTX * pps_ctx_ul_init(PPSN_CTX * fl_ctx, BOOL bNeedMutex);
HT_API BOOL pps_ctx_ul_init_assign(PPSN_CTX * ul_ctx, PPSN_CTX * fl_ctx, BOOL bNeedMutex);
HT_API BOOL pps_ctx_ul_init_nm(PPSN_CTX * fl_ctx, PPSN_CTX * ul_ctx);
HT_API void pps_ul_reinit(PPSN_CTX * ul_ctx);
HT_API void pps_ul_free(PPSN_CTX * ul_ctx);
HT_API BOOL pps_ctx_ul_del(PPSN_CTX * ul_ctx, void * content_ptr);
HT_API PPSN * pps_ctx_ul_del_node_unlock(PPSN_CTX * ul_ctx, PPSN * p_node);
HT_API void * pps_ctx_ul_del_unlock(PPSN_CTX * ul_ctx, void * content_ptr);
HT_API BOOL pps_ctx_ul_add(PPSN_CTX * ul_ctx, void * content_ptr);
HT_API BOOL pps_ctx_ul_add_head(PPSN_CTX * ul_ctx, void * content_ptr);
HT_API uint32 pps_get_index(PPSN_CTX * pps_ctx, void * content_ptr);
HT_API void * pps_get_node_by_index(PPSN_CTX * pps_ctx, unsigned long index);
/***************************************************************************************/
HT_API void * pps_lookup_start(PPSN_CTX * pps_ctx);
HT_API void * pps_lookup_next(PPSN_CTX * pps_ctx, void * ct_ptr);
HT_API void pps_lookup_end(PPSN_CTX * pps_ctx);
HT_API void * pps_lookback_start(PPSN_CTX * pps_ctx);
HT_API void * pps_lookback_next(PPSN_CTX * pps_ctx, void * ct_ptr);
HT_API void pps_lookback_end(PPSN_CTX * pps_ctx);
HT_API void pps_wait_mutex(PPSN_CTX * pps_ctx);
HT_API void pps_post_mutex(PPSN_CTX * pps_ctx);
HT_API BOOL pps_safe_node(PPSN_CTX * pps_ctx, void * content_ptr);
HT_API BOOL pps_idle_node(PPSN_CTX * pps_ctx, void * content_ptr);
HT_API BOOL pps_exist_node(PPSN_CTX * pps_ctx, void * content_ptr);
HT_API BOOL pps_used_node(PPSN_CTX * pps_ctx, void * content_ptr);
/***************************************************************************************/
HT_API int pps_node_count(PPSN_CTX * pps_ctx);
HT_API void * pps_get_head_node(PPSN_CTX * pps_ctx);
HT_API void * pps_get_tail_node(PPSN_CTX * pps_ctx);
HT_API void * pps_get_next_node(PPSN_CTX * pps_ctx, void * content_ptr);
HT_API void * pps_get_prev_node(PPSN_CTX * pps_ctx, void * content_ptr);
#ifdef __cplusplus
}
#endif
#endif // PPSTACK_H

245
MediaClient/bm/rfc_md5.cpp Normal file
View File

@@ -0,0 +1,245 @@
/***************************************************************************************
*
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
*
* By downloading, copying, installing or using the software you agree to this license.
* If you do not agree to this license, do not download, install,
* copy or use the software.
*
* Copyright (C) 2014-2024, Happytimesoft Corporation, all rights reserved.
*
* Redistribution and use in binary forms, with or without modification, are permitted.
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************************/
#include "sys_inc.h"
#include "rfc_md5.h"
#define GET_UINT32(n,b,i) \
{ \
(n) = ( (uint32) (b)[(i) ] ) \
| ( (uint32) (b)[(i) + 1] << 8 ) \
| ( (uint32) (b)[(i) + 2] << 16 ) \
| ( (uint32) (b)[(i) + 3] << 24 ); \
}
#define PUT_UINT32(n,b,i) \
{ \
(b)[(i) ] = (uint8) ( (n) ); \
(b)[(i) + 1] = (uint8) ( (n) >> 8 ); \
(b)[(i) + 2] = (uint8) ( (n) >> 16 ); \
(b)[(i) + 3] = (uint8) ( (n) >> 24 ); \
}
HT_API void md5_starts(md5_context *ctx)
{
ctx->total[0] = 0;
ctx->total[1] = 0;
ctx->state[0] = 0x67452301;
ctx->state[1] = 0xEFCDAB89;
ctx->state[2] = 0x98BADCFE;
ctx->state[3] = 0x10325476;
}
void md5_process(md5_context *ctx, uint8 data[64])
{
uint32 X[16], A, B, C, D;
GET_UINT32( X[0], data, 0 );
GET_UINT32( X[1], data, 4 );
GET_UINT32( X[2], data, 8 );
GET_UINT32( X[3], data, 12 );
GET_UINT32( X[4], data, 16 );
GET_UINT32( X[5], data, 20 );
GET_UINT32( X[6], data, 24 );
GET_UINT32( X[7], data, 28 );
GET_UINT32( X[8], data, 32 );
GET_UINT32( X[9], data, 36 );
GET_UINT32( X[10], data, 40 );
GET_UINT32( X[11], data, 44 );
GET_UINT32( X[12], data, 48 );
GET_UINT32( X[13], data, 52 );
GET_UINT32( X[14], data, 56 );
GET_UINT32( X[15], data, 60 );
#define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
#define P(a,b,c,d,k,s,t) \
{ \
a += F(b,c,d) + X[k] + t; a = S(a,s) + b; \
}
A = ctx->state[0];
B = ctx->state[1];
C = ctx->state[2];
D = ctx->state[3];
#define F(x,y,z) (z ^ (x & (y ^ z)))
P( A, B, C, D, 0, 7, 0xD76AA478 );
P( D, A, B, C, 1, 12, 0xE8C7B756 );
P( C, D, A, B, 2, 17, 0x242070DB );
P( B, C, D, A, 3, 22, 0xC1BDCEEE );
P( A, B, C, D, 4, 7, 0xF57C0FAF );
P( D, A, B, C, 5, 12, 0x4787C62A );
P( C, D, A, B, 6, 17, 0xA8304613 );
P( B, C, D, A, 7, 22, 0xFD469501 );
P( A, B, C, D, 8, 7, 0x698098D8 );
P( D, A, B, C, 9, 12, 0x8B44F7AF );
P( C, D, A, B, 10, 17, 0xFFFF5BB1 );
P( B, C, D, A, 11, 22, 0x895CD7BE );
P( A, B, C, D, 12, 7, 0x6B901122 );
P( D, A, B, C, 13, 12, 0xFD987193 );
P( C, D, A, B, 14, 17, 0xA679438E );
P( B, C, D, A, 15, 22, 0x49B40821 );
#undef F
#define F(x,y,z) (y ^ (z & (x ^ y)))
P( A, B, C, D, 1, 5, 0xF61E2562 );
P( D, A, B, C, 6, 9, 0xC040B340 );
P( C, D, A, B, 11, 14, 0x265E5A51 );
P( B, C, D, A, 0, 20, 0xE9B6C7AA );
P( A, B, C, D, 5, 5, 0xD62F105D );
P( D, A, B, C, 10, 9, 0x02441453 );
P( C, D, A, B, 15, 14, 0xD8A1E681 );
P( B, C, D, A, 4, 20, 0xE7D3FBC8 );
P( A, B, C, D, 9, 5, 0x21E1CDE6 );
P( D, A, B, C, 14, 9, 0xC33707D6 );
P( C, D, A, B, 3, 14, 0xF4D50D87 );
P( B, C, D, A, 8, 20, 0x455A14ED );
P( A, B, C, D, 13, 5, 0xA9E3E905 );
P( D, A, B, C, 2, 9, 0xFCEFA3F8 );
P( C, D, A, B, 7, 14, 0x676F02D9 );
P( B, C, D, A, 12, 20, 0x8D2A4C8A );
#undef F
#define F(x,y,z) (x ^ y ^ z)
P( A, B, C, D, 5, 4, 0xFFFA3942 );
P( D, A, B, C, 8, 11, 0x8771F681 );
P( C, D, A, B, 11, 16, 0x6D9D6122 );
P( B, C, D, A, 14, 23, 0xFDE5380C );
P( A, B, C, D, 1, 4, 0xA4BEEA44 );
P( D, A, B, C, 4, 11, 0x4BDECFA9 );
P( C, D, A, B, 7, 16, 0xF6BB4B60 );
P( B, C, D, A, 10, 23, 0xBEBFBC70 );
P( A, B, C, D, 13, 4, 0x289B7EC6 );
P( D, A, B, C, 0, 11, 0xEAA127FA );
P( C, D, A, B, 3, 16, 0xD4EF3085 );
P( B, C, D, A, 6, 23, 0x04881D05 );
P( A, B, C, D, 9, 4, 0xD9D4D039 );
P( D, A, B, C, 12, 11, 0xE6DB99E5 );
P( C, D, A, B, 15, 16, 0x1FA27CF8 );
P( B, C, D, A, 2, 23, 0xC4AC5665 );
#undef F
#define F(x,y,z) (y ^ (x | ~z))
P( A, B, C, D, 0, 6, 0xF4292244 );
P( D, A, B, C, 7, 10, 0x432AFF97 );
P( C, D, A, B, 14, 15, 0xAB9423A7 );
P( B, C, D, A, 5, 21, 0xFC93A039 );
P( A, B, C, D, 12, 6, 0x655B59C3 );
P( D, A, B, C, 3, 10, 0x8F0CCC92 );
P( C, D, A, B, 10, 15, 0xFFEFF47D );
P( B, C, D, A, 1, 21, 0x85845DD1 );
P( A, B, C, D, 8, 6, 0x6FA87E4F );
P( D, A, B, C, 15, 10, 0xFE2CE6E0 );
P( C, D, A, B, 6, 15, 0xA3014314 );
P( B, C, D, A, 13, 21, 0x4E0811A1 );
P( A, B, C, D, 4, 6, 0xF7537E82 );
P( D, A, B, C, 11, 10, 0xBD3AF235 );
P( C, D, A, B, 2, 15, 0x2AD7D2BB );
P( B, C, D, A, 9, 21, 0xEB86D391 );
#undef F
ctx->state[0] += A;
ctx->state[1] += B;
ctx->state[2] += C;
ctx->state[3] += D;
}
HT_API void md5_update(md5_context *ctx, uint8 *input, uint32 length)
{
uint32 left, fill;
if (!length)
{
return;
}
left = ctx->total[0] & 0x3F;
fill = 64 - left;
ctx->total[0] += length;
ctx->total[0] &= 0xFFFFFFFF;
if (ctx->total[0] < length)
{
ctx->total[1]++;
}
if (left && length >= fill)
{
memcpy((void *) (ctx->buffer + left), (void *) input, fill);
md5_process(ctx, ctx->buffer);
length -= fill;
input += fill;
left = 0;
}
while (length >= 64)
{
md5_process(ctx, input);
length -= 64;
input += 64;
}
if (length)
{
memcpy((void *) (ctx->buffer + left), (void *) input, length);
}
}
HT_API void md5_finish(md5_context *ctx, uint8 digest[16])
{
uint32 last, padn;
uint32 high, low;
uint8 msglen[8];
uint8 padding[64];
high = (ctx->total[0] >> 29) | (ctx->total[1] << 3);
low = (ctx->total[0] << 3);
PUT_UINT32(low, msglen, 0);
PUT_UINT32(high, msglen, 4);
last = ctx->total[0] & 0x3F;
padn = (last < 56) ? (56 - last) : (120 - last);
memset(padding, 0, sizeof(padding));
padding[0] = 0x80;
md5_update(ctx, padding, padn);
md5_update(ctx, msglen, 8);
PUT_UINT32(ctx->state[0], digest, 0);
PUT_UINT32(ctx->state[1], digest, 4);
PUT_UINT32(ctx->state[2], digest, 8);
PUT_UINT32(ctx->state[3], digest, 12);
}

46
MediaClient/bm/rfc_md5.h Normal file
View File

@@ -0,0 +1,46 @@
/***************************************************************************************
*
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
*
* By downloading, copying, installing or using the software you agree to this license.
* If you do not agree to this license, do not download, install,
* copy or use the software.
*
* Copyright (C) 2014-2024, Happytimesoft Corporation, all rights reserved.
*
* Redistribution and use in binary forms, with or without modification, are permitted.
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************************/
#ifndef RFC_MD5_H
#define RFC_MD5_H
typedef struct
{
uint32 total[2];
uint32 state[4];
uint8 buffer[64];
} md5_context;
#ifdef __cplusplus
extern "C"{
#endif
HT_API void md5_starts(md5_context *ctx);
HT_API void md5_update(md5_context *ctx, uint8 *input, uint32 length);
HT_API void md5_finish(md5_context *ctx, uint8 digest[16]);
#ifdef __cplusplus
}
#endif
#endif

280
MediaClient/bm/sha1.cpp Normal file
View File

@@ -0,0 +1,280 @@
/***************************************************************************************
*
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
*
* By downloading, copying, installing or using the software you agree to this license.
* If you do not agree to this license, do not download, install,
* copy or use the software.
*
* Copyright (C) 2014-2024, Happytimesoft Corporation, all rights reserved.
*
* Redistribution and use in binary forms, with or without modification, are permitted.
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************************/
#include "sys_inc.h"
#include "sha1.h"
#define GET_UINT32(n,b,i) \
{ \
(n) = ( (uint32) (b)[(i) ] << 24 ) \
| ( (uint32) (b)[(i) + 1] << 16 ) \
| ( (uint32) (b)[(i) + 2] << 8 ) \
| ( (uint32) (b)[(i) + 3] ); \
}
#define PUT_UINT32(n,b,i) \
{ \
(b)[(i) ] = (uint8) ( (n) >> 24 ); \
(b)[(i) + 1] = (uint8) ( (n) >> 16 ); \
(b)[(i) + 2] = (uint8) ( (n) >> 8 ); \
(b)[(i) + 3] = (uint8) ( (n) ); \
}
HT_API void sha1_starts(sha1_context * ctx)
{
ctx->total[0] = 0;
ctx->total[1] = 0;
ctx->state[0] = 0x67452301;
ctx->state[1] = 0xEFCDAB89;
ctx->state[2] = 0x98BADCFE;
ctx->state[3] = 0x10325476;
ctx->state[4] = 0xC3D2E1F0;
}
void sha1_process(sha1_context * ctx, uint8 data[64])
{
uint32 temp, W[16], A, B, C, D, E;
GET_UINT32( W[0], data, 0 );
GET_UINT32( W[1], data, 4 );
GET_UINT32( W[2], data, 8 );
GET_UINT32( W[3], data, 12 );
GET_UINT32( W[4], data, 16 );
GET_UINT32( W[5], data, 20 );
GET_UINT32( W[6], data, 24 );
GET_UINT32( W[7], data, 28 );
GET_UINT32( W[8], data, 32 );
GET_UINT32( W[9], data, 36 );
GET_UINT32( W[10], data, 40 );
GET_UINT32( W[11], data, 44 );
GET_UINT32( W[12], data, 48 );
GET_UINT32( W[13], data, 52 );
GET_UINT32( W[14], data, 56 );
GET_UINT32( W[15], data, 60 );
#define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
#define R(t) \
( \
temp = W[(t - 3) & 0x0F] ^ W[(t - 8) & 0x0F] ^ \
W[(t - 14) & 0x0F] ^ W[ t & 0x0F], \
( W[t & 0x0F] = S(temp,1) ) \
)
#define P(a,b,c,d,e,x) \
{ \
e += S(a,5) + F(b,c,d) + K + x; b = S(b,30); \
}
A = ctx->state[0];
B = ctx->state[1];
C = ctx->state[2];
D = ctx->state[3];
E = ctx->state[4];
#define F(x,y,z) (z ^ (x & (y ^ z)))
#define K 0x5A827999
P( A, B, C, D, E, W[0] );
P( E, A, B, C, D, W[1] );
P( D, E, A, B, C, W[2] );
P( C, D, E, A, B, W[3] );
P( B, C, D, E, A, W[4] );
P( A, B, C, D, E, W[5] );
P( E, A, B, C, D, W[6] );
P( D, E, A, B, C, W[7] );
P( C, D, E, A, B, W[8] );
P( B, C, D, E, A, W[9] );
P( A, B, C, D, E, W[10] );
P( E, A, B, C, D, W[11] );
P( D, E, A, B, C, W[12] );
P( C, D, E, A, B, W[13] );
P( B, C, D, E, A, W[14] );
P( A, B, C, D, E, W[15] );
P( E, A, B, C, D, R(16) );
P( D, E, A, B, C, R(17) );
P( C, D, E, A, B, R(18) );
P( B, C, D, E, A, R(19) );
#undef K
#undef F
#define F(x,y,z) (x ^ y ^ z)
#define K 0x6ED9EBA1
P( A, B, C, D, E, R(20) );
P( E, A, B, C, D, R(21) );
P( D, E, A, B, C, R(22) );
P( C, D, E, A, B, R(23) );
P( B, C, D, E, A, R(24) );
P( A, B, C, D, E, R(25) );
P( E, A, B, C, D, R(26) );
P( D, E, A, B, C, R(27) );
P( C, D, E, A, B, R(28) );
P( B, C, D, E, A, R(29) );
P( A, B, C, D, E, R(30) );
P( E, A, B, C, D, R(31) );
P( D, E, A, B, C, R(32) );
P( C, D, E, A, B, R(33) );
P( B, C, D, E, A, R(34) );
P( A, B, C, D, E, R(35) );
P( E, A, B, C, D, R(36) );
P( D, E, A, B, C, R(37) );
P( C, D, E, A, B, R(38) );
P( B, C, D, E, A, R(39) );
#undef K
#undef F
#define F(x,y,z) ((x & y) | (z & (x | y)))
#define K 0x8F1BBCDC
P( A, B, C, D, E, R(40) );
P( E, A, B, C, D, R(41) );
P( D, E, A, B, C, R(42) );
P( C, D, E, A, B, R(43) );
P( B, C, D, E, A, R(44) );
P( A, B, C, D, E, R(45) );
P( E, A, B, C, D, R(46) );
P( D, E, A, B, C, R(47) );
P( C, D, E, A, B, R(48) );
P( B, C, D, E, A, R(49) );
P( A, B, C, D, E, R(50) );
P( E, A, B, C, D, R(51) );
P( D, E, A, B, C, R(52) );
P( C, D, E, A, B, R(53) );
P( B, C, D, E, A, R(54) );
P( A, B, C, D, E, R(55) );
P( E, A, B, C, D, R(56) );
P( D, E, A, B, C, R(57) );
P( C, D, E, A, B, R(58) );
P( B, C, D, E, A, R(59) );
#undef K
#undef F
#define F(x,y,z) (x ^ y ^ z)
#define K 0xCA62C1D6
P( A, B, C, D, E, R(60) );
P( E, A, B, C, D, R(61) );
P( D, E, A, B, C, R(62) );
P( C, D, E, A, B, R(63) );
P( B, C, D, E, A, R(64) );
P( A, B, C, D, E, R(65) );
P( E, A, B, C, D, R(66) );
P( D, E, A, B, C, R(67) );
P( C, D, E, A, B, R(68) );
P( B, C, D, E, A, R(69) );
P( A, B, C, D, E, R(70) );
P( E, A, B, C, D, R(71) );
P( D, E, A, B, C, R(72) );
P( C, D, E, A, B, R(73) );
P( B, C, D, E, A, R(74) );
P( A, B, C, D, E, R(75) );
P( E, A, B, C, D, R(76) );
P( D, E, A, B, C, R(77) );
P( C, D, E, A, B, R(78) );
P( B, C, D, E, A, R(79) );
#undef K
#undef F
ctx->state[0] += A;
ctx->state[1] += B;
ctx->state[2] += C;
ctx->state[3] += D;
ctx->state[4] += E;
}
HT_API void sha1_update(sha1_context * ctx, uint8 * input, uint32 length)
{
uint32 left, fill;
if (!length)
{
return;
}
left = ctx->total[0] & 0x3F;
fill = 64 - left;
ctx->total[0] += length;
ctx->total[0] &= 0xFFFFFFFF;
if (ctx->total[0] < length)
{
ctx->total[1]++;
}
if (left && length >= fill)
{
memcpy((void *) (ctx->buffer + left), (void *) input, fill);
sha1_process(ctx, ctx->buffer);
length -= fill;
input += fill;
left = 0;
}
while (length >= 64)
{
sha1_process(ctx, input);
length -= 64;
input += 64;
}
if (length)
{
memcpy((void *) (ctx->buffer + left), (void *) input, length);
}
}
HT_API void sha1_finish(sha1_context * ctx, uint8 digest[20])
{
uint32 last, padn;
uint32 high, low;
uint8 msglen[8];
uint8 padding[64];
high = (ctx->total[0] >> 29) | (ctx->total[1] << 3);
low = (ctx->total[0] << 3);
PUT_UINT32(high, msglen, 0);
PUT_UINT32(low, msglen, 4);
last = ctx->total[0] & 0x3F;
padn = (last < 56) ? (56 - last) : (120 - last);
memset(padding, 0, sizeof(padding));
padding[0] = 0x80;
sha1_update(ctx, padding, padn);
sha1_update(ctx, msglen, 8);
PUT_UINT32(ctx->state[0], digest, 0);
PUT_UINT32(ctx->state[1], digest, 4);
PUT_UINT32(ctx->state[2], digest, 8);
PUT_UINT32(ctx->state[3], digest, 12);
PUT_UINT32(ctx->state[4], digest, 16);
}

44
MediaClient/bm/sha1.h Normal file
View File

@@ -0,0 +1,44 @@
/***************************************************************************************
*
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
*
* By downloading, copying, installing or using the software you agree to this license.
* If you do not agree to this license, do not download, install,
* copy or use the software.
*
* Copyright (C) 2014-2024, Happytimesoft Corporation, all rights reserved.
*
* Redistribution and use in binary forms, with or without modification, are permitted.
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************************/
#ifndef _SHA1_H_
#define _SHA1_H_
typedef struct
{
uint32 total[2];
uint32 state[5];
uint8 buffer[64];
} sha1_context;
#ifdef __cplusplus
extern "C" {
#endif
HT_API void sha1_starts(sha1_context * ctx);
HT_API void sha1_update(sha1_context * ctx, uint8 * input, uint32 length);
HT_API void sha1_finish(sha1_context * ctx, uint8 digest[20]);
#ifdef __cplusplus
}
#endif
#endif // _SHA1_H_

262
MediaClient/bm/sha256.cpp Normal file
View File

@@ -0,0 +1,262 @@
/***************************************************************************************
*
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
*
* By downloading, copying, installing or using the software you agree to this license.
* If you do not agree to this license, do not download, install,
* copy or use the software.
*
* Copyright (C) 2014-2024, Happytimesoft Corporation, all rights reserved.
*
* Redistribution and use in binary forms, with or without modification, are permitted.
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************************/
#include "sys_inc.h"
#include "sha256.h"
#define GET_UINT32(n,b,i) \
{ \
(n) = ( (uint32) (b)[(i) ] << 24 ) \
| ( (uint32) (b)[(i) + 1] << 16 ) \
| ( (uint32) (b)[(i) + 2] << 8 ) \
| ( (uint32) (b)[(i) + 3] ); \
}
#define PUT_UINT32(n,b,i) \
{ \
(b)[(i) ] = (uint8) ( (n) >> 24 ); \
(b)[(i) + 1] = (uint8) ( (n) >> 16 ); \
(b)[(i) + 2] = (uint8) ( (n) >> 8 ); \
(b)[(i) + 3] = (uint8) ( (n) ); \
}
HT_API void sha256_starts(sha256_context *ctx)
{
ctx->total[0] = 0;
ctx->total[1] = 0;
ctx->state[0] = 0x6A09E667;
ctx->state[1] = 0xBB67AE85;
ctx->state[2] = 0x3C6EF372;
ctx->state[3] = 0xA54FF53A;
ctx->state[4] = 0x510E527F;
ctx->state[5] = 0x9B05688C;
ctx->state[6] = 0x1F83D9AB;
ctx->state[7] = 0x5BE0CD19;
}
void sha256_process(sha256_context *ctx, uint8 data[64])
{
uint32 temp1, temp2, W[64];
uint32 A, B, C, D, E, F, G, H;
GET_UINT32( W[0], data, 0 );
GET_UINT32( W[1], data, 4 );
GET_UINT32( W[2], data, 8 );
GET_UINT32( W[3], data, 12 );
GET_UINT32( W[4], data, 16 );
GET_UINT32( W[5], data, 20 );
GET_UINT32( W[6], data, 24 );
GET_UINT32( W[7], data, 28 );
GET_UINT32( W[8], data, 32 );
GET_UINT32( W[9], data, 36 );
GET_UINT32( W[10], data, 40 );
GET_UINT32( W[11], data, 44 );
GET_UINT32( W[12], data, 48 );
GET_UINT32( W[13], data, 52 );
GET_UINT32( W[14], data, 56 );
GET_UINT32( W[15], data, 60 );
#define SHR(x,n) ((x & 0xFFFFFFFF) >> n)
#define ROTR(x,n) (SHR(x,n) | (x << (32 - n)))
#define S0(x) (ROTR(x, 7) ^ ROTR(x,18) ^ SHR(x, 3))
#define S1(x) (ROTR(x,17) ^ ROTR(x,19) ^ SHR(x,10))
#define S2(x) (ROTR(x, 2) ^ ROTR(x,13) ^ ROTR(x,22))
#define S3(x) (ROTR(x, 6) ^ ROTR(x,11) ^ ROTR(x,25))
#define F0(x,y,z) ((x & y) | (z & (x | y)))
#define F1(x,y,z) (z ^ (x & (y ^ z)))
#define R(t) \
( \
W[t] = S1(W[t - 2]) + W[t - 7] + \
S0(W[t - 15]) + W[t - 16] \
)
#define P(a,b,c,d,e,f,g,h,x,K) \
{ \
temp1 = h + S3(e) + F1(e,f,g) + K + x; \
temp2 = S2(a) + F0(a,b,c); \
d += temp1; h = temp1 + temp2; \
}
A = ctx->state[0];
B = ctx->state[1];
C = ctx->state[2];
D = ctx->state[3];
E = ctx->state[4];
F = ctx->state[5];
G = ctx->state[6];
H = ctx->state[7];
P( A, B, C, D, E, F, G, H, W[ 0], 0x428A2F98 );
P( H, A, B, C, D, E, F, G, W[ 1], 0x71374491 );
P( G, H, A, B, C, D, E, F, W[ 2], 0xB5C0FBCF );
P( F, G, H, A, B, C, D, E, W[ 3], 0xE9B5DBA5 );
P( E, F, G, H, A, B, C, D, W[ 4], 0x3956C25B );
P( D, E, F, G, H, A, B, C, W[ 5], 0x59F111F1 );
P( C, D, E, F, G, H, A, B, W[ 6], 0x923F82A4 );
P( B, C, D, E, F, G, H, A, W[ 7], 0xAB1C5ED5 );
P( A, B, C, D, E, F, G, H, W[ 8], 0xD807AA98 );
P( H, A, B, C, D, E, F, G, W[ 9], 0x12835B01 );
P( G, H, A, B, C, D, E, F, W[10], 0x243185BE );
P( F, G, H, A, B, C, D, E, W[11], 0x550C7DC3 );
P( E, F, G, H, A, B, C, D, W[12], 0x72BE5D74 );
P( D, E, F, G, H, A, B, C, W[13], 0x80DEB1FE );
P( C, D, E, F, G, H, A, B, W[14], 0x9BDC06A7 );
P( B, C, D, E, F, G, H, A, W[15], 0xC19BF174 );
P( A, B, C, D, E, F, G, H, R(16), 0xE49B69C1 );
P( H, A, B, C, D, E, F, G, R(17), 0xEFBE4786 );
P( G, H, A, B, C, D, E, F, R(18), 0x0FC19DC6 );
P( F, G, H, A, B, C, D, E, R(19), 0x240CA1CC );
P( E, F, G, H, A, B, C, D, R(20), 0x2DE92C6F );
P( D, E, F, G, H, A, B, C, R(21), 0x4A7484AA );
P( C, D, E, F, G, H, A, B, R(22), 0x5CB0A9DC );
P( B, C, D, E, F, G, H, A, R(23), 0x76F988DA );
P( A, B, C, D, E, F, G, H, R(24), 0x983E5152 );
P( H, A, B, C, D, E, F, G, R(25), 0xA831C66D );
P( G, H, A, B, C, D, E, F, R(26), 0xB00327C8 );
P( F, G, H, A, B, C, D, E, R(27), 0xBF597FC7 );
P( E, F, G, H, A, B, C, D, R(28), 0xC6E00BF3 );
P( D, E, F, G, H, A, B, C, R(29), 0xD5A79147 );
P( C, D, E, F, G, H, A, B, R(30), 0x06CA6351 );
P( B, C, D, E, F, G, H, A, R(31), 0x14292967 );
P( A, B, C, D, E, F, G, H, R(32), 0x27B70A85 );
P( H, A, B, C, D, E, F, G, R(33), 0x2E1B2138 );
P( G, H, A, B, C, D, E, F, R(34), 0x4D2C6DFC );
P( F, G, H, A, B, C, D, E, R(35), 0x53380D13 );
P( E, F, G, H, A, B, C, D, R(36), 0x650A7354 );
P( D, E, F, G, H, A, B, C, R(37), 0x766A0ABB );
P( C, D, E, F, G, H, A, B, R(38), 0x81C2C92E );
P( B, C, D, E, F, G, H, A, R(39), 0x92722C85 );
P( A, B, C, D, E, F, G, H, R(40), 0xA2BFE8A1 );
P( H, A, B, C, D, E, F, G, R(41), 0xA81A664B );
P( G, H, A, B, C, D, E, F, R(42), 0xC24B8B70 );
P( F, G, H, A, B, C, D, E, R(43), 0xC76C51A3 );
P( E, F, G, H, A, B, C, D, R(44), 0xD192E819 );
P( D, E, F, G, H, A, B, C, R(45), 0xD6990624 );
P( C, D, E, F, G, H, A, B, R(46), 0xF40E3585 );
P( B, C, D, E, F, G, H, A, R(47), 0x106AA070 );
P( A, B, C, D, E, F, G, H, R(48), 0x19A4C116 );
P( H, A, B, C, D, E, F, G, R(49), 0x1E376C08 );
P( G, H, A, B, C, D, E, F, R(50), 0x2748774C );
P( F, G, H, A, B, C, D, E, R(51), 0x34B0BCB5 );
P( E, F, G, H, A, B, C, D, R(52), 0x391C0CB3 );
P( D, E, F, G, H, A, B, C, R(53), 0x4ED8AA4A );
P( C, D, E, F, G, H, A, B, R(54), 0x5B9CCA4F );
P( B, C, D, E, F, G, H, A, R(55), 0x682E6FF3 );
P( A, B, C, D, E, F, G, H, R(56), 0x748F82EE );
P( H, A, B, C, D, E, F, G, R(57), 0x78A5636F );
P( G, H, A, B, C, D, E, F, R(58), 0x84C87814 );
P( F, G, H, A, B, C, D, E, R(59), 0x8CC70208 );
P( E, F, G, H, A, B, C, D, R(60), 0x90BEFFFA );
P( D, E, F, G, H, A, B, C, R(61), 0xA4506CEB );
P( C, D, E, F, G, H, A, B, R(62), 0xBEF9A3F7 );
P( B, C, D, E, F, G, H, A, R(63), 0xC67178F2 );
ctx->state[0] += A;
ctx->state[1] += B;
ctx->state[2] += C;
ctx->state[3] += D;
ctx->state[4] += E;
ctx->state[5] += F;
ctx->state[6] += G;
ctx->state[7] += H;
}
HT_API void sha256_update(sha256_context *ctx, uint8 *input, uint32 length)
{
uint32 left, fill;
if (!length)
{
return;
}
left = ctx->total[0] & 0x3F;
fill = 64 - left;
ctx->total[0] += length;
ctx->total[0] &= 0xFFFFFFFF;
if (ctx->total[0] < length)
{
ctx->total[1]++;
}
if (left && length >= fill)
{
memcpy((void *) (ctx->buffer + left), (void *) input, fill);
sha256_process(ctx, ctx->buffer);
length -= fill;
input += fill;
left = 0;
}
while (length >= 64)
{
sha256_process(ctx, input);
length -= 64;
input += 64;
}
if (length)
{
memcpy((void *) (ctx->buffer + left), (void *) input, length);
}
}
HT_API void sha256_finish(sha256_context *ctx, uint8 digest[32])
{
uint32 last, padn;
uint32 high, low;
uint8 msglen[8];
uint8 padding[64];
high = (ctx->total[0] >> 29) | (ctx->total[1] << 3);
low = (ctx->total[0] << 3);
PUT_UINT32(high, msglen, 0);
PUT_UINT32(low, msglen, 4);
last = ctx->total[0] & 0x3F;
padn = (last < 56) ? (56 - last) : (120 - last);
memset(padding, 0, sizeof(padding));
padding[0] = 0x80;
sha256_update(ctx, padding, padn);
sha256_update(ctx, msglen, 8);
PUT_UINT32(ctx->state[0], digest, 0);
PUT_UINT32(ctx->state[1], digest, 4);
PUT_UINT32(ctx->state[2], digest, 8);
PUT_UINT32(ctx->state[3], digest, 12);
PUT_UINT32(ctx->state[4], digest, 16);
PUT_UINT32(ctx->state[5], digest, 20);
PUT_UINT32(ctx->state[6], digest, 24);
PUT_UINT32(ctx->state[7], digest, 28);
}

44
MediaClient/bm/sha256.h Normal file
View File

@@ -0,0 +1,44 @@
/***************************************************************************************
*
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
*
* By downloading, copying, installing or using the software you agree to this license.
* If you do not agree to this license, do not download, install,
* copy or use the software.
*
* Copyright (C) 2014-2024, Happytimesoft Corporation, all rights reserved.
*
* Redistribution and use in binary forms, with or without modification, are permitted.
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************************/
#ifndef _SHA256_H_
#define _SHA256_H_
typedef struct
{
uint32 total[2];
uint32 state[8];
uint8 buffer[64];
} sha256_context;
#ifdef __cplusplus
extern "C" {
#endif
HT_API void sha256_starts(sha256_context *ctx);
HT_API void sha256_update(sha256_context *ctx, uint8 *input, uint32 length);
HT_API void sha256_finish(sha256_context *ctx, uint8 digest[32]);
#ifdef __cplusplus
}
#endif
#endif

201
MediaClient/bm/sys_buf.cpp Normal file
View File

@@ -0,0 +1,201 @@
/***************************************************************************************
*
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
*
* By downloading, copying, installing or using the software you agree to this license.
* If you do not agree to this license, do not download, install,
* copy or use the software.
*
* Copyright (C) 2014-2024, Happytimesoft Corporation, all rights reserved.
*
* Redistribution and use in binary forms, with or without modification, are permitted.
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************************/
#include "sys_inc.h"
#include "sys_buf.h"
/***************************************************************************************/
PPSN_CTX * net_buf_fl = NULL;
PPSN_CTX * hdrv_buf_fl = NULL;
static int net_buffer_init_count = 0;
static int hdrv_buf_init_count = 0;
/***************************************************************************************/
HT_API BOOL net_buf_init(int num, int size)
{
net_buffer_init_count++;
if (net_buf_fl)
{
return TRUE;
}
net_buf_fl = pps_ctx_fl_init(num, size, TRUE);
if (net_buf_fl == NULL)
{
return FALSE;
}
log_print(HT_LOG_INFO, "%s, num = %lu\r\n", __FUNCTION__, net_buf_fl->node_num);
return TRUE;
}
HT_API char * net_buf_get_idle()
{
return (char *)pps_fl_pop(net_buf_fl);
}
HT_API void net_buf_free(char * rbuf)
{
if (rbuf == NULL)
{
return;
}
if (pps_safe_node(net_buf_fl, rbuf))
{
pps_fl_push_tail(net_buf_fl, rbuf);
}
else
{
free(rbuf);
}
}
HT_API uint32 net_buf_get_size()
{
if (net_buf_fl == NULL)
{
return 0;
}
return (net_buf_fl->unit_size - sizeof(PPSN));
}
HT_API uint32 net_buf_idle_num()
{
if (net_buf_fl == NULL)
{
return 0;
}
return net_buf_fl->node_num;
}
HT_API void net_buf_deinit()
{
net_buffer_init_count--;
if (net_buffer_init_count == 0) {
if (net_buf_fl)
{
pps_fl_free(net_buf_fl);
net_buf_fl = NULL;
}
}
if (net_buffer_init_count < 0)net_buffer_init_count=0;//Reset
}
HT_API BOOL hdrv_buf_init(int num)
{
hdrv_buf_init_count++;
if (hdrv_buf_fl)
{
return TRUE;
}
hdrv_buf_fl = pps_ctx_fl_init(num, sizeof(HDRV), TRUE);
if (hdrv_buf_fl == NULL)
{
return FALSE;
}
log_print(HT_LOG_INFO, "%s, num = %lu\r\n", __FUNCTION__, hdrv_buf_fl->node_num);
return TRUE;
}
HT_API void hdrv_buf_deinit()
{
hdrv_buf_init_count--;
if (hdrv_buf_init_count == 0) {
if (hdrv_buf_fl)
{
pps_fl_free(hdrv_buf_fl);
hdrv_buf_fl = NULL;
}
}
if (hdrv_buf_init_count < 0)hdrv_buf_init_count = 0;
}
HT_API HDRV * hdrv_buf_get_idle()
{
HDRV * p_ret = (HDRV *)pps_fl_pop(hdrv_buf_fl);
return p_ret;
}
HT_API void hdrv_buf_free(HDRV * pHdrv)
{
if (pHdrv == NULL)
{
return;
}
pHdrv->header[0] = '\0';
pHdrv->value_string = NULL;
pps_fl_push(hdrv_buf_fl, pHdrv);
}
HT_API uint32 hdrv_buf_idle_num()
{
if (NULL == hdrv_buf_fl)
{
return 0;
}
return hdrv_buf_fl->node_num;
}
HT_API void hdrv_ctx_ul_init(PPSN_CTX * ul_ctx)
{
pps_ctx_ul_init_nm(hdrv_buf_fl, ul_ctx);
}
HT_API void hdrv_ctx_free(PPSN_CTX * p_ctx)
{
HDRV * p_free;
if (p_ctx == NULL)
{
return;
}
p_free = (HDRV *)pps_lookup_start(p_ctx);
while (p_free != NULL)
{
HDRV * p_next = (HDRV *)pps_lookup_next(p_ctx, p_free);
pps_ctx_ul_del(p_ctx, p_free);
hdrv_buf_free(p_free);
p_free = p_next;
}
pps_lookup_end(p_ctx);
}
HT_API BOOL sys_buf_init(int nums)
{
if (net_buf_init(nums, 2048) == FALSE)
{
log_print(HT_LOG_ERR, "%s, net_buf_init failed!!!\r\n", __FUNCTION__);
return FALSE;
}
if (hdrv_buf_init(8*nums) == FALSE)
{
log_print(HT_LOG_ERR, "%s, hdrv_buf_init failed!!!\r\n", __FUNCTION__);
return FALSE;
}
return TRUE;
}
HT_API void sys_buf_deinit()
{
net_buf_deinit();
hdrv_buf_deinit();
}

116
MediaClient/bm/sys_buf.h Normal file
View File

@@ -0,0 +1,116 @@
/***************************************************************************************
*
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
*
* By downloading, copying, installing or using the software you agree to this license.
* If you do not agree to this license, do not download, install,
* copy or use the software.
*
* Copyright (C) 2014-2024, Happytimesoft Corporation, all rights reserved.
*
* Redistribution and use in binary forms, with or without modification, are permitted.
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************************/
#ifndef SYS_BUF_H
#define SYS_BUF_H
/***************************************************************************************/
#define MAX_AVN 8
#define MAX_AVDESCLEN 500
#define MAX_USRL 64
#define MAX_PWDL 32
#define MAX_NUML 64
#define MAX_UA_ALT_NUM 8
/***************************************************************************************/
typedef struct header_value
{
char header[32];
char * value_string;
} HDRV;
typedef struct ua_rtp_info
{
int rtp_cnt;
uint32 rtp_ssrc;
uint32 rtp_ts;
uint8 rtp_pt;
} UA_RTP_INFO;
typedef struct
{
/* rtcp sender statistics */
int64 last_rtcp_ntp_time;
int64 first_rtcp_ntp_time;
uint32 packet_count;
uint32 octet_count;
uint32 last_octet_count;
int first_packet;
char cname[64];
} UA_RTCP_INFO;
typedef struct http_digest_auth_info
{
char auth_name[MAX_USRL];
char auth_pwd[64];
char auth_uri[256];
char auth_qop[32];
char auth_nonce[128];
char auth_cnonce[128];
char auth_realm[128];
char auth_algorithm[32];
int auth_opaque_flag;
char auth_opaque[128];
int auth_nc;
char auth_ncstr[12];
char auth_response[100];
} HD_AUTH_INFO;
#ifdef __cplusplus
extern "C" {
#endif
extern HT_API PPSN_CTX * hdrv_buf_fl;
/***********************************************************************/
HT_API BOOL net_buf_init(int num, int size);
HT_API void net_buf_deinit();
HT_API char * net_buf_get_idle();
HT_API void net_buf_free(char * rbuf);
HT_API uint32 net_buf_get_size();
HT_API uint32 net_buf_idle_num();
/***********************************************************************/
HT_API BOOL hdrv_buf_init(int num);
HT_API void hdrv_buf_deinit();
HT_API HDRV * hdrv_buf_get_idle();
HT_API void hdrv_buf_free(HDRV * pHdrv);
HT_API uint32 hdrv_buf_idle_num();
HT_API void hdrv_ctx_ul_init(PPSN_CTX * ul_ctx);
HT_API void hdrv_ctx_free(PPSN_CTX * p_ctx);
/***********************************************************************/
HT_API BOOL sys_buf_init(int nums);
HT_API void sys_buf_deinit();
/***********************************************************************/
#ifdef __cplusplus
}
#endif
#endif // SYS_BUF_H

185
MediaClient/bm/sys_inc.h Normal file
View File

@@ -0,0 +1,185 @@
/***************************************************************************************
*
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
*
* By downloading, copying, installing or using the software you agree to this license.
* If you do not agree to this license, do not download, install,
* copy or use the software.
*
* Copyright (C) 2014-2024, Happytimesoft Corporation, all rights reserved.
*
* Redistribution and use in binary forms, with or without modification, are permitted.
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************************/
#ifndef __SYS_INC_H__
#define __SYS_INC_H__
#if defined(_WIN32) || defined(_WIN64)
#define __WINDOWS_OS__ 1
#define __LINUX_OS__ 0
#else
#define __WINDOWS_OS__ 0
#define __LINUX_OS__ 1
#endif
#if __WINDOWS_OS__
#ifdef HT_EXPORTS
#define HT_API __declspec(dllexport)
#else
#define HT_API __declspec(dllimport)
#endif
#ifdef HT_STATIC
#undef HT_API
#define HT_API
#endif
#else
#define HT_API
#endif
/***************************************************************************************/
//typedef int int32;
typedef unsigned int uint32;
typedef unsigned short uint16;
typedef unsigned char uint8;
/***************************************************************************************/
#if __WINDOWS_OS__
#include "stdafx.h"
#include <io.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <time.h>
#include <process.h> /* _beginthread, _endthread */
#include <iphlpapi.h>
#include <assert.h>
#define sleep(x) Sleep((x) * 1000)
#define usleep(x) Sleep((x) / 1000)
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
#define snprintf _snprintf
#define pthread_t DWORD
typedef __int64 int64;
typedef unsigned __int64 uint64;
#pragma comment(lib, "iphlpapi.lib")
#pragma comment(lib, "ws2_32.lib")
#elif __LINUX_OS__
#include <sys/types.h>
#include <sys/ipc.h>
#ifndef ANDROID
#include <sys/sem.h>
#endif
#include <semaphore.h>
#include <signal.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#ifndef IOS
#include <linux/netlink.h>
#include <netinet/udp.h>
#include <sys/prctl.h>
#include <sys/epoll.h>
#endif
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <net/if.h>
#include <sys/resource.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <ctype.h>
#include <unistd.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#include <assert.h>
#include <pthread.h>
#include <dlfcn.h>
#include <dirent.h>
#ifdef IOS
#include <ifaddrs.h>
#endif
typedef signed char BOOL;
typedef int SOCKET;
typedef int64_t int64;
typedef uint64_t uint64;
#define TRUE 1
#define FALSE 0
#define closesocket close
#endif
/*************************************************************************/
#include "sys_log.h"
#include "ppstack.h"
#include "word_analyse.h"
#include "sys_buf.h"
#include "util.h"
#ifdef __cplusplus
extern "C" {
#endif
HT_API void * sys_os_create_mutex();
HT_API void * sys_os_create_sig();
HT_API void sys_os_destroy_sig_mutex(void * ptr);
HT_API int sys_os_mutex_enter(void * p_sem);
HT_API void sys_os_mutex_leave(void * p_sem);
HT_API int sys_os_sig_wait(void * p_sig);
HT_API int sys_os_sig_wait_timeout(void * p_sig, uint32 ms);
HT_API void sys_os_sig_sign(void * p_sig);
HT_API pthread_t sys_os_create_thread(void * thread_func, void * argv);
HT_API uint32 sys_os_get_ms();
HT_API uint32 sys_os_get_uptime();
HT_API char * sys_os_get_socket_error();
HT_API int sys_os_get_socket_error_num();
#ifdef __cplusplus
}
#endif
#endif // __SYS_INC_H__

447
MediaClient/bm/sys_log.cpp Normal file
View File

@@ -0,0 +1,447 @@
/***************************************************************************************
*
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
*
* By downloading, copying, installing or using the software you agree to this license.
* If you do not agree to this license, do not download, install,
* copy or use the software.
*
* Copyright (C) 2014-2024, Happytimesoft Corporation, all rights reserved.
*
* Redistribution and use in binary forms, with or without modification, are permitted.
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************************/
#include "sys_inc.h"
#include "sys_log.h"
/***************************************************************************************/
HT_LOG_CTX g_log_ctx = {
NULL,
NULL,
HT_LOG_ERR, // default log level
0,
1024, // Maximum file size in KB
0,
3, // Maximum file indexes
1, // Loop write log flag
0
};
static const char * g_log_level_str[] =
{
"TRACE",
"DEBUG",
"INFO",
"WARN",
"ERROR",
"FATAL"
};
/***************************************************************************************/
void log_get_name(const char * log_fname, char * name, int size)
{
const char * p;
p = strrchr(log_fname, '.');
if (p)
{
char fname[256] = {'\0'};
int len = p - log_fname;
len = (len <= size ? len : size);
strncpy(fname, log_fname, len);
p++;
if (*p == '\0')
{
p = "log";
}
snprintf(name, size, "%s-%d.%s", fname, g_log_ctx.cur_idx+1, p);
}
else
{
snprintf(name, size, "%s-%d.log", log_fname, g_log_ctx.cur_idx+1);
}
if (++g_log_ctx.cur_idx >= g_log_ctx.max_idx)
{
g_log_ctx.cur_idx = 0;
}
}
HT_API int log_init(const char * log_fname)
{
char name[256] = {'\0'};
log_close();
if (g_log_ctx.rewind)
{
log_get_name(log_fname, name, sizeof(name)-1);
}
else
{
strncpy(name, log_fname, sizeof(name)-1);
}
g_log_ctx.fp = fopen(name, "w+");
if (g_log_ctx.fp == NULL)
{
printf("log init fopen[%s] failed[%s]\r\n", name, strerror(errno));
return -1;
}
g_log_ctx.cur_size = 0;
g_log_ctx.mutex = sys_os_create_mutex();
if (g_log_ctx.mutex == NULL)
{
printf("log init mutex failed[%s]\r\n", strerror(errno));
return -1;
}
if (!g_log_ctx.time_init)
{
strncpy(g_log_ctx.name, log_fname, sizeof(g_log_ctx.name)-1);
}
return 0;
}
HT_API int log_time_init(const char * fname_prev)
{
char fpath[256];
time_t time_now = time(NULL);
struct tm * st = localtime(&(time_now));
snprintf(fpath, sizeof(fpath),
"%s-%04d%02d%02d_%02d%02d%02d.log",
fname_prev,
st->tm_year+1900, st->tm_mon+1, st->tm_mday,
st->tm_hour, st->tm_min, st->tm_sec);
g_log_ctx.rewind = 0;
g_log_ctx.time_init = 1;
strncpy(g_log_ctx.name, fname_prev, sizeof(g_log_ctx.name)-1);
return log_init(fpath);
}
HT_API int log_reinit(const char * log_fname)
{
int ret = 0;
char name[256] = {'\0'};
sys_os_mutex_enter(g_log_ctx.mutex);
if (g_log_ctx.fp)
{
fclose(g_log_ctx.fp);
g_log_ctx.fp = NULL;
}
if (g_log_ctx.rewind)
{
log_get_name(log_fname, name, sizeof(name)-1);
}
else
{
strncpy(name, log_fname, sizeof(name)-1);
}
g_log_ctx.fp = fopen(name, "w+");
if (g_log_ctx.fp == NULL)
{
printf("log init fopen[%s] failed[%s]\r\n", name, strerror(errno));
ret = -1;
}
g_log_ctx.cur_size = 0;
if (!g_log_ctx.time_init)
{
strncpy(g_log_ctx.name, log_fname, sizeof(g_log_ctx.name)-1);
}
sys_os_mutex_leave(g_log_ctx.mutex);
return ret;
}
HT_API int log_time_reinit(const char * fname_prev)
{
char fpath[256];
time_t time_now = time(NULL);
struct tm * st = localtime(&(time_now));
snprintf(fpath, sizeof(fpath),
"%s-%04d%02d%02d_%02d%02d%02d.log",
fname_prev,
st->tm_year+1900, st->tm_mon+1, st->tm_mday,
st->tm_hour, st->tm_min, st->tm_sec);
g_log_ctx.rewind = 0;
g_log_ctx.time_init = 1;
strncpy(g_log_ctx.name, fname_prev, sizeof(g_log_ctx.name)-1);
return log_reinit(fpath);
}
HT_API void log_close()
{
sys_os_mutex_enter(g_log_ctx.mutex);
if (g_log_ctx.fp)
{
fclose(g_log_ctx.fp);
g_log_ctx.fp = NULL;
}
sys_os_mutex_leave(g_log_ctx.mutex);
if (g_log_ctx.mutex)
{
sys_os_destroy_sig_mutex(g_log_ctx.mutex);
g_log_ctx.mutex = NULL;
}
}
void log_switch()
{
if (g_log_ctx.cur_size >= g_log_ctx.max_size * 1024)
{
if (g_log_ctx.time_init)
{
log_time_reinit(g_log_ctx.name);
}
else
{
log_reinit(g_log_ctx.name);
}
}
}
int log_print_ex(int level, const char *fmt, va_list argptr)
{
int slen = 0;
time_t time_now;
struct tm * st;
if (g_log_ctx.fp == NULL || g_log_ctx.mutex == NULL)
{
return 0;
}
time_now = time(NULL);
st = localtime(&(time_now));
sys_os_mutex_enter(g_log_ctx.mutex);
if (g_log_ctx.fp)
{
slen = fprintf(g_log_ctx.fp,
"[%04d-%02d-%02d %02d:%02d:%02d] : [%s] ",
st->tm_year+1900, st->tm_mon+1, st->tm_mday,
st->tm_hour, st->tm_min, st->tm_sec,
g_log_level_str[level]);
if (slen > 0)
{
g_log_ctx.cur_size += slen;
}
slen = vfprintf(g_log_ctx.fp, fmt, argptr);
fflush(g_log_ctx.fp);
if (slen > 0)
{
g_log_ctx.cur_size += slen;
}
}
sys_os_mutex_leave(g_log_ctx.mutex);
log_switch();
return slen;
}
#ifndef IOS
HT_API int log_print(int level, const char * fmt,...)
{
if (level < g_log_ctx.level || level > HT_LOG_FATAL)
{
return 0;
}
else
{
int slen;
va_list argptr;
va_start(argptr, fmt);
slen = log_print_ex(level, fmt, argptr);
va_end(argptr);
return slen;
}
}
#else
HT_API int log_ios_print(int level, const char * fmt,...)
{
if (level < g_log_ctx.level || level > HT_LOG_FATAL)
{
return 0;
}
else
{
int slen;
va_list argptr;
va_start(argptr, fmt);
slen = log_print_ex(level, fmt, argptr);
va_end(argptr);
return slen;
}
return 0;
}
#endif
static int log_lock_print_ex(const char *fmt, va_list argptr)
{
int slen;
if (g_log_ctx.fp == NULL || g_log_ctx.mutex == NULL)
{
return 0;
}
slen = vfprintf(g_log_ctx.fp, fmt, argptr);
fflush(g_log_ctx.fp);
if (slen > 0)
{
g_log_ctx.cur_size += slen;
}
return slen;
}
HT_API int log_lock_start(const char * fmt,...)
{
int slen = 0;
va_list argptr;
if (g_log_ctx.fp == NULL || g_log_ctx.mutex == NULL)
{
return 0;
}
va_start(argptr,fmt);
sys_os_mutex_enter(g_log_ctx.mutex);
slen = log_lock_print_ex(fmt,argptr);
va_end(argptr);
return slen;
}
HT_API int log_lock_print(const char * fmt,...)
{
int slen;
va_list argptr;
va_start(argptr,fmt);
slen = log_lock_print_ex(fmt, argptr);
va_end(argptr);
return slen;
}
HT_API int log_lock_end(const char * fmt,...)
{
int slen;
va_list argptr;
va_start(argptr,fmt);
slen = log_lock_print_ex(fmt, argptr);
va_end(argptr);
sys_os_mutex_leave(g_log_ctx.mutex);
log_switch();
return slen;
}
HT_API void log_set_level(int level)
{
g_log_ctx.level = level;
}
HT_API int log_get_level()
{
return g_log_ctx.level;
}
HT_API void log_set_rewind(int rewind)
{
g_log_ctx.rewind = rewind;
}
HT_API int log_get_rewind()
{
return g_log_ctx.rewind;
}
HT_API void log_set_max_size(int max_size)
{
g_log_ctx.max_size = max_size;
}
HT_API int log_get_max_size()
{
return g_log_ctx.max_size;
}
HT_API void log_set_max_idx(int max_idx)
{
g_log_ctx.max_idx = max_idx;
}
HT_API int log_get_max_idx()
{
return g_log_ctx.max_idx;
}

81
MediaClient/bm/sys_log.h Normal file
View File

@@ -0,0 +1,81 @@
/***************************************************************************************
*
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
*
* By downloading, copying, installing or using the software you agree to this license.
* If you do not agree to this license, do not download, install,
* copy or use the software.
*
* Copyright (C) 2014-2024, Happytimesoft Corporation, all rights reserved.
*
* Redistribution and use in binary forms, with or without modification, are permitted.
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************************/
#ifndef __H_SYS_LOG_H__
#define __H_SYS_LOG_H__
// log level
#define HT_LOG_TRC 0
#define HT_LOG_DBG 1
#define HT_LOG_INFO 2
#define HT_LOG_WARN 3
#define HT_LOG_ERR 4
#define HT_LOG_FATAL 5
typedef struct
{
FILE * fp; // Log file pointer
void * mutex; // read-write lock
int level; // Log level
uint32 cur_size; // The current write length of the log
uint32 max_size; // Maximum file size in KB
int cur_idx; // Current log file index
int max_idx; // Maximum file indexes
int rewind; // Loop write log flag
int time_init; // Initialize log file names using system time
char name[256]; // Log file name
} HT_LOG_CTX;
#ifdef __cplusplus
extern "C" {
#endif
HT_API int log_init(const char * log_fname);
HT_API int log_time_init(const char * fname_prev);
HT_API int log_reinit(const char * log_fname);
HT_API int log_time_reinit(const char * fname_prev);
HT_API void log_close();
HT_API void log_set_level(int level);
HT_API int log_get_level();
HT_API void log_set_rewind(int rewind);
HT_API int log_get_rewind();
HT_API void log_set_max_size(int max_size);
HT_API int log_get_max_size();
HT_API void log_set_max_idx(int max_idx);
HT_API int log_get_max_idx();
HT_API int log_lock_start(const char * fmt,...);
HT_API int log_lock_print(const char * fmt,...);
HT_API int log_lock_end(const char * fmt,...);
#ifdef IOS
HT_API int log_ios_print(int level, const char * fmt,...);
#define log_print log_ios_print
#else
HT_API int log_print(int level, const char * fmt,...);
#endif
#ifdef __cplusplus
}
#endif
#endif

448
MediaClient/bm/sys_os.cpp Normal file
View File

@@ -0,0 +1,448 @@
/***************************************************************************************
*
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
*
* By downloading, copying, installing or using the software you agree to this license.
* If you do not agree to this license, do not download, install,
* copy or use the software.
*
* Copyright (C) 2014-2024, Happytimesoft Corporation, all rights reserved.
*
* Redistribution and use in binary forms, with or without modification, are permitted.
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************************/
/***************************************************************************************/
#include "sys_inc.h"
/***************************************************************************************/
HT_API void * sys_os_create_mutex()
{
void * p_mutex = NULL;
#ifdef IOS
static int index = 0;
char name[32] = {'\0'};
snprintf(name, sizeof(name), "testmutex%u", (uint32)time(NULL)+index++);
p_mutex = sem_open(name, O_CREAT, 0644, 1);
if (p_mutex == SEM_FAILED)
{
log_print(HT_LOG_ERR, "%s, sem_open failed. name=%s\r\n", __FUNCTION__, name);
return NULL;
}
#elif __WINDOWS_OS__
p_mutex = CreateMutex(NULL, FALSE, NULL);
#elif __LINUX_OS__
int ret;
p_mutex = (sem_t *)malloc(sizeof(sem_t));
ret = sem_init((sem_t *)p_mutex, 0, 1);
if (ret != 0)
{
free(p_mutex);
return NULL;
}
#endif
return p_mutex;
}
HT_API void * sys_os_create_sig()
{
void * p_sig = NULL;
#ifdef IOS
static int index = 0;
char name[32] = {'\0'};
snprintf(name, sizeof(name), "testsig%u", (uint32)time(NULL)+index++);
p_sig = sem_open(name, O_CREAT, 0644, 1);
if (p_sig == SEM_FAILED)
{
log_print(HT_LOG_ERR, "%s, sem_open failed. name=%s\r\n", __FUNCTION__, name);
return NULL;
}
#elif __WINDOWS_OS__
p_sig = CreateEvent(NULL, FALSE, FALSE, NULL);
#elif __LINUX_OS__
int ret;
p_sig = malloc(sizeof(sem_t));
ret = sem_init((sem_t *)p_sig, 0, 0);
if (ret != 0)
{
free(p_sig);
return NULL;
}
#endif
return p_sig;
}
HT_API void sys_os_destroy_sig_mutex(void * ptr)
{
if (ptr == NULL)
{
return;
}
#ifdef IOS
sem_close((sem_t *)ptr);
#elif __WINDOWS_OS__
CloseHandle(ptr);
#elif __LINUX_OS__
sem_destroy((sem_t *)ptr);
free(ptr);
#endif
}
HT_API int sys_os_mutex_enter(void * p_sem)
{
int ret;
if (p_sem == NULL)
{
return -1;
}
#if __LINUX_OS__
ret = sem_wait((sem_t *)p_sem);
if (ret != 0)
{
return -1;
}
#elif __WINDOWS_OS__
ret = WaitForSingleObject(p_sem, INFINITE);
if (ret == WAIT_FAILED)
{
return -1;
}
#endif
return 0;
}
HT_API void sys_os_mutex_leave(void * p_sem)
{
if (p_sem == NULL)
{
return;
}
#if __LINUX_OS__
sem_post((sem_t *)p_sem);
#elif __WINDOWS_OS__
ReleaseMutex(p_sem);
#endif
}
HT_API int sys_os_sig_wait(void * p_sig)
{
int ret;
if (p_sig == NULL)
{
return -1;
}
#if __LINUX_OS__
ret = sem_wait((sem_t *)p_sig);
if (ret != 0)
{
return -1;
}
#elif __WINDOWS_OS__
ret = WaitForSingleObject(p_sig, INFINITE);
if (ret == WAIT_FAILED)
{
return -1;
}
#endif
return 0;
}
HT_API int sys_os_sig_wait_timeout(void * p_sig, uint32 ms)
{
#ifdef IOS
if (p_sig == NULL)
{
return -1;
}
while (ms > 0)
{
if (sem_trywait((sem_t *)p_sig) == 0)
{
return 0;
}
usleep(1000);
ms -= 1;
}
return -1;
#elif __LINUX_OS__
int ret;
struct timespec ts;
struct timeval tt;
if (p_sig == NULL)
{
return -1;
}
gettimeofday(&tt,NULL);
tt.tv_sec = tt.tv_sec + ms / 1000;
tt.tv_usec = tt.tv_usec + (ms % 1000) * 1000;
tt.tv_sec += tt.tv_usec / (1000 * 1000);
tt.tv_usec = tt.tv_usec % (1000 * 1000);
ts.tv_sec = tt.tv_sec;
ts.tv_nsec = tt.tv_usec * 1000;
ret = sem_timedwait((sem_t *)p_sig, &ts);
if (ret == -1 && errno == ETIMEDOUT)
{
return -1;
}
else
{
return 0;
}
#elif __WINDOWS_OS__
DWORD ret;
if (p_sig == NULL)
{
return -1;
}
ret = WaitForSingleObject(p_sig, ms);
if (ret == WAIT_FAILED)
{
return -1;
}
else if (ret == WAIT_TIMEOUT)
{
return -1;
}
#endif
return 0;
}
HT_API void sys_os_sig_sign(void * p_sig)
{
if (p_sig == NULL)
{
return;
}
#if __LINUX_OS__
sem_post((sem_t *)p_sig);
#elif __WINDOWS_OS__
SetEvent(p_sig);
#endif
}
HT_API pthread_t sys_os_create_thread(void * thread_func, void * argv)
{
pthread_t tid = 0;
#if __LINUX_OS__
int ret = pthread_create(&tid, NULL, (void *(*)(void *))thread_func, argv);
if (ret != 0)
{
log_print(HT_LOG_ERR, "%s, pthread_create failed, ret = %d\r\n", __FUNCTION__, ret);
}
pthread_detach(tid);
#elif __WINDOWS_OS__
HANDLE hret = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)thread_func, argv, 0, &tid);
if (hret == NULL || tid == 0)
{
log_print(HT_LOG_ERR, "%s, CreateThread hret=%u, tid=%u, err=%u\r\n", __FUNCTION__, hret, tid, GetLastError());
}
CloseHandle(hret);
#endif
return tid;
}
HT_API uint32 sys_os_get_ms()
{
uint32 ms = 0;
#if __LINUX_OS__
struct timeval tv;
gettimeofday(&tv, NULL);
ms = tv.tv_sec * 1000 + tv.tv_usec/1000;
#elif __WINDOWS_OS__
ms = GetTickCount();
#endif
return ms;
}
HT_API uint32 sys_os_get_uptime()
{
uint32 upt = 0;
#ifdef ANDROID
upt = (uint32)time(NULL);
#elif __LINUX_OS__
int rlen;
char bufs[512];
char * ptr;
FILE * file;
file = fopen("/proc/uptime", "rb");
if (NULL == file)
{
return (uint32)time(NULL);
}
rlen = fread(bufs, 1, sizeof(bufs)-1, file);
fclose(file);
if (rlen <= 0)
{
return (uint32)time(NULL);
}
bufs[rlen] = '\0';
ptr = bufs;
while (*ptr != '\0' && *ptr != ' ' && *ptr != '\r' && *ptr != '\n')
{
ptr++;
}
if (*ptr == ' ')
{
*ptr = '\0';
}
else
{
return (uint32)time(NULL);
}
upt = (uint32)strtod(bufs, NULL);
#elif __WINDOWS_OS__
LARGE_INTEGER freq;
LARGE_INTEGER cur;
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&cur);
upt = (uint32) (cur.QuadPart / freq.QuadPart);
#endif
return upt;
}
HT_API char * sys_os_get_socket_error()
{
char * p_estr = NULL;
#if __LINUX_OS__
p_estr = strerror(errno);
#elif __WINDOWS_OS__
int err = WSAGetLastError();
static char err_buf[24];
snprintf(err_buf, sizeof(err_buf), "WSAE-%d", err);
p_estr = err_buf;
#endif
return p_estr;
}
HT_API int sys_os_get_socket_error_num()
{
int sockerr;
#if __LINUX_OS__
sockerr = errno;
#elif __WINDOWS_OS__
sockerr = WSAGetLastError();
#endif
return sockerr;
}

1687
MediaClient/bm/util.cpp Normal file

File diff suppressed because it is too large Load Diff

94
MediaClient/bm/util.h Normal file
View File

@@ -0,0 +1,94 @@
/***************************************************************************************
*
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
*
* By downloading, copying, installing or using the software you agree to this license.
* If you do not agree to this license, do not download, install,
* copy or use the software.
*
* Copyright (C) 2014-2024, Happytimesoft Corporation, all rights reserved.
*
* Redistribution and use in binary forms, with or without modification, are permitted.
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************************/
#ifndef __H_UTIL_H__
#define __H_UTIL_H__
/*************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
/*************************************************************************/
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ARRAY_SIZE(ary) (sizeof(ary) / sizeof(ary[0]))
/*************************************************************************/
HT_API int get_if_nums();
HT_API uint32 get_if_ip(int index);
HT_API uint32 get_route_if_ip(uint32 dst_ip);
HT_API uint32 get_default_if_ip();
HT_API const char * get_local_ip();
HT_API uint32 get_if_mask(int index);
HT_API uint32 get_route_if_mask(uint32 dst_ip);
HT_API uint32 get_default_if_mask();
HT_API int is_local_if_net(uint32 destip);
HT_API int get_default_if_mac(uint8 * mac);
HT_API uint32 get_address_by_name(const char * host_name);
HT_API const char * get_default_gateway();
HT_API const char * get_dns_server();
HT_API const char * get_mask_by_prefix_len(int len);
HT_API int get_prefix_len_by_mask(const char * mask);
HT_API const char * get_ip_str(uint32 ipaddr /* network byte order */);
/*************************************************************************/
HT_API char * lowercase(char * str);
HT_API char * uppercase(char * str);
HT_API int unicode(char ** dst, char * src);
HT_API BOOL bin_to_hex_str(uint8 * bin, int binlen, char * hex, int hexlen);
HT_API int hex_str_to_bin(char * hex, int hexlen, uint8 * bin, int binlen);
HT_API int url_encode(const char * src, const int srcsize, char * dst, const int dstsize);
HT_API int url_decode(char * dst, char const * src, uint32 len);
HT_API void url_split(char const* url, char *proto, int proto_size, char *user, int user_size, char *pass, int pass_size, char *host, int host_size, int *port, char *path, int path_size);
/*************************************************************************/
HT_API time_t get_time_by_string(char * p_time_str);
HT_API void get_time_str(char * buff, int len);
HT_API void get_time_str_day_off(time_t nt, char * buff, int len, int dayoff);
HT_API void get_time_str_mon_off(time_t nt, char * buff, int len, int moffset);
HT_API time_t get_time_by_tstring(const char * p_time_str);
HT_API void get_tstring_by_time(time_t t, char * buff, int len);
HT_API SOCKET tcp_connect_timeout(uint32 rip, int port, int timeout);
/*************************************************************************/
HT_API void network_init();
HT_API void network_deinit();
HT_API int daemon_init();
#if __WINDOWS_OS__
HT_API int gettimeofday(struct timeval* tp, int* tz);
#endif
#ifdef __cplusplus
}
#endif
#endif // __H_UTIL_H__

View File

@@ -0,0 +1,566 @@
/***************************************************************************************
*
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
*
* By downloading, copying, installing or using the software you agree to this license.
* If you do not agree to this license, do not download, install,
* copy or use the software.
*
* Copyright (C) 2014-2024, Happytimesoft Corporation, all rights reserved.
*
* Redistribution and use in binary forms, with or without modification, are permitted.
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************************/
/***************************************************************************************/
#include "sys_inc.h"
#include "word_analyse.h"
/***************************************************************************************/
HT_API BOOL is_char(char ch)
{
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch == '#') || (ch == '@') || (ch == '/'))
{
return TRUE;
}
return FALSE;
}
HT_API BOOL is_num(char ch)
{
if (ch >= '0' && ch <= '9')
{
return TRUE;
}
return FALSE;
}
static char separator[] = {' ','\t','\r','\n',',',':','{','}','(',')','\0','\'','"','?','<','>','=',';'};
HT_API BOOL is_separator(char ch)
{
uint32 i;
for (i=0; i<sizeof(separator); i++)
{
if (separator[i] == ch)
{
return TRUE;
}
}
return FALSE;
}
HT_API BOOL is_ip_address(const char * address)
{
int i;
int index = 0;
uint16 byte_value;
int total_len = (int)strlen(address);
if (total_len > 15)
{
return FALSE;
}
for (i=0; i<4; i++)
{
if ((address[index] < '0') || (address[index] > '9'))
{
return FALSE;
}
if (((address[index +1] < '0') || (address[index +1] > '9')) && (address[index +1] != '.'))
{
if ((address[index +1] == '\0') && (i == 3))
{
return TRUE;
}
return FALSE;
}
if (address[index +1] == '.')
{
index+=2;
continue;
}
if (((address[index +2] < '0') || (address[index +2] > '9')) && (address[index +2] != '.'))
{
if ((address[index +2] == '\0') && (i == 3))
{
return TRUE;
}
return FALSE;
}
if (address[index +2] == '.')
{
index+=3;
continue;
}
if (i < 3)
{
if (address[index +3] != '.')
{
return FALSE;
}
}
byte_value = (address[index] - '0') *100 + (address[index +1] -'0') *10 + (address[index +2] - '0');
if (byte_value > 255)
{
return FALSE;
}
if (i < 3)
{
index += 4;
}
else
{
index += 3;
}
}
if (index != total_len)
{
return FALSE;
}
return TRUE;
}
HT_API BOOL is_integer(char * p_str)
{
int i;
int len = (int)strlen(p_str);
for (i=0; i<len; i++)
{
if (!is_num(p_str[i]))
{
return FALSE;
}
}
return TRUE;
}
HT_API BOOL GetLineText(char * buf, int cur_line_offset, int max_len, int * len, int * next_line_offset)
{
char * ptr_start = buf+cur_line_offset;
char * ptr_end = ptr_start;
int line_len;
BOOL bHaveNextLine = TRUE;
while ((*ptr_end != '\r') && (*ptr_end != '\n') && (*ptr_end != '\0') && ((ptr_end - ptr_start) < max_len))
{
ptr_end++;
}
while (*(ptr_end-1) == ',')
{
while ((*ptr_end == '\r') || (*ptr_end == '\n'))
{
*ptr_end = ' ';
ptr_end++;
}
while ((*ptr_end != '\r') && (*ptr_end != '\n') && (*ptr_end != '\0') && ((ptr_end - ptr_start) < max_len))
{
ptr_end++;
}
}
line_len = (int)(ptr_end - ptr_start);
if ((*ptr_end == '\r') && (*(ptr_end+1) == '\n'))
{
line_len += 2;
if (line_len == max_len)
{
bHaveNextLine = FALSE;
}
}
else if(*ptr_end == '\n')
{
line_len += 1;
if (line_len == max_len)
{
bHaveNextLine = FALSE;
}
}
else if ((*ptr_end == '\0') || ((ptr_end - ptr_start) < max_len))
{
bHaveNextLine = FALSE;
}
else
{
bHaveNextLine = FALSE;
}
*len = (int)(ptr_end - ptr_start);
*next_line_offset = cur_line_offset + line_len;
return bHaveNextLine;
}
HT_API BOOL GetSipLine(char * p_buf, int max_len, int * len, BOOL * bHaveNextLine)
{
char * ptr_start = p_buf;
char * ptr_end = ptr_start;
int line_len;
*bHaveNextLine = TRUE;
while ((*ptr_end != '\0') && (!((*ptr_end == '\r') || (*ptr_end == '\n'))) && ((ptr_end - ptr_start) < max_len))
{
ptr_end++;
}
while (*(ptr_end-1) == ',')
{
while ((*ptr_end == '\r') || (*ptr_end == '\n'))
{
*ptr_end = ' ';
ptr_end++;
}
while ((*ptr_end != '\r') && (*ptr_end != '\n') && (*ptr_end != '\0') && ((ptr_end - ptr_start) < max_len))
{
ptr_end++;
}
}
line_len = (int)(ptr_end - ptr_start);
if (((*ptr_end == '\r') && (*(ptr_end+1) == '\n')) || ((*ptr_end == '\n') && (*(ptr_end+1) == '\n')))
{
*ptr_end = '\0';
*(ptr_end+1) = '\0';
line_len += 2;
if (line_len == max_len)
{
*bHaveNextLine = FALSE;
}
*len = line_len;
return TRUE;
}
else if ((*ptr_end == '\r') || (*ptr_end == '\n'))
{
*ptr_end = '\0';
line_len += 1;
if (line_len == max_len)
{
*bHaveNextLine = FALSE;
}
*len = line_len;
return TRUE;
}
else if (*ptr_end == '\0')
{
if (line_len == max_len)
{
*bHaveNextLine = FALSE;
}
*len = line_len;
return TRUE;
}
else
{
return FALSE;
}
}
HT_API BOOL GetLineWord(char * line, int cur_word_offset, int line_max_len, char * word_buf, int buf_len, int * next_word_offset, WORD_TYPE w_t)
{
int len;
char * ptr_start = line+cur_word_offset;
char * ptr_end;
BOOL bHaveNextWord = TRUE;
word_buf[0] = '\0';
while (((*ptr_start == ' ') || (*ptr_start == '\t')) && (cur_word_offset < line_max_len))
{
cur_word_offset++;
ptr_start++;
}
if (*ptr_start == '\0')
{
return FALSE;
}
ptr_end = ptr_start;
while ((!is_separator(*ptr_end)) && ((ptr_end - ptr_start) < line_max_len))
{
ptr_end++;
}
len = (int)(ptr_end - ptr_start);
if (len >= buf_len)
{
return bHaveNextWord;
}
*next_word_offset = cur_word_offset + len;
if ((*next_word_offset >= line_max_len) || (line[*next_word_offset] == '\0'))
{
bHaveNextWord = FALSE;
}
switch (w_t)
{
case WORD_TYPE_NULL:
break;
case WORD_TYPE_STRING:
if (len == 0 && is_separator(*ptr_end))
{
(*next_word_offset)++;
word_buf[0] = *ptr_end;
word_buf[1] = '\0';
return bHaveNextWord;
}
break;
case WORD_TYPE_NUM:
{
char * ptr;
for (ptr=ptr_start; ptr<ptr_end; ptr++)
{
if (!is_num(*ptr))
{
return bHaveNextWord;
}
}
}
break;
case WORD_TYPE_SEPARATOR:
if (is_separator(*ptr_end))
{
(*next_word_offset)++;
word_buf[0] = *ptr_end;
word_buf[1] = '\0';
return bHaveNextWord;
}
break;
}
memcpy(word_buf, ptr_start, len);
word_buf[len] = '\0';
return bHaveNextWord;
}
HT_API BOOL GetNameValuePair(char * text_buf, int text_len, const char * name, char * value, int value_len)
{
char word_buf[256];
int cur_offset = 0,next_offset = 0;
char * value_start, * value_end;
while (next_offset < text_len)
{
word_buf[0] = '\0';
cur_offset = next_offset;
GetLineWord(text_buf, cur_offset, text_len, word_buf, sizeof(word_buf), &next_offset, WORD_TYPE_STRING);
if (strcmp(word_buf, name) == 0)
{
int len;
char * ptr = text_buf + next_offset;
while ((*ptr == ' ' || *ptr == '\t') && (next_offset <text_len))
{
ptr++;
next_offset++;
}
if ((*ptr == ';') || (*ptr == ',') || (*ptr == '\0'))
{
value[0] = '\0';
return TRUE;
}
if (*ptr != '=')
{
return FALSE;
}
ptr++;
next_offset++;
while ((*ptr == ' ' || *ptr == '\t') && (next_offset <text_len))
{
ptr++;
next_offset++;
}
if (*ptr != '"')
{
value_start = ptr;
while ((*ptr != ';') && (*ptr != ',') && (*ptr != '&') && (next_offset <text_len))
{
ptr++;
next_offset++;
}
if ((*ptr != ';') && (*ptr != ',') && (*ptr != '&') && (*ptr != '\0'))
{
return FALSE;
}
value_end = ptr;
}
else
{
ptr++;
next_offset++;
value_start = text_buf + next_offset;
while ((*ptr != '"') && (next_offset <text_len))
{
ptr++;
next_offset++;
}
if (*ptr != '"')
{
return FALSE;
}
value_end = ptr;
}
len = (int)(value_end - value_start);
if (len > value_len)
{
len = value_len - 1;
}
memcpy(value, value_start, len);
value[len] = '\0';
return TRUE;
}
else
{
char * ptr = text_buf + next_offset;
while((*ptr == ' ' || *ptr == '\t') && (next_offset <text_len))
{
ptr++;
next_offset++;
}
if ((*ptr == ';') || (*ptr == ',') || (*ptr == '&'))
{
next_offset++;
continue;
}
if (*ptr != '=')
{
return FALSE;
}
ptr++;
next_offset++;
while ((*ptr == ' ' || *ptr == '\t') && (next_offset <text_len))
{
ptr++;
next_offset++;
}
if (*ptr != '"')
{
while ((*ptr != ';') && (*ptr != ',') && (*ptr != '&') && (next_offset <text_len))
{
ptr++;
next_offset++;
}
if ((*ptr != ';') && (*ptr != ',') && (*ptr != '&') && (*ptr != '\0'))
{
return FALSE;
}
next_offset++;
}
else
{
ptr++;
next_offset++;
while ((*ptr != '"') && (next_offset <text_len))
{
ptr++;
next_offset++;
}
if (*ptr != '"')
{
return FALSE;
}
ptr++;
next_offset++;
while ((*ptr == ' ' || *ptr == '\t') && (next_offset <text_len))
{
ptr++;
next_offset++;
}
if ((*ptr != ';') && (*ptr != ',') && (*ptr != '&') && (*ptr != '\0'))
{
return FALSE;
}
next_offset++;
}
}
}
return FALSE;
}

View File

@@ -0,0 +1,55 @@
/***************************************************************************************
*
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
*
* By downloading, copying, installing or using the software you agree to this license.
* If you do not agree to this license, do not download, install,
* copy or use the software.
*
* Copyright (C) 2014-2024, Happytimesoft Corporation, all rights reserved.
*
* Redistribution and use in binary forms, with or without modification, are permitted.
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************************/
#ifndef __H_WORD_ANALYSE_H__
#define __H_WORD_ANALYSE_H__
/***************************************************************************************/
typedef enum word_type
{
WORD_TYPE_NULL = 0,
WORD_TYPE_STRING,
WORD_TYPE_NUM,
WORD_TYPE_SEPARATOR
} WORD_TYPE;
#ifdef __cplusplus
extern "C" {
#endif
HT_API BOOL is_char(char ch);
HT_API BOOL is_num(char ch);
HT_API BOOL is_separator(char ch);
HT_API BOOL is_ip_address(const char * address);
HT_API BOOL is_integer(char * p_str);
HT_API BOOL GetLineText(char * buf, int cur_line_offset, int max_len, int * len, int * next_line_offset);
HT_API BOOL GetSipLine(char * p_buf, int max_len, int * len, BOOL * bHaveNextLine);
HT_API BOOL GetLineWord(char * line, int cur_word_offset, int line_max_len, char * word_buf, int buf_len, int * next_word_offset, WORD_TYPE w_t);
HT_API BOOL GetNameValuePair(char * text_buf, int text_len, const char * name, char * value, int value_len);
#ifdef __cplusplus
}
#endif
#endif // __H_WORD_ANALYSE_H__

89
MediaClient/bm/xml_node.h Normal file
View File

@@ -0,0 +1,89 @@
/***************************************************************************************
*
* IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
*
* By downloading, copying, installing or using the software you agree to this license.
* If you do not agree to this license, do not download, install,
* copy or use the software.
*
* Copyright (C) 2014-2024, Happytimesoft Corporation, all rights reserved.
*
* Redistribution and use in binary forms, with or without modification, are permitted.
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************************/
#ifndef XML_NODE_H
#define XML_NODE_H
/***************************************************************************************
*
* XML node define
*
***************************************************************************************/
#define NTYPE_TAG 0
#define NTYPE_ATTRIB 1
#define NTYPE_CDATA 2
#define NTYPE_LAST 2
#define NTYPE_UNDEF -1
typedef struct XMLN
{
int flag; // Is the buffer pointed to by data dynamically allocated memory? If so, it needs to be free
const char * name;
uint32 type;
const char * data;
int dlen;
int finish;
struct XMLN * parent;
struct XMLN * f_child;
struct XMLN * l_child;
struct XMLN * prev;
struct XMLN * next;
struct XMLN * f_attrib;
struct XMLN * l_attrib;
} XMLN;
#ifdef __cplusplus
extern "C" {
#endif
/***************************************************************************************/
HT_API XMLN * xml_node_add(XMLN * parent, const char * name);
HT_API void xml_node_del(XMLN * p_node);
HT_API XMLN * xml_node_get(XMLN * parent, const char * name);
HT_API int soap_strcmp(const char * str1, const char * str2);
HT_API void soap_strncpy(char * dest, const char * src, int size);
HT_API XMLN * xml_node_soap_get(XMLN * parent, const char * name);
/***************************************************************************************/
HT_API XMLN * xml_attr_add(XMLN * p_node, const char * name, const char * value);
HT_API void xml_attr_del(XMLN * p_node, const char * name);
HT_API const char * xml_attr_get(XMLN * p_node, const char * name);
HT_API XMLN * xml_attr_node_get(XMLN * p_node, const char * name);
/***************************************************************************************/
HT_API void xml_cdata_set(XMLN * p_node, const char * value, int len);
/***************************************************************************************/
HT_API int xml_calc_buf_len(XMLN * p_node);
HT_API int xml_write_buf(XMLN * p_node, char * xml_buf, int buf_len);
/***************************************************************************************/
HT_API XMLN * xxx_hxml_parse(char * p_xml, int len);
#ifdef __cplusplus
}
#endif
#endif // XML_NODE_H