/*---------------------------------------------------------------------------*/ void _rtp_timer_process_expired_jobs (RTPTimerJob* timerList) { RTPTimerJob *job = timerList->next; long timeDifferenceMsec; unsigned long currentMsec = rtp_get_system_msec(); void (*timerFunction) (int,void*); void* timerData; while (job != timerList) { rtpTimerNextToProcess = job->next; timeDifferenceMsec = (long) (currentMsec - job->scheduledTimeMsec); if (timeDifferenceMsec > 0) { DLLIST_REMOVE(job); if (job->repeat == RTP_TIMER_REPEAT_INFINITE) { DLLIST_INSERT_BEFORE(&rtpTimerNewList, job); job->listId = RTP_TIMER_LIST_NEW; } else { if (job->repeat > 0) { /* if this timer has more repeats left, add it to the new list */ job->repeat--; DLLIST_INSERT_BEFORE(&rtpTimerNewList, job); job->listId = RTP_TIMER_LIST_NEW; } else { DLLIST_INIT(job); job->listId = RTP_TIMER_LIST_NONE; } } if (job->timerFunction) { timerFunction = job->timerFunction; timerData = job->timerData; rtp_sig_mutex_release(rtpTimerLock); timerFunction(0, timerData); rtp_sig_mutex_claim(rtpTimerLock); } } else { break; } job = rtpTimerNextToProcess; } rtpTimerNextToProcess = 0; }
/*---------------------------------------------------------------------------*/ void _rtp_timer_add_new_jobs (RTPTimerJob* toTimerList, RTPTimerJob* fromTimerList) { RTPTimerJob *next; RTPTimerJob *newJob; RTPTimerJob *job; long timeDifference; newJob = fromTimerList->next; while (newJob != fromTimerList) { next = newJob->next; newJob->scheduledTimeMsec += rtp_get_system_msec(); job = toTimerList->next; while (job != toTimerList) { timeDifference = (long) (job->scheduledTimeMsec - newJob->scheduledTimeMsec); if (timeDifference > 0) { break; } job = job->next; } DLLIST_REMOVE(newJob); DLLIST_INSERT_BEFORE(job, newJob); newJob->listId = RTP_TIMER_LIST_ACTIVE; newJob = next; } }
/*---------------------------------------------------------------------------*/ int rtp_timer_start (RTP_TIMER* newJob, void (*fn)(int,void*), void* data, long msecInterval, unsigned long repeat) { newJob->scheduledTimeMsec = msecInterval; newJob->timerFunction = fn; newJob->timerData = data; newJob->repeat = repeat; if (rtp_sig_mutex_claim(rtpTimerLock) >= 0) { DLLIST_INSERT_BEFORE(&rtpTimerNewList, newJob); newJob->listId = RTP_TIMER_LIST_NEW; if (!rtpTimerThreadAwake) { rtpTimerThreadAwake = 1; rtp_sig_semaphore_signal(rtpTimerSignal); } rtp_sig_mutex_release(rtpTimerLock); return (0); } return (-1); }
/*---------------------------------------------------------------------------*/ int HTTP_ServerAddAuthRealm (HTTPServerContext *server, const HTTP_CHAR *realmName, HTTPAuthRealmPath *pathList, HTTP_INT16 numPaths, HTTPAuthRealmUser *userList, HTTP_INT16 numUsers, HTTPAuthScheme scheme) { HTTPServerAuthRealm *realm; /* first try to find an existing realm with the same name */ realm = (HTTPServerAuthRealm *) server->realmList.next; while (realm != (HTTPServerAuthRealm *) &server->realmList) { if (!rtp_strcmp(realmName, realm->realmName)) { /* already exists; first need to remove it */ return (-1); } realm = (HTTPServerAuthRealm *) realm->node.next; } realm = _HTTP_AllocServerAuthRealm(); if (realm) { DLLIST_INSERT_BEFORE(&server->realmList, &realm->node); DLLIST_INIT(&realm->activeNonceList); realm->pathList = pathList; realm->userList = userList; realm->scheme = scheme; realm->numPaths = numPaths; realm->numUsers = numUsers; rtp_strncpy(realm->realmName, realmName, HTTP_SERVER_NAME_LEN-1); return (0); } return (-1); }
/*---------------------------------------------------------------------------*/ int _HTTP_ServerAddPath (HTTPServerContext *server, const HTTP_CHAR *path, HTTP_BOOL exactMatch, HTTPRequestHandler fn, HTTPServerPathDestructor dfn, void *userData) { HTTPServerPath *serverPath; /* first try to find an existing path */ serverPath = (HTTPServerPath *) server->pathList.next; while (serverPath != (HTTPServerPath *) &server->pathList) { /* path name space is case-preserving, case-insensitive */ if (!rtp_stricmp(path, serverPath->path)) { /* already exists; first need to remove it */ return (-2); } serverPath = (HTTPServerPath *) serverPath->node.next; } serverPath = _HTTP_AllocServerPath(); if (serverPath) { DLLIST_INSERT_BEFORE(&server->pathList, &serverPath->node); serverPath->fn = fn; serverPath->dfn = dfn; serverPath->userData = userData; serverPath->exactMatch = exactMatch; rtp_strncpy(serverPath->path, path, HTTP_SERVER_PATH_LEN-1); return (0); } return (-1); }