White spaces and indentation.
This commit is contained in:
parent
40239ca44a
commit
2da8a7fba1
@ -414,11 +414,11 @@ static void SetSeed(void)
|
||||
|
||||
gettimeofday(&t, NULL);
|
||||
#if defined(WIN32)
|
||||
srand((unsigned int)t.tv_usec + (unsigned int)ithread_get_current_thread_id().p);
|
||||
srand((unsigned int)t.tv_usec + (unsigned int)ithread_get_current_thread_id().p);
|
||||
#elif defined(BSD) || defined(__OSX__) || defined(__APPLE__) || defined(__FreeBSD_kernel__)
|
||||
srand((unsigned int)t.tv_usec + (unsigned int)ithread_get_current_thread_id());
|
||||
srand((unsigned int)t.tv_usec + (unsigned int)ithread_get_current_thread_id());
|
||||
#elif defined(__linux__) || defined(__sun) || defined(__CYGWIN__) || defined(__GLIBC__)
|
||||
srand((unsigned int)t.tv_usec + (unsigned int)ithread_get_current_thread_id());
|
||||
srand((unsigned int)t.tv_usec + (unsigned int)ithread_get_current_thread_id());
|
||||
#else
|
||||
{
|
||||
volatile union {
|
||||
@ -780,9 +780,8 @@ int ThreadPoolAddPersistent(ThreadPool *tp, ThreadPoolJob *job, int *jobId)
|
||||
ithread_cond_signal(&tp->condition);
|
||||
|
||||
/* wait until long job has been picked up */
|
||||
while (tp->persistentJob) {
|
||||
while (tp->persistentJob)
|
||||
ithread_cond_wait(&tp->start_and_shutdown, &tp->mutex);
|
||||
}
|
||||
*jobId = tp->lastJobId++;
|
||||
|
||||
exit_function:
|
||||
@ -798,9 +797,8 @@ int ThreadPoolAdd(ThreadPool *tp, ThreadPoolJob *job, int *jobId)
|
||||
long totalJobs;
|
||||
ThreadPoolJob *temp = NULL;
|
||||
|
||||
if (!tp || !job) {
|
||||
if (!tp || !job)
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
ithread_mutex_lock(&tp->mutex);
|
||||
|
||||
@ -809,38 +807,29 @@ int ThreadPoolAdd(ThreadPool *tp, ThreadPoolJob *job, int *jobId)
|
||||
fprintf(stderr, "total jobs = %ld, too many jobs", totalJobs);
|
||||
goto exit_function;
|
||||
}
|
||||
if (!jobId) {
|
||||
if (!jobId)
|
||||
jobId = &tempId;
|
||||
}
|
||||
*jobId = INVALID_JOB_ID;
|
||||
temp = CreateThreadPoolJob(job, tp->lastJobId, tp);
|
||||
if (!temp) {
|
||||
if (!temp)
|
||||
goto exit_function;
|
||||
}
|
||||
if (job->priority == HIGH_PRIORITY) {
|
||||
if (ListAddTail(&tp->highJobQ, temp)) {
|
||||
if (ListAddTail(&tp->highJobQ, temp))
|
||||
rc = 0;
|
||||
}
|
||||
} else if (job->priority == MED_PRIORITY) {
|
||||
if (ListAddTail(&tp->medJobQ, temp)) {
|
||||
if (ListAddTail(&tp->medJobQ, temp))
|
||||
rc = 0;
|
||||
}
|
||||
} else {
|
||||
if (ListAddTail(&tp->lowJobQ, temp)) {
|
||||
if (ListAddTail(&tp->lowJobQ, temp))
|
||||
rc = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* AddWorker if appropriate */
|
||||
AddWorker(tp);
|
||||
|
||||
/* Notify a waiting thread */
|
||||
if (rc == 0) {
|
||||
if (rc == 0)
|
||||
ithread_cond_signal(&tp->condition);
|
||||
} else {
|
||||
else
|
||||
FreeThreadPoolJob(tp, temp);
|
||||
}
|
||||
|
||||
*jobId = tp->lastJobId++;
|
||||
|
||||
exit_function:
|
||||
@ -856,12 +845,10 @@ int ThreadPoolRemove(ThreadPool *tp, int jobId, ThreadPoolJob *out)
|
||||
ListNode *tempNode = NULL;
|
||||
ThreadPoolJob dummy;
|
||||
|
||||
if (!tp) {
|
||||
if (!tp)
|
||||
return EINVAL;
|
||||
}
|
||||
if (!out) {
|
||||
if (!out)
|
||||
out = &dummy;
|
||||
}
|
||||
dummy.jobId = jobId;
|
||||
|
||||
ithread_mutex_lock(&tp->mutex);
|
||||
@ -910,16 +897,13 @@ exit_function:
|
||||
|
||||
int ThreadPoolGetAttr(ThreadPool *tp, ThreadPoolAttr *out)
|
||||
{
|
||||
if (!tp || !out) {
|
||||
if (!tp || !out)
|
||||
return EINVAL;
|
||||
}
|
||||
if (!tp->shutdown) {
|
||||
if (!tp->shutdown)
|
||||
ithread_mutex_lock(&tp->mutex);
|
||||
}
|
||||
*out = tp->attr;
|
||||
if (!tp->shutdown) {
|
||||
if (!tp->shutdown)
|
||||
ithread_mutex_unlock(&tp->mutex);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -930,20 +914,17 @@ int ThreadPoolSetAttr(ThreadPool *tp, ThreadPoolAttr *attr)
|
||||
ThreadPoolAttr temp;
|
||||
int i = 0;
|
||||
|
||||
if (!tp) {
|
||||
if (!tp)
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
ithread_mutex_lock(&tp->mutex);
|
||||
|
||||
if (attr) {
|
||||
if (attr)
|
||||
temp = *attr;
|
||||
} else {
|
||||
else
|
||||
TPAttrInit(&temp);
|
||||
}
|
||||
if (SetPolicyType(temp.schedPolicy) != 0) {
|
||||
ithread_mutex_unlock(&tp->mutex);
|
||||
|
||||
return INVALID_POLICY;
|
||||
}
|
||||
tp->attr = temp;
|
||||
@ -961,10 +942,9 @@ int ThreadPoolSetAttr(ThreadPool *tp, ThreadPoolAttr *attr)
|
||||
|
||||
ithread_mutex_unlock(&tp->mutex);
|
||||
|
||||
if (retCode != 0) {
|
||||
if (retCode != 0)
|
||||
/* clean up if the min threads could not be created */
|
||||
ThreadPoolShutdown(tp);
|
||||
}
|
||||
|
||||
return retCode;
|
||||
}
|
||||
@ -974,54 +954,44 @@ int ThreadPoolShutdown(ThreadPool *tp)
|
||||
ListNode *head = NULL;
|
||||
ThreadPoolJob *temp = NULL;
|
||||
|
||||
if (!tp) {
|
||||
if (!tp)
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
ithread_mutex_lock(&tp->mutex);
|
||||
|
||||
/* clean up high priority jobs */
|
||||
while (tp->highJobQ.size) {
|
||||
head = ListHead(&tp->highJobQ);
|
||||
temp = (ThreadPoolJob *)head->item;
|
||||
if (temp->free_func) {
|
||||
if (temp->free_func)
|
||||
temp->free_func(temp->arg);
|
||||
}
|
||||
FreeThreadPoolJob(tp, temp);
|
||||
ListDelNode(&tp->highJobQ, head, 0);
|
||||
}
|
||||
ListDestroy(&tp->highJobQ, 0);
|
||||
|
||||
/* clean up med priority jobs */
|
||||
while (tp->medJobQ.size) {
|
||||
head = ListHead(&tp->medJobQ);
|
||||
temp = (ThreadPoolJob *)head->item;
|
||||
if (temp->free_func) {
|
||||
if (temp->free_func)
|
||||
temp->free_func(temp->arg);
|
||||
}
|
||||
FreeThreadPoolJob(tp, temp);
|
||||
ListDelNode(&tp->medJobQ, head, 0);
|
||||
}
|
||||
ListDestroy(&tp->medJobQ, 0);
|
||||
|
||||
/* clean up low priority jobs */
|
||||
while (tp->lowJobQ.size) {
|
||||
head = ListHead(&tp->lowJobQ);
|
||||
temp = (ThreadPoolJob *)head->item;
|
||||
if (temp->free_func) {
|
||||
if (temp->free_func)
|
||||
temp->free_func(temp->arg);
|
||||
}
|
||||
FreeThreadPoolJob(tp, temp);
|
||||
ListDelNode(&tp->lowJobQ, head, 0);
|
||||
}
|
||||
ListDestroy(&tp->lowJobQ, 0);
|
||||
|
||||
/* clean up long term job */
|
||||
if (tp->persistentJob) {
|
||||
temp = tp->persistentJob;
|
||||
if (temp->free_func) {
|
||||
if (temp->free_func)
|
||||
temp->free_func(temp->arg);
|
||||
}
|
||||
FreeThreadPoolJob(tp, temp);
|
||||
tp->persistentJob = NULL;
|
||||
}
|
||||
@ -1029,33 +999,25 @@ int ThreadPoolShutdown(ThreadPool *tp)
|
||||
tp->shutdown = 1;
|
||||
ithread_cond_broadcast(&tp->condition);
|
||||
/* wait for all threads to finish */
|
||||
while (tp->totalThreads > 0) {
|
||||
while (tp->totalThreads > 0)
|
||||
ithread_cond_wait(&tp->start_and_shutdown, &tp->mutex);
|
||||
}
|
||||
/* destroy condition */
|
||||
while (ithread_cond_destroy(&tp->condition) != 0) {
|
||||
/**/
|
||||
}
|
||||
while (ithread_cond_destroy(&tp->start_and_shutdown) != 0) {
|
||||
/**/
|
||||
}
|
||||
while (ithread_cond_destroy(&tp->condition) != 0) {}
|
||||
while (ithread_cond_destroy(&tp->start_and_shutdown) != 0) {}
|
||||
FreeListDestroy(&tp->jobFreeList);
|
||||
|
||||
ithread_mutex_unlock(&tp->mutex);
|
||||
|
||||
/* destroy mutex */
|
||||
while (ithread_mutex_destroy(&tp->mutex) != 0) {
|
||||
/**/
|
||||
}
|
||||
while (ithread_mutex_destroy(&tp->mutex) != 0) {}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int TPAttrInit(ThreadPoolAttr *attr)
|
||||
{
|
||||
if (!attr) {
|
||||
if (!attr)
|
||||
return EINVAL;
|
||||
}
|
||||
attr->jobsPerThread = DEFAULT_JOBS_PER_THREAD;
|
||||
attr->maxIdleTime = DEFAULT_IDLE_TIME;
|
||||
attr->maxThreads = DEFAULT_MAX_THREADS;
|
||||
@ -1070,9 +1032,8 @@ int TPAttrInit(ThreadPoolAttr *attr)
|
||||
|
||||
int TPJobInit(ThreadPoolJob *job, start_routine func, void *arg)
|
||||
{
|
||||
if (!job || !func) {
|
||||
if (!job || !func)
|
||||
return EINVAL;
|
||||
}
|
||||
job->func = func;
|
||||
job->arg = arg;
|
||||
job->priority = DEFAULT_PRIORITY;
|
||||
@ -1083,9 +1044,8 @@ int TPJobInit(ThreadPoolJob *job, start_routine func, void *arg)
|
||||
|
||||
int TPJobSetPriority(ThreadPoolJob *job, ThreadPriority priority)
|
||||
{
|
||||
if (!job) {
|
||||
if (!job)
|
||||
return EINVAL;
|
||||
}
|
||||
if (priority == LOW_PRIORITY ||
|
||||
priority == MED_PRIORITY ||
|
||||
priority == HIGH_PRIORITY) {
|
||||
@ -1098,9 +1058,8 @@ int TPJobSetPriority(ThreadPoolJob *job, ThreadPriority priority)
|
||||
|
||||
int TPJobSetFreeFunction(ThreadPoolJob *job, free_routine func)
|
||||
{
|
||||
if(!job) {
|
||||
if(!job)
|
||||
return EINVAL;
|
||||
}
|
||||
job->free_func = func;
|
||||
|
||||
return 0;
|
||||
@ -1108,9 +1067,8 @@ int TPJobSetFreeFunction(ThreadPoolJob *job, free_routine func)
|
||||
|
||||
int TPAttrSetMaxThreads(ThreadPoolAttr *attr, int maxThreads)
|
||||
{
|
||||
if (!attr) {
|
||||
if (!attr)
|
||||
return EINVAL;
|
||||
}
|
||||
attr->maxThreads = maxThreads;
|
||||
|
||||
return 0;
|
||||
@ -1118,9 +1076,8 @@ int TPAttrSetMaxThreads(ThreadPoolAttr *attr, int maxThreads)
|
||||
|
||||
int TPAttrSetMinThreads(ThreadPoolAttr *attr, int minThreads)
|
||||
{
|
||||
if (!attr) {
|
||||
if (!attr)
|
||||
return EINVAL;
|
||||
}
|
||||
attr->minThreads = minThreads;
|
||||
|
||||
return 0;
|
||||
@ -1128,9 +1085,8 @@ int TPAttrSetMinThreads(ThreadPoolAttr *attr, int minThreads)
|
||||
|
||||
int TPAttrSetStackSize(ThreadPoolAttr *attr, size_t stackSize)
|
||||
{
|
||||
if (!attr) {
|
||||
if (!attr)
|
||||
return EINVAL;
|
||||
}
|
||||
attr->stackSize = stackSize;
|
||||
|
||||
return 0;
|
||||
@ -1138,9 +1094,8 @@ int TPAttrSetStackSize(ThreadPoolAttr *attr, size_t stackSize)
|
||||
|
||||
int TPAttrSetIdleTime(ThreadPoolAttr *attr, int idleTime)
|
||||
{
|
||||
if (!attr) {
|
||||
if (!attr)
|
||||
return EINVAL;
|
||||
}
|
||||
attr->maxIdleTime = idleTime;
|
||||
|
||||
return 0;
|
||||
@ -1148,9 +1103,8 @@ int TPAttrSetIdleTime(ThreadPoolAttr *attr, int idleTime)
|
||||
|
||||
int TPAttrSetJobsPerThread(ThreadPoolAttr *attr, int jobsPerThread)
|
||||
{
|
||||
if (!attr) {
|
||||
if (!attr)
|
||||
return EINVAL;
|
||||
}
|
||||
attr->jobsPerThread = jobsPerThread;
|
||||
|
||||
return 0;
|
||||
@ -1158,9 +1112,8 @@ int TPAttrSetJobsPerThread(ThreadPoolAttr *attr, int jobsPerThread)
|
||||
|
||||
int TPAttrSetStarvationTime(ThreadPoolAttr *attr, int starvationTime)
|
||||
{
|
||||
if (!attr) {
|
||||
if (!attr)
|
||||
return EINVAL;
|
||||
}
|
||||
attr->starvationTime = starvationTime;
|
||||
|
||||
return 0;
|
||||
@ -1168,9 +1121,8 @@ int TPAttrSetStarvationTime(ThreadPoolAttr *attr, int starvationTime)
|
||||
|
||||
int TPAttrSetSchedPolicy(ThreadPoolAttr *attr, PolicyType schedPolicy)
|
||||
{
|
||||
if (!attr) {
|
||||
if (!attr)
|
||||
return EINVAL;
|
||||
}
|
||||
attr->schedPolicy = schedPolicy;
|
||||
|
||||
return 0;
|
||||
@ -1178,9 +1130,8 @@ int TPAttrSetSchedPolicy(ThreadPoolAttr *attr, PolicyType schedPolicy)
|
||||
|
||||
int TPAttrSetMaxJobsTotal(ThreadPoolAttr *attr, int maxJobsTotal)
|
||||
{
|
||||
if (!attr) {
|
||||
if (!attr)
|
||||
return EINVAL;
|
||||
}
|
||||
attr->maxJobsTotal = maxJobsTotal;
|
||||
|
||||
return 0;
|
||||
@ -1189,9 +1140,8 @@ int TPAttrSetMaxJobsTotal(ThreadPoolAttr *attr, int maxJobsTotal)
|
||||
#ifdef STATS
|
||||
void ThreadPoolPrintStats(ThreadPoolStats *stats)
|
||||
{
|
||||
if (!stats) {
|
||||
if (!stats)
|
||||
return;
|
||||
}
|
||||
/* some OSses time_t length may depending on platform, promote it to long for safety */
|
||||
printf("ThreadPoolStats at Time: %ld\n", (long)StatsTime(NULL));
|
||||
printf("High Jobs pending: %d\n", stats->currentJobsHQ);
|
||||
@ -1211,40 +1161,34 @@ void ThreadPoolPrintStats(ThreadPoolStats *stats)
|
||||
|
||||
int ThreadPoolGetStats(ThreadPool *tp, ThreadPoolStats *stats)
|
||||
{
|
||||
if (tp == NULL || stats == NULL) {
|
||||
if (tp == NULL || stats == NULL)
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
/* if not shutdown then acquire mutex */
|
||||
if (!tp->shutdown) {
|
||||
if (!tp->shutdown)
|
||||
ithread_mutex_lock(&tp->mutex);
|
||||
}
|
||||
|
||||
*stats = tp->stats;
|
||||
if (stats->totalJobsHQ > 0) {
|
||||
if (stats->totalJobsHQ > 0)
|
||||
stats->avgWaitHQ = stats->totalTimeHQ / stats->totalJobsHQ;
|
||||
} else {
|
||||
else
|
||||
stats->avgWaitHQ = 0;
|
||||
}
|
||||
if (stats->totalJobsMQ > 0) {
|
||||
if (stats->totalJobsMQ > 0)
|
||||
stats->avgWaitMQ = stats->totalTimeMQ / stats->totalJobsMQ;
|
||||
} else {
|
||||
else
|
||||
stats->avgWaitMQ = 0;
|
||||
}
|
||||
if (stats->totalJobsLQ > 0) {
|
||||
if (stats->totalJobsLQ > 0)
|
||||
stats->avgWaitLQ = stats->totalTimeLQ / stats->totalJobsLQ;
|
||||
} else {
|
||||
else
|
||||
stats->avgWaitLQ = 0;
|
||||
}
|
||||
stats->totalThreads = tp->totalThreads;
|
||||
stats->persistentThreads = tp->persistentThreads;
|
||||
stats->currentJobsHQ = (int)ListSize(&tp->highJobQ);
|
||||
stats->currentJobsLQ = (int)ListSize(&tp->lowJobQ);
|
||||
stats->currentJobsMQ = (int)ListSize(&tp->medJobQ);
|
||||
|
||||
/* if not shutdown then release mutex */
|
||||
if (!tp->shutdown) {
|
||||
if (!tp->shutdown)
|
||||
ithread_mutex_unlock(&tp->mutex);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -1288,4 +1232,3 @@ int ThreadPoolGetStats(ThreadPool *tp, ThreadPoolStats *stats)
|
||||
return 0;
|
||||
}
|
||||
#endif /* WIN32 */
|
||||
|
||||
|
@ -520,7 +520,6 @@ exit_function:
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
int UpnpFinish(void)
|
||||
{
|
||||
#ifdef INCLUDE_DEVICE_APIS
|
||||
@ -531,75 +530,64 @@ int UpnpFinish(void)
|
||||
#endif
|
||||
struct Handle_Info *temp;
|
||||
|
||||
if (UpnpSdkInit != 1) {
|
||||
if (UpnpSdkInit != 1)
|
||||
return UPNP_E_FINISH;
|
||||
}
|
||||
|
||||
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
|
||||
"Inside UpnpFinish: UpnpSdkInit is %d\n", UpnpSdkInit);
|
||||
if (UpnpSdkInit == 1) {
|
||||
"Inside UpnpFinish: UpnpSdkInit is %d\n", UpnpSdkInit);
|
||||
if (UpnpSdkInit == 1)
|
||||
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
|
||||
"UpnpFinish: UpnpSdkInit is ONE\n");
|
||||
}
|
||||
PrintThreadPoolStats(&gSendThreadPool, __FILE__, __LINE__, "Send Thread Pool");
|
||||
PrintThreadPoolStats(&gRecvThreadPool, __FILE__, __LINE__, "Recv Thread Pool");
|
||||
PrintThreadPoolStats(&gMiniServerThreadPool, __FILE__, __LINE__, "MiniServer Thread Pool");
|
||||
|
||||
"UpnpFinish: UpnpSdkInit is ONE\n");
|
||||
PrintThreadPoolStats(&gSendThreadPool, __FILE__, __LINE__,
|
||||
"Send Thread Pool");
|
||||
PrintThreadPoolStats(&gRecvThreadPool, __FILE__, __LINE__,
|
||||
"Recv Thread Pool");
|
||||
PrintThreadPoolStats(&gMiniServerThreadPool, __FILE__, __LINE__,
|
||||
"MiniServer Thread Pool");
|
||||
#ifdef INCLUDE_DEVICE_APIS
|
||||
if (GetDeviceHandleInfo(AF_INET, &device_handle, &temp) == HND_DEVICE ) {
|
||||
if (GetDeviceHandleInfo(AF_INET, &device_handle, &temp) == HND_DEVICE)
|
||||
UpnpUnRegisterRootDevice(device_handle);
|
||||
}
|
||||
if (GetDeviceHandleInfo(AF_INET6, &device_handle, &temp) == HND_DEVICE ) {
|
||||
if (GetDeviceHandleInfo(AF_INET6, &device_handle, &temp) == HND_DEVICE)
|
||||
UpnpUnRegisterRootDevice(device_handle);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef INCLUDE_CLIENT_APIS
|
||||
if (GetClientHandleInfo(&client_handle, &temp) == HND_CLIENT) {
|
||||
if (GetClientHandleInfo(&client_handle, &temp) == HND_CLIENT)
|
||||
UpnpUnRegisterClient(client_handle);
|
||||
}
|
||||
#endif
|
||||
|
||||
TimerThreadShutdown(&gTimerThread);
|
||||
StopMiniServer();
|
||||
|
||||
#if EXCLUDE_WEB_SERVER == 0
|
||||
web_server_destroy();
|
||||
#endif
|
||||
|
||||
ThreadPoolShutdown(&gMiniServerThreadPool);
|
||||
PrintThreadPoolStats(&gMiniServerThreadPool, __FILE__, __LINE__, "MiniServer Thread Pool");
|
||||
PrintThreadPoolStats(&gMiniServerThreadPool, __FILE__, __LINE__,
|
||||
"MiniServer Thread Pool");
|
||||
ThreadPoolShutdown(&gRecvThreadPool);
|
||||
PrintThreadPoolStats(&gSendThreadPool, __FILE__, __LINE__, "Send Thread Pool");
|
||||
PrintThreadPoolStats(&gSendThreadPool, __FILE__, __LINE__,
|
||||
"Send Thread Pool");
|
||||
ThreadPoolShutdown(&gSendThreadPool);
|
||||
PrintThreadPoolStats(&gRecvThreadPool, __FILE__, __LINE__, "Recv Thread Pool");
|
||||
|
||||
PrintThreadPoolStats(&gRecvThreadPool, __FILE__, __LINE__,
|
||||
"Recv Thread Pool");
|
||||
#ifdef INCLUDE_CLIENT_APIS
|
||||
ithread_mutex_destroy(&GlobalClientSubscribeMutex);
|
||||
#endif
|
||||
ithread_rwlock_destroy(&GlobalHndRWLock);
|
||||
ithread_mutex_destroy(&gUUIDMutex);
|
||||
|
||||
/* remove all virtual dirs */
|
||||
UpnpRemoveAllVirtualDirs();
|
||||
|
||||
/* Clean-up ithread library resources */
|
||||
ithread_cleanup_library();
|
||||
|
||||
UpnpSdkInit = 0;
|
||||
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
|
||||
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
|
||||
"Exiting UpnpFinish: UpnpSdkInit is :%d:\n", UpnpSdkInit);
|
||||
UpnpCloseLog();
|
||||
|
||||
return UPNP_E_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
unsigned short UpnpGetServerPort(void)
|
||||
{
|
||||
if (UpnpSdkInit != 1) {
|
||||
if (UpnpSdkInit != 1)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return LOCAL_PORT_V4;
|
||||
}
|
||||
@ -607,44 +595,37 @@ unsigned short UpnpGetServerPort(void)
|
||||
#ifdef UPNP_ENABLE_IPV6
|
||||
unsigned short UpnpGetServerPort6(void)
|
||||
{
|
||||
if (UpnpSdkInit != 1) {
|
||||
if (UpnpSdkInit != 1)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return LOCAL_PORT_V6;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
char *UpnpGetServerIpAddress(void)
|
||||
{
|
||||
if (UpnpSdkInit != 1) {
|
||||
if (UpnpSdkInit != 1)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return gIF_IPV4;
|
||||
}
|
||||
|
||||
|
||||
char *UpnpGetServerIp6Address(void)
|
||||
{
|
||||
if( UpnpSdkInit != 1 ) {
|
||||
if (UpnpSdkInit != 1)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return gIF_IPV6;
|
||||
}
|
||||
|
||||
char *UpnpGetServerUlaGuaIp6Address(void)
|
||||
{
|
||||
if( UpnpSdkInit != 1 ) {
|
||||
if (UpnpSdkInit != 1)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return gIF_IPV6_ULA_GUA;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Get a free handle.
|
||||
*
|
||||
@ -656,18 +637,14 @@ static int GetFreeHandle()
|
||||
/* Handle 0 is not used as NULL translates to 0 when passed as a handle */
|
||||
int i = 1;
|
||||
|
||||
while (i < NUM_HANDLE && HandleTable[i] != NULL) {
|
||||
while (i < NUM_HANDLE && HandleTable[i] != NULL)
|
||||
++i;
|
||||
}
|
||||
|
||||
if (i == NUM_HANDLE) {
|
||||
if (i == NUM_HANDLE)
|
||||
return UPNP_E_OUTOF_HANDLE;
|
||||
} else {
|
||||
else
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Free handle.
|
||||
*
|
||||
@ -681,7 +658,6 @@ static int FreeHandle(
|
||||
|
||||
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
|
||||
"FreeHandle: entering, Handle is %d\n", Upnp_Handle);
|
||||
|
||||
if (Upnp_Handle < 1 || Upnp_Handle >= NUM_HANDLE) {
|
||||
UpnpPrintf(UPNP_CRITICAL, API, __FILE__, __LINE__,
|
||||
"FreeHandle: Handle %d is out of range\n",
|
||||
@ -695,14 +671,12 @@ static int FreeHandle(
|
||||
HandleTable[Upnp_Handle] = NULL;
|
||||
ret = UPNP_E_SUCCESS;
|
||||
}
|
||||
|
||||
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
|
||||
"FreeHandle: exiting, ret = %d.\n", ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
#ifdef INCLUDE_DEVICE_APIS
|
||||
int UpnpRegisterRootDevice(
|
||||
const char *DescUrl,
|
||||
@ -1140,179 +1114,159 @@ exit_function:
|
||||
#ifdef INCLUDE_DEVICE_APIS
|
||||
int UpnpUnRegisterRootDevice(UpnpDevice_Handle Hnd)
|
||||
{
|
||||
int retVal = 0;
|
||||
struct Handle_Info *HInfo = NULL;
|
||||
int retVal = 0;
|
||||
struct Handle_Info *HInfo = NULL;
|
||||
|
||||
if (UpnpSdkInit != 1) {
|
||||
return UPNP_E_FINISH;
|
||||
}
|
||||
|
||||
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
|
||||
"Inside UpnpUnRegisterRootDevice\n");
|
||||
if (UpnpSdkInit != 1)
|
||||
return UPNP_E_FINISH;
|
||||
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
|
||||
"Inside UpnpUnRegisterRootDevice\n");
|
||||
#if EXCLUDE_GENA == 0
|
||||
if( genaUnregisterDevice( Hnd ) != UPNP_E_SUCCESS )
|
||||
return UPNP_E_INVALID_HANDLE;
|
||||
if (genaUnregisterDevice(Hnd) != UPNP_E_SUCCESS)
|
||||
return UPNP_E_INVALID_HANDLE;
|
||||
#endif
|
||||
|
||||
HandleLock();
|
||||
if( GetHandleInfo( Hnd, &HInfo ) == UPNP_E_INVALID_HANDLE ) {
|
||||
HandleUnlock();
|
||||
return UPNP_E_INVALID_HANDLE;
|
||||
}
|
||||
HandleUnlock();
|
||||
HandleLock();
|
||||
if (GetHandleInfo(Hnd, &HInfo) == UPNP_E_INVALID_HANDLE) {
|
||||
HandleUnlock();
|
||||
return UPNP_E_INVALID_HANDLE;
|
||||
}
|
||||
HandleUnlock();
|
||||
|
||||
#if EXCLUDE_SSDP == 0
|
||||
retVal = AdvertiseAndReply(-1, Hnd, 0, (struct sockaddr *)NULL,
|
||||
(char *)NULL, (char *)NULL, (char *)NULL, HInfo->MaxAge);
|
||||
retVal = AdvertiseAndReply(-1, Hnd, 0, (struct sockaddr *)NULL,
|
||||
(char *)NULL, (char *)NULL, (char *)NULL,
|
||||
HInfo->MaxAge);
|
||||
#endif
|
||||
|
||||
HandleLock();
|
||||
if( GetHandleInfo( Hnd, &HInfo ) == UPNP_E_INVALID_HANDLE ) {
|
||||
HandleUnlock();
|
||||
return UPNP_E_INVALID_HANDLE;
|
||||
}
|
||||
/*info = (struct Handle_Info *) HandleTable[Hnd]; */
|
||||
ixmlNodeList_free( HInfo->DeviceList );
|
||||
ixmlNodeList_free( HInfo->ServiceList );
|
||||
ixmlDocument_free( HInfo->DescDocument );
|
||||
|
||||
HandleLock();
|
||||
if (GetHandleInfo(Hnd, &HInfo) == UPNP_E_INVALID_HANDLE) {
|
||||
HandleUnlock();
|
||||
return UPNP_E_INVALID_HANDLE;
|
||||
}
|
||||
ixmlNodeList_free(HInfo->DeviceList);
|
||||
ixmlNodeList_free(HInfo->ServiceList);
|
||||
ixmlDocument_free(HInfo->DescDocument);
|
||||
#ifdef INCLUDE_CLIENT_APIS
|
||||
ListDestroy( &HInfo->SsdpSearchList, 0 );
|
||||
ListDestroy(&HInfo->SsdpSearchList, 0);
|
||||
#endif /* INCLUDE_CLIENT_APIS */
|
||||
|
||||
#ifdef INTERNAL_WEB_SERVER
|
||||
if( HInfo->aliasInstalled ) {
|
||||
web_server_set_alias( NULL, NULL, 0, 0 );
|
||||
}
|
||||
if (HInfo->aliasInstalled)
|
||||
web_server_set_alias(NULL, NULL, 0, 0);
|
||||
#endif /* INTERNAL_WEB_SERVER */
|
||||
if (HInfo->DeviceAf == AF_INET)
|
||||
UpnpSdkDeviceRegisteredV4 = 0;
|
||||
else if (HInfo->DeviceAf == AF_INET6)
|
||||
UpnpSdkDeviceregisteredV6 = 0;
|
||||
FreeHandle(Hnd);
|
||||
HandleUnlock();
|
||||
|
||||
if( HInfo->DeviceAf == AF_INET ) {
|
||||
UpnpSdkDeviceRegisteredV4 = 0;
|
||||
} else if( HInfo->DeviceAf == AF_INET6 ) {
|
||||
UpnpSdkDeviceregisteredV6 = 0;
|
||||
}
|
||||
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
|
||||
"Exiting UpnpUnRegisterRootDevice\n");
|
||||
|
||||
FreeHandle(Hnd);
|
||||
HandleUnlock();
|
||||
|
||||
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
|
||||
"Exiting UpnpUnRegisterRootDevice\n" );
|
||||
|
||||
return retVal;
|
||||
return retVal;
|
||||
}
|
||||
#endif /* INCLUDE_DEVICE_APIS */
|
||||
|
||||
|
||||
#ifdef INCLUDE_CLIENT_APIS
|
||||
int UpnpRegisterClient(
|
||||
Upnp_FunPtr Fun,
|
||||
const void *Cookie,
|
||||
int UpnpRegisterClient(Upnp_FunPtr Fun, const void *Cookie,
|
||||
UpnpClient_Handle *Hnd)
|
||||
{
|
||||
struct Handle_Info *HInfo;
|
||||
struct Handle_Info *HInfo;
|
||||
|
||||
if( UpnpSdkInit != 1 ) {
|
||||
return UPNP_E_FINISH;
|
||||
}
|
||||
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
||||
"Inside UpnpRegisterClient \n" );
|
||||
if( Fun == NULL || Hnd == NULL ) {
|
||||
return UPNP_E_INVALID_PARAM;
|
||||
}
|
||||
if (UpnpSdkInit != 1)
|
||||
return UPNP_E_FINISH;
|
||||
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
|
||||
"Inside UpnpRegisterClient \n");
|
||||
if (Fun == NULL || Hnd == NULL)
|
||||
return UPNP_E_INVALID_PARAM;
|
||||
|
||||
HandleLock();
|
||||
|
||||
if( UpnpSdkClientRegistered ) {
|
||||
HandleUnlock();
|
||||
return UPNP_E_ALREADY_REGISTERED;
|
||||
}
|
||||
if( ( *Hnd = GetFreeHandle() ) == UPNP_E_OUTOF_HANDLE ) {
|
||||
HandleUnlock();
|
||||
return UPNP_E_OUTOF_MEMORY;
|
||||
}
|
||||
HInfo = ( struct Handle_Info * )malloc( sizeof( struct Handle_Info ) );
|
||||
if( HInfo == NULL ) {
|
||||
HandleUnlock();
|
||||
return UPNP_E_OUTOF_MEMORY;
|
||||
}
|
||||
|
||||
HInfo->HType = HND_CLIENT;
|
||||
HInfo->Callback = Fun;
|
||||
HInfo->Cookie = ( void * )Cookie;
|
||||
HInfo->ClientSubList = NULL;
|
||||
ListInit( &HInfo->SsdpSearchList, NULL, NULL );
|
||||
HandleLock();
|
||||
if (UpnpSdkClientRegistered) {
|
||||
HandleUnlock();
|
||||
return UPNP_E_ALREADY_REGISTERED;
|
||||
}
|
||||
if ((*Hnd = GetFreeHandle()) == UPNP_E_OUTOF_HANDLE) {
|
||||
HandleUnlock();
|
||||
return UPNP_E_OUTOF_MEMORY;
|
||||
}
|
||||
HInfo = (struct Handle_Info *)malloc(sizeof(struct Handle_Info));
|
||||
if (HInfo == NULL) {
|
||||
HandleUnlock();
|
||||
return UPNP_E_OUTOF_MEMORY;
|
||||
}
|
||||
HInfo->HType = HND_CLIENT;
|
||||
HInfo->Callback = Fun;
|
||||
HInfo->Cookie = (void *)Cookie;
|
||||
HInfo->ClientSubList = NULL;
|
||||
ListInit(&HInfo->SsdpSearchList, NULL, NULL);
|
||||
#ifdef INCLUDE_DEVICE_APIS
|
||||
HInfo->MaxAge = 0;
|
||||
HInfo->MaxSubscriptions = UPNP_INFINITE;
|
||||
HInfo->MaxSubscriptionTimeOut = UPNP_INFINITE;
|
||||
HInfo->MaxAge = 0;
|
||||
HInfo->MaxSubscriptions = UPNP_INFINITE;
|
||||
HInfo->MaxSubscriptionTimeOut = UPNP_INFINITE;
|
||||
#endif
|
||||
HandleTable[*Hnd] = HInfo;
|
||||
UpnpSdkClientRegistered = 1;
|
||||
HandleUnlock();
|
||||
|
||||
HandleTable[*Hnd] = HInfo;
|
||||
UpnpSdkClientRegistered = 1;
|
||||
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
|
||||
"Exiting UpnpRegisterClient \n");
|
||||
|
||||
HandleUnlock();
|
||||
|
||||
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
||||
"Exiting UpnpRegisterClient \n" );
|
||||
|
||||
return UPNP_E_SUCCESS;
|
||||
return UPNP_E_SUCCESS;
|
||||
}
|
||||
#endif /* INCLUDE_CLIENT_APIS */
|
||||
|
||||
|
||||
#ifdef INCLUDE_CLIENT_APIS
|
||||
int UpnpUnRegisterClient(UpnpClient_Handle Hnd)
|
||||
{
|
||||
struct Handle_Info *HInfo;
|
||||
ListNode *node = NULL;
|
||||
SsdpSearchArg *searchArg = NULL;
|
||||
struct Handle_Info *HInfo;
|
||||
ListNode *node = NULL;
|
||||
SsdpSearchArg *searchArg = NULL;
|
||||
|
||||
if( UpnpSdkInit != 1 ) {
|
||||
return UPNP_E_FINISH;
|
||||
}
|
||||
if (UpnpSdkInit != 1)
|
||||
return UPNP_E_FINISH;
|
||||
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
|
||||
"Inside UpnpUnRegisterClient \n");
|
||||
|
||||
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
||||
"Inside UpnpUnRegisterClient \n" );
|
||||
HandleLock();
|
||||
if( !UpnpSdkClientRegistered ) {
|
||||
HandleUnlock();
|
||||
return UPNP_E_INVALID_HANDLE;
|
||||
}
|
||||
HandleUnlock();
|
||||
HandleLock();
|
||||
if (!UpnpSdkClientRegistered) {
|
||||
HandleUnlock();
|
||||
return UPNP_E_INVALID_HANDLE;
|
||||
}
|
||||
HandleUnlock();
|
||||
|
||||
#if EXCLUDE_GENA == 0
|
||||
if( genaUnregisterClient( Hnd ) != UPNP_E_SUCCESS )
|
||||
return UPNP_E_INVALID_HANDLE;
|
||||
if (genaUnregisterClient(Hnd) != UPNP_E_SUCCESS)
|
||||
return UPNP_E_INVALID_HANDLE;
|
||||
#endif
|
||||
HandleLock();
|
||||
if( GetHandleInfo( Hnd, &HInfo ) == UPNP_E_INVALID_HANDLE ) {
|
||||
HandleUnlock();
|
||||
return UPNP_E_INVALID_HANDLE;
|
||||
}
|
||||
/* clean up search list */
|
||||
node = ListHead( &HInfo->SsdpSearchList );
|
||||
while( node != NULL ) {
|
||||
searchArg = ( SsdpSearchArg * ) node->item;
|
||||
if( searchArg ) {
|
||||
free( searchArg->searchTarget );
|
||||
free( searchArg );
|
||||
}
|
||||
ListDelNode( &HInfo->SsdpSearchList, node, 0 );
|
||||
node = ListHead( &HInfo->SsdpSearchList );
|
||||
}
|
||||
HandleLock();
|
||||
if (GetHandleInfo(Hnd, &HInfo) == UPNP_E_INVALID_HANDLE) {
|
||||
HandleUnlock();
|
||||
return UPNP_E_INVALID_HANDLE;
|
||||
}
|
||||
/* clean up search list */
|
||||
node = ListHead(&HInfo->SsdpSearchList);
|
||||
while (node != NULL) {
|
||||
searchArg = (SsdpSearchArg *) node->item;
|
||||
if (searchArg) {
|
||||
free(searchArg->searchTarget);
|
||||
free(searchArg);
|
||||
}
|
||||
ListDelNode(&HInfo->SsdpSearchList, node, 0);
|
||||
node = ListHead(&HInfo->SsdpSearchList);
|
||||
}
|
||||
ListDestroy(&HInfo->SsdpSearchList, 0);
|
||||
FreeHandle(Hnd);
|
||||
UpnpSdkClientRegistered = 0;
|
||||
HandleUnlock();
|
||||
|
||||
ListDestroy( &HInfo->SsdpSearchList, 0 );
|
||||
FreeHandle(Hnd);
|
||||
UpnpSdkClientRegistered = 0;
|
||||
HandleUnlock();
|
||||
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
||||
"Exiting UpnpUnRegisterClient \n" );
|
||||
return UPNP_E_SUCCESS;
|
||||
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
|
||||
"Exiting UpnpUnRegisterClient \n");
|
||||
|
||||
return UPNP_E_SUCCESS;
|
||||
}
|
||||
#endif /* INCLUDE_CLIENT_APIS */
|
||||
|
||||
|
||||
#ifdef INCLUDE_DEVICE_APIS
|
||||
#ifdef INTERNAL_WEB_SERVER
|
||||
/*!
|
||||
|
@ -305,11 +305,9 @@ static UPNP_INLINE int get_content_type(
|
||||
UpnpFileInfo_set_ContentType(fileInfo, NULL);
|
||||
/* get ext */
|
||||
extension = strrchr(filename, '.');
|
||||
if (extension != NULL) {
|
||||
if (search_extension(extension + 1, &type, &subtype) == 0) {
|
||||
if (extension != NULL)
|
||||
if (search_extension(extension + 1, &type, &subtype) == 0)
|
||||
ctype_found = TRUE;
|
||||
}
|
||||
}
|
||||
if (!ctype_found) {
|
||||
/* unknown content type */
|
||||
type = gMediaTypes[APPLICATION_INDEX];
|
||||
@ -317,16 +315,14 @@ static UPNP_INLINE int get_content_type(
|
||||
}
|
||||
length = strlen(type) + strlen("/") + strlen(subtype) + 1;
|
||||
temp = malloc(length);
|
||||
if (!temp) {
|
||||
if (!temp)
|
||||
return UPNP_E_OUTOF_MEMORY;
|
||||
}
|
||||
sprintf(temp, "%s/%s", type, subtype);
|
||||
UpnpFileInfo_set_ContentType(fileInfo, temp);
|
||||
free(temp);
|
||||
|
||||
if (!UpnpFileInfo_get_ContentType(fileInfo)) {
|
||||
if (!UpnpFileInfo_get_ContentType(fileInfo))
|
||||
return UPNP_E_OUTOF_MEMORY;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -413,18 +409,14 @@ int web_server_set_alias(const char *alias_name,
|
||||
alias.ct = NULL;
|
||||
do {
|
||||
/* insert leading /, if missing */
|
||||
if (*alias_name != '/') {
|
||||
if (membuffer_assign_str(&alias.name, "/") != 0) {
|
||||
if (*alias_name != '/')
|
||||
if (membuffer_assign_str(&alias.name, "/") != 0)
|
||||
break; /* error; out of mem */
|
||||
}
|
||||
}
|
||||
ret_code = membuffer_append_str(&alias.name, alias_name);
|
||||
if (ret_code != 0) {
|
||||
if (ret_code != 0)
|
||||
break; /* error */
|
||||
}
|
||||
if ((alias.ct = (int *)malloc(sizeof(int))) == NULL) {
|
||||
if ((alias.ct = (int *)malloc(sizeof(int))) == NULL)
|
||||
break; /* error */
|
||||
}
|
||||
*alias.ct = 1;
|
||||
membuffer_attach(&alias.doc, (char *)alias_content,
|
||||
alias_content_length);
|
||||
@ -436,18 +428,19 @@ int web_server_set_alias(const char *alias_name,
|
||||
|
||||
return 0;
|
||||
} while (FALSE);
|
||||
|
||||
/* error handler */
|
||||
/* free temp alias */
|
||||
membuffer_destroy(&alias.name);
|
||||
membuffer_destroy(&alias.doc);
|
||||
free(alias.ct);
|
||||
|
||||
return UPNP_E_OUTOF_MEMORY;
|
||||
}
|
||||
|
||||
int web_server_init()
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (bWebServerState == WEB_SERVER_DISABLED) {
|
||||
/* decode media list */
|
||||
media_list_init();
|
||||
@ -463,11 +456,10 @@ int web_server_init()
|
||||
virtualDirCallback.seek = NULL;
|
||||
virtualDirCallback.close = NULL;
|
||||
|
||||
if (ithread_mutex_init(&gWebMutex, NULL) == -1) {
|
||||
if (ithread_mutex_init(&gWebMutex, NULL) == -1)
|
||||
ret = UPNP_E_OUTOF_MEMORY;
|
||||
} else {
|
||||
else
|
||||
bWebServerState = WEB_SERVER_ENABLED;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
@ -513,34 +505,25 @@ static int get_file_info(
|
||||
time_t aux_LastModified;
|
||||
|
||||
UpnpFileInfo_set_ContentType(info, NULL);
|
||||
|
||||
code = stat(filename, &s);
|
||||
if (code == -1) {
|
||||
if (code == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (S_ISDIR(s.st_mode)) {
|
||||
if (S_ISDIR(s.st_mode))
|
||||
UpnpFileInfo_set_IsDirectory(info, TRUE);
|
||||
} else if (S_ISREG(s.st_mode)) {
|
||||
else if (S_ISREG(s.st_mode))
|
||||
UpnpFileInfo_set_IsDirectory(info, FALSE);
|
||||
} else {
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* check readable */
|
||||
fp = fopen(filename, "r");
|
||||
UpnpFileInfo_set_IsReadable(info, fp != NULL);
|
||||
if (fp) {
|
||||
if (fp)
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
UpnpFileInfo_set_FileLength(info, s.st_size);
|
||||
UpnpFileInfo_set_LastModified(info, s.st_mtime);
|
||||
|
||||
rc = get_content_type(filename, info);
|
||||
|
||||
aux_LastModified = UpnpFileInfo_get_LastModified(info);
|
||||
UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__,
|
||||
UpnpPrintf(UPNP_INFO, HTTP, __FILE__, __LINE__,
|
||||
"file info: %s, length: %lld, last_mod=%s readable=%d\n",
|
||||
filename,
|
||||
(long long)UpnpFileInfo_get_FileLength(info),
|
||||
@ -556,15 +539,13 @@ int web_server_set_root_dir(const char *root_dir)
|
||||
int ret;
|
||||
|
||||
ret = membuffer_assign_str(&gDocumentRootDir, root_dir);
|
||||
if (ret != 0) {
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
}
|
||||
/* remove trailing '/', if any */
|
||||
if (gDocumentRootDir.length > 0) {
|
||||
index = gDocumentRootDir.length - 1; /* last char */
|
||||
if (gDocumentRootDir.buf[index] == '/') {
|
||||
if (gDocumentRootDir.buf[index] == '/')
|
||||
membuffer_delete(&gDocumentRootDir, index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -667,17 +648,15 @@ static char *StrStr(
|
||||
if (!Str1)
|
||||
goto error1;
|
||||
Str2 = strdup(s2);
|
||||
if (!Str2) {
|
||||
if (!Str2)
|
||||
goto error2;
|
||||
}
|
||||
ToUpperCase(Str1);
|
||||
ToUpperCase(Str2);
|
||||
Ptr = strstr(Str1, Str2);
|
||||
if (!Ptr) {
|
||||
if (!Ptr)
|
||||
ret = NULL;
|
||||
} else {
|
||||
else
|
||||
ret = s1 + (Ptr - Str1);
|
||||
}
|
||||
|
||||
free(Str2);
|
||||
error2:
|
||||
@ -735,13 +714,11 @@ static int GetNextRange(
|
||||
int64_t L = -1;
|
||||
int Is_Suffix_byte_Range = 1;
|
||||
|
||||
if (*SrcRangeStr == NULL) {
|
||||
if (*SrcRangeStr == NULL)
|
||||
return -1;
|
||||
}
|
||||
Tok = StrTok(SrcRangeStr, ",");
|
||||
if ((Ptr = strstr(Tok, "-")) == NULL) {
|
||||
if ((Ptr = strstr(Tok, "-")) == NULL)
|
||||
return -1;
|
||||
}
|
||||
*Ptr = ' ';
|
||||
sscanf(Tok, "%" SCNd64 "%" SCNd64, &F, &L);
|
||||
if (F == -1 || L == -1) {
|
||||
@ -979,8 +956,8 @@ static int CheckOtherHTTPHeaders(
|
||||
}
|
||||
node = ListNext(&Req->headers, node);
|
||||
}
|
||||
|
||||
free(TmpBuf);
|
||||
|
||||
return RetCode;
|
||||
}
|
||||
|
||||
@ -1339,21 +1316,18 @@ static int http_RecvPostMessage(
|
||||
|
||||
if (Instr && Instr->IsVirtualFile) {
|
||||
Fp = (virtualDirCallback.open) (filename, UPNP_WRITE);
|
||||
if (Fp == NULL) {
|
||||
if (Fp == NULL)
|
||||
return HTTP_INTERNAL_SERVER_ERROR;
|
||||
}
|
||||
} else {
|
||||
Fp = fopen(filename, "wb");
|
||||
if (Fp == NULL) {
|
||||
if (Fp == NULL)
|
||||
return HTTP_UNAUTHORIZED;
|
||||
}
|
||||
}
|
||||
parser->position = POS_ENTITY;
|
||||
do {
|
||||
/* first parse what has already been gotten */
|
||||
if (parser->position != POS_COMPLETE) {
|
||||
if (parser->position != POS_COMPLETE)
|
||||
status = parser_parse_entity(parser);
|
||||
}
|
||||
if (status == PARSE_INCOMPLETE_ENTITY) {
|
||||
/* read until close */
|
||||
ok_on_close = TRUE;
|
||||
|
Loading…
x
Reference in New Issue
Block a user