Example #1
0
/*---------------------------------------------------------------------------*/
int rtp_helper_thread_stop_all (
		RTP_HELPER_THREAD_CTX* ctx,
		long maxTimeoutMsec
	)
{	
	int result;
	long elapsedMsec = 0;
	
	rtp_sig_mutex_claim(ctx->mutex);	
	
	ctx->stopping = 1;
	
	while ((maxTimeoutMsec == RTP_TIMEOUT_INFINITE || elapsedMsec < maxTimeoutMsec) &&
	       ctx->numHelpersRunning > 0)
	{
		rtp_sig_mutex_release(ctx->mutex);
		rtp_thread_sleep(RTP_HELPER_THREAD_QUEUE_TIMEOUT_MSEC);		
		elapsedMsec += RTP_HELPER_THREAD_QUEUE_TIMEOUT_MSEC;
		rtp_sig_mutex_claim(ctx->mutex);			
	}

	ctx->stopping = 0;
	result = (ctx->numHelpersRunning == 0)? 0 : -1;

	rtp_sig_mutex_release(ctx->mutex);
	
	return (result);
}
Example #2
0
/*---------------------------------------------------------------------------*/
void _rtp_timer_thread (void* data)
{
	int result;
	long msecsUntilNextTimer;

	rtp_sig_mutex_claim(rtpTimerLock);

	while (1)
	{
		msecsUntilNextTimer = _rtp_timer_find_msecs_to_next_timer(&rtpTimerActiveList);

		if (msecsUntilNextTimer != 0)
		{			
			rtpTimerThreadAwake = 0;
			rtp_sig_mutex_release(rtpTimerLock);
			result = rtp_sig_semaphore_wait_timed(rtpTimerSignal, msecsUntilNextTimer);
			rtp_sig_mutex_claim(rtpTimerLock);
			rtpTimerThreadAwake = 1;
		}
		else
		{
			result = 1;
		}

		if (result != 0)
		{
			rtpTimerThreadAwake = 1;
			_rtp_timer_process_expired_jobs(&rtpTimerActiveList);		
			rtpTimerThreadAwake = 0;
		}
		
		_rtp_timer_add_new_jobs(&rtpTimerActiveList, &rtpTimerNewList);		
	}
	
}
Example #3
0
/*
    @return
 */
char *_getLocation (unsigned char * remoteAddr, int remotePort, int addrType,
                    UPnPRootDevice *rootDevice)
{
	char *toReturn = 0;

	if (rootDevice->autoAddr)
	{
		RTP_NET_ADDR serverAddr = {0};

		rtp_net_getifaceaddr(serverAddr.ipAddr, remoteAddr, remotePort, addrType);

		serverAddr.port = HTTP_ServerGetPort(&rootDevice->deviceRuntime->upnpRuntime->httpServer);
		serverAddr.type = addrType;

	 #ifdef UPNP_MULTITHREAD
		rtp_sig_mutex_claim(rootDevice->mutex);
	 #endif

	 	toReturn = UPnP_DOMSubstituteAddr(rootDevice->descLocation, &serverAddr);

	 #ifdef UPNP_MULTITHREAD
		rtp_sig_mutex_release(rootDevice->mutex);
	 #endif
	}
	else
	{
		toReturn = rootDevice->descLocation;
	}

 	return (toReturn);
}
Example #4
0
/*---------------------------------------------------------------------------*/
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);
}
Example #5
0
/*----------------------------------------------------------------------*
                         rtp_debug_output_int
 *----------------------------------------------------------------------*/
void _rtp_debug_output_int (
	long val
	)
{
char* buffer;
int i;

  #ifdef RTP_DEBUG_MULTITHREAD
	if (_rtp_InitDebugOutput())
	{
		rtp_sig_mutex_claim(rtpDebugLock);
  #endif
		
		if (val)
		{
			char tmpbuffer[33]; /* MAXINT can have 32 digits max, base 2 */
			
			rtp_itoa(val, tmpbuffer, 2);
			buffer = tmpbuffer;
			for (i = 0; buffer[i]; i++)
			{
				if (giRTPDebugOutputPos >= RTP_DEBUG_STRING_LEN)
				{
					giRTPDebugOutputPos = 0;
				}
				gcRTPDebugOutputStr[giRTPDebugOutputPos++] = (char)buffer[i];
			}
		}

  #ifdef RTP_DEBUG_MULTITHREAD
		rtp_sig_mutex_release(rtpDebugLock);
	}
  #endif
}
Example #6
0
long rtsmb_srv_browse_get_next_wake_timeout (void)
{
    long rv = 0x7FFFFFFF;
    unsigned long current_time = rtp_get_system_msec();

    rtp_sig_mutex_claim((RTP_MUTEX) prtsmb_browse_ctx->mutex);

    if (rtsmb_srv_browse_announcement_send)
    {
        rv = MIN (rv, (long) (rtsmb_srv_browse_announcement_next_base + rtsmb_srv_browse_announcement_next_delay - current_time));
        rv = MAX (0, rv);
    }

    if (rtsmb_srv_browse_election_win_count > 0)
    {
        rv = MIN (rv, (long) (rtsmb_srv_browse_election_next_base + rtsmb_srv_browse_election_next_delay - current_time));
        rv = MAX (0, rv);
    }

    if (rtsmb_srv_browse_get_role () == RTSMB_SRV_BROWSE_ROLE_MASTER_BROWSER)
    {
        rv = MIN (rv, (long) (rtsmb_srv_browse_master_last_domain_announcement + RTSMB_SRV_BROWSE_DOMAIN_ANNOUNCE_DELAY - current_time));
        rv = MAX (0, rv);
    }

    rtp_sig_mutex_release((RTP_MUTEX) prtsmb_browse_ctx->mutex);

    return (rv == 0x7FFFFFFF) ? -1 : rv;
}
Example #7
0
/*---------------------------------------------------------------------------*/
int rtp_helper_thread_start (
		RTP_HELPER_THREAD_CTX* ctx		
	)
{
	int result = -1;
	RTP_THREAD threadHandle;

	rtp_sig_mutex_claim(ctx->mutex);
	
	if (rtp_thread_spawn (
			&threadHandle, 
			_rtp_helper_thread, 
			0, 
			RTP_HELPER_THREAD_STACK_SIZE, 
			RTP_HELPER_THREAD_PRIORITY, 
			ctx
		) >= 0)
	{
		ctx->numHelpersRunning++;
		result = 0;
	}
	
	rtp_sig_mutex_release(ctx->mutex);
	
	return (result);
}
Example #8
0
/*---------------------------------------------------------------------------*/
void _rtp_helper_thread (void* d)
{
RTP_HELPER_THREAD_CTX* ctx = (RTP_HELPER_THREAD_CTX*) d;
RTP_HELPER_THREAD_JOB* job;
long idleMsec = 0;	
	
	/* loop: wait for a job, process it */
	
	rtp_sig_mutex_claim(ctx->mutex);
	
	while (!ctx->stopping && idleMsec < ctx->maxIdleTimeMsec)
	{		
		rtp_sig_mutex_release(ctx->mutex);
		
		if (rtp_sig_semaphore_wait_timed(ctx->signal, RTP_HELPER_THREAD_QUEUE_TIMEOUT_MSEC) < 0)
		{
			idleMsec += RTP_HELPER_THREAD_QUEUE_TIMEOUT_MSEC;
			rtp_sig_mutex_claim(ctx->mutex);
			continue;
		}
		
		rtp_sig_mutex_claim(ctx->mutex);
		
		job = ctx->firstJob;
		if (job)
		{
			idleMsec = 0;
			if (job == ctx->lastJob)
			{
				ctx->lastJob = 0;
			}
			ctx->firstJob = job->next;
			job->next = 0;
			ctx->numHelpersActive++;
			rtp_sig_mutex_release(ctx->mutex);
			
			job->execute(job);
			
			rtp_sig_mutex_claim(ctx->mutex);
			ctx->numHelpersActive--;
		}
	}
	
	ctx->numHelpersRunning--;
	
	rtp_sig_mutex_release(ctx->mutex);
}
Example #9
0
/*---------------------------------------------------------------------------*/
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;
}
Example #10
0
/*----------------------------------------------------------------------*
                         rtp_debug_output_str
 *----------------------------------------------------------------------*/
void _rtp_debug_output_str (
	char* msg,
	const char *file,
	long line_num
	)
{
char* buffer;
int i;

  #ifdef RTP_DEBUG_MULTITHREAD
	if (_rtp_InitDebugOutput())
	{
		rtp_sig_mutex_claim(rtpDebugLock);
  #endif

	  #ifdef RTP_DEBUG_OUTPUT_FILE_AND_LINE
		buffer = file;
		for (i = 0; buffer[i]; i++)
		{
			if (giRTPDebugOutputPos >= RTP_DEBUG_STRING_LEN)
			{
				giRTPDebugOutputPos = 0;
			}
			gcRTPDebugOutputStr[giRTPDebugOutputPos++] = buffer[i];
		}
		
		if (line_num)
		{
			char tmpbuffer[33]; /* MAXINT can have 32 digits max, base 2 */
			
			rtp_itoa(line_num, tmpbuffer, 2);
			buffer = tmpbuffer;
			for (i = 0; buffer[i]; i++)
			{
				if (giRTPDebugOutputPos >= RTP_DEBUG_STRING_LEN)
				{
					giRTPDebugOutputPos = 0;
				}
				gcRTPDebugOutputStr[giRTPDebugOutputPos++] = buffer[i];
			}
		}
	  #endif

		buffer = msg;
		for (i = 0; buffer[i]; i++)
		{
			if (giRTPDebugOutputPos >= RTP_DEBUG_STRING_LEN)
			{
				giRTPDebugOutputPos = 0;
			}
			gcRTPDebugOutputStr[giRTPDebugOutputPos++] = buffer[i];
		}

  #ifdef RTP_DEBUG_MULTITHREAD
		rtp_sig_mutex_release(rtpDebugLock);
	}
  #endif
	rtp_printf("RTP debug %s\n",gcRTPDebugOutputStr);
}
Example #11
0
static void _rtp_FreeMemBlock(void *ptr, const char* file, long line)
{
RTPMemBlockHeader *pFreedBlock = (RTPMemBlockHeader *) ptr;

  #ifdef RTP_MEM_DEBUG_MULTITHREAD
	if (_rtp_InitMemDebug())
	{
		rtp_sig_mutex_claim(rtpMemDebugLock);
  #endif

	  #ifdef RTP_MEM_DEBUG_LOG_SIZE

		if (ptr == rtpMemDebugLog[pFreedBlock->logIndex].location &&
		    pFreedBlock->file == rtpMemDebugLog[pFreedBlock->logIndex].allocedFromFile &&
		    pFreedBlock->line == rtpMemDebugLog[pFreedBlock->logIndex].allocedFromLine)
		{
			rtpMemDebugLog[pFreedBlock->logIndex].freedFromFile = file;
			rtpMemDebugLog[pFreedBlock->logIndex].freedFromLine = line;
			rtpMemDebugLog[pFreedBlock->logIndex].freedAtTime = rtpMemDebugLogTime++;
			rtpMemDebugLog[pFreedBlock->logIndex].freed = 1;
		}

		if (rtpMemDebugLogPrint)
		{
			_rtp_debug_print_log("memlog.csv", "wb+");
			rtpMemDebugLogPrint = 0;
			rtpMemDebugLogPrintFilter = 0;
		}

	  #endif /* RTP_MEM_DEBUG_LOG_SIZE */

		if (pFreedBlock->file && (pFreedBlock->flags & dbMFlagIgnore)==0)
		{
			giMemFreed += pFreedBlock->size;
			if (pFreedBlock->flags&dbMFlagNewEntry)
				giMemNewed -= pFreedBlock->size;
			else
				giMemUsed -= pFreedBlock->size;
		}

		if (pFreedBlock->prev)
		{
			pFreedBlock->prev->next = pFreedBlock->next;
		}

		if (pFreedBlock->next)
		{
			pFreedBlock->next->prev = pFreedBlock->prev;
		}
		else
		{
			gpMemBlockList = pFreedBlock->prev;
		}

  #ifdef RTP_MEM_DEBUG_MULTITHREAD
		rtp_sig_mutex_release(rtpMemDebugLock);
	}
  #endif
}
Example #12
0
/*---------------------------------------------------------------------------*/
static void _rtp_pbuf_ctx_add_ts (RTP_PBUF_CTX* pbufCtx, RTP_PBUF_RESOURCE* resource)
{
	if (rtp_sig_mutex_claim(pbufCtx->lock) >= 0)
	{
		_rtp_pbuf_ctx_add(pbufCtx, resource);
		rtp_sig_mutex_release(pbufCtx->lock);
	}
}
Example #13
0
/*---------------------------------------------------------------------------*/
static void _rtp_pbuf_ctx_destroy_ts (RTP_PBUF_CTX* pbufCtx)
{
	if (rtp_sig_mutex_claim(pbufCtx->lock) >= 0)
	{
		_rtp_pbuf_ctx_destroy(pbufCtx);
		rtp_sig_mutex_release(pbufCtx->lock);
	}
}
Example #14
0
void rtsmb_srv_browse_shutdown (void)
{
    rtp_sig_mutex_claim((RTP_MUTEX) prtsmb_browse_ctx->mutex);

    if (rtsmb_srv_browse_announcement_send)
    {
        rtsmb_srv_browse_send_host_announcement (TRUE);
    }

    rtp_sig_mutex_release((RTP_MUTEX) prtsmb_browse_ctx->mutex);
}
Example #15
0
void rtsmb_srv_browse_restart_announcements (void)
{

    rtp_sig_mutex_claim((RTP_MUTEX) prtsmb_browse_ctx->mutex);

    rtsmb_srv_browse_announcement_count = 0;
    rtsmb_srv_browse_announcement_next_base = rtp_get_system_msec();
    rtsmb_srv_browse_announcement_next_delay = 0;

    rtp_sig_mutex_release((RTP_MUTEX) prtsmb_browse_ctx->mutex);
}
Example #16
0
/*---------------------------------------------------------------------------*/
static void* _rtp_pbuf_ctx_pop_ts (RTP_PBUF_CTX* pbufCtx)
{
RTP_PBUF_ELEMENT* tempElement;

	if (rtp_sig_mutex_claim(pbufCtx->lock) >= 0)
	{
		tempElement = _rtp_pbuf_ctx_pop(pbufCtx);
		rtp_sig_mutex_release(pbufCtx->lock);
		return ((void*)tempElement);
	}
	return ((void*)0);
}
Example #17
0
void rtsmb_srv_browse_domain_list_remove_all (void)
{
    int i;

    rtp_sig_mutex_claim((RTP_MUTEX) prtsmb_browse_ctx->mutex);

    for (i = 0; i < prtsmb_srv_ctx->domain_table_size; i++)
    {
        prtsmb_srv_ctx->domain_table[i].type = 0;
    }

    rtp_sig_mutex_release((RTP_MUTEX) prtsmb_browse_ctx->mutex);
}
Example #18
0
/*---------------------------------------------------------------------------*/
static void _rtp_pbuf_ctx_push_ts (void* data)
{
RTP_PBUF_ELEMENT* tempElement;

	tempElement = (RTP_PBUF_ELEMENT*) (((unsigned long)data) - RTP_PBUF_ELEMENT_START_OFFSET);
	if (rtp_sig_mutex_claim(tempElement->elementOwner->lock) >= 0)
	{
		tempElement->next = tempElement->elementOwner->firstElement;
		tempElement->elementOwner->firstElement = tempElement;
		(tempElement->elementOwner->elementsAvailable)++;
		rtp_sig_mutex_release(tempElement->elementOwner->lock);
	}
}
Example #19
0
void rtsmb_srv_browse_set_announcement_info (BBOOL send)
{
    rtp_sig_mutex_claim((RTP_MUTEX) prtsmb_browse_ctx->mutex);

    rtsmb_srv_browse_announcement_send = send;

    if (!send)
    {
        /* if we're stopping browser service, demote ourselves to potential
           browser */
        rtsmb_srv_browse_switch_role (RTSMB_SRV_BROWSE_ROLE_POTENTIAL_BROWSER);
    }

    rtp_sig_mutex_release((RTP_MUTEX) prtsmb_browse_ctx->mutex);
}
Example #20
0
void rtsmb_srv_browse_domain_list_add (PRTSMB_BROWSE_SERVER_INFO pinfo)
{
    int i;

    rtp_sig_mutex_claim((RTP_MUTEX) prtsmb_browse_ctx->mutex);

    for (i = 0; i < prtsmb_srv_ctx->domain_table_size; i++)
    {
        if (prtsmb_srv_ctx->domain_table[i].type == 0)
        {
            prtsmb_srv_ctx->domain_table[i] = *pinfo;
            break;
        }
    }

    rtp_sig_mutex_release((RTP_MUTEX) prtsmb_browse_ctx->mutex);
}
Example #21
0
/*---------------------------------------------------------------------------*/
int rtp_queue_peek (RTPMessageQueue *queue)
{
int first;
int last;

	if (rtp_sig_mutex_claim(queue->lock) < 0)
	{
		return (-1);
	}
	
	first = queue->first;
	last = queue->last;
	
	rtp_sig_mutex_release(queue->lock);
		
	if (last < first)
	{
		last += queue->queueSize;
	}
	
	return (last - first);
}
Example #22
0
/*---------------------------------------------------------------------------*/
int rtp_helper_thread_queue_job (
		RTP_HELPER_THREAD_CTX* ctx,
		RTP_HELPER_THREAD_JOB* job
	)
{
	rtp_sig_mutex_claim(ctx->mutex);	
	
	if (ctx->lastJob)
	{
		ctx->lastJob->next = job;		
	}	
	else
	{
		ctx->firstJob = job;
	}
	job->next = 0;
	ctx->lastJob = job;
	rtp_sig_semaphore_signal(ctx->signal);	
	
	rtp_sig_mutex_release(ctx->mutex);

	return (0);
}
Example #23
0
/*---------------------------------------------------------------------------*/
int rtp_queue_get (RTPMessageQueue *queue, void *message)
{
	if (rtp_sig_semaphore_wait(queue->sem) < 0)
	{
		return (-1);
	}
	
	if (rtp_sig_mutex_claim(queue->lock) < 0)
	{
		return (-1);
	}
	
	if (queue->first != queue->last)
	{
		tc_memcpy((char *) message, &queue->messages[queue->first * queue->msgSize], queue->msgSize);
		
		queue->first = (queue->first + 1) % queue->queueSize;
	}
	
	rtp_sig_mutex_release(queue->lock);

	return (0);
}
Example #24
0
/*---------------------------------------------------------------------------*/
int rtp_queue_put (RTPMessageQueue *queue, void *message)
{
	if (rtp_sig_mutex_claim(queue->lock) < 0)
	{
		return (-1);
	}
	
	/* make sure the queue is not full */
	if ((queue->last + 1) % queue->queueSize == queue->first)
	{
		rtp_sig_mutex_release(queue->lock);	
		return (-1);
	}
		
	tc_memcpy(&queue->messages[queue->last * queue->msgSize], (char *) message, queue->msgSize);

	queue->last = (queue->last + 1) % queue->queueSize;
		
	rtp_sig_semaphore_signal(queue->sem);
	rtp_sig_mutex_release(queue->lock);
	
	return (0);
}
Example #25
0
/*---------------------------------------------------------------------------*/
int  rtp_timer_stop    (RTP_TIMER* timer)
{
	int result = -1;
	
	rtp_sig_mutex_claim(rtpTimerLock);
	
	switch (timer->listId)
	{
		case RTP_TIMER_LIST_NONE:
			break;

		case RTP_TIMER_LIST_ACTIVE:
			if (rtpTimerNextToProcess == timer)
			{
				rtpTimerNextToProcess = timer->next;
			}
			/* intentional fall-through */
			
		case RTP_TIMER_LIST_NEW:
			DLLIST_REMOVE(timer);
			DLLIST_INIT(timer);
			timer->listId = RTP_TIMER_LIST_NONE;
			result = 0;

			if (!rtpTimerThreadAwake)
			{
				rtpTimerThreadAwake = 1;
				rtp_sig_semaphore_signal(rtpTimerSignal);		
			}
			break;
	}
	
	rtp_sig_mutex_release(rtpTimerLock);
		
	return (result);
}
Example #26
0
/*
================

================
*/
int NetServerEnum2 (PSMB_SESSIONCTX pCtx, PRTSMB_RAP_REQUEST pFunc,
    PRTSMB_HEADER pInHdr, PFVOID pInBuf,
    PRTSMB_HEADER pOutHdr,
    rtsmb_size size_left, PFWORD param_size)
{
    RTSMB_RAP_SERVER_ENUM2 command;
    RTSMB_RAP_ENUM_HEADER_R header;
    RTSMB_RAP_SERVER_INFO_1 info;
    PRTSMB_BROWSE_SERVER_INFO plist;
    PFVOID data_section;
    PFVOID pOutBuf = pCtx->tmpBuffer;
    int r, i, j, max_possible;
    rtsmb_char domain [RTSMB_NB_NAME_SIZE + 1];

    command.domain = domain;
    command.domain_size = RTSMB_NB_NAME_SIZE;
    r = srv_cmd_read_rap_server_enum2 (pCtx->write_origin, pInBuf,
        pCtx->current_body_size - (rtsmb_size)(PDIFF (pInBuf, pCtx->read_origin)), pInHdr,
        &command);
    if (r == -1)
        return -1;

    size_left = MIN (command.receive_size, size_left);

    // Fill out parameters
    header.status = RAP_ERROR_ACCESS_DENIED;
    header.converter = 0;
    header.entry_count = 0;
    header.available_entries = 0;

    r = srv_cmd_fill_rap_share_enum_header (pCtx->tmpBuffer, pCtx->tmpBuffer,
        size_left, pOutHdr, &header);
    if (r == -1)
        return r;
    size_left -= (rtsmb_size)r;
    *param_size = (word)r;

    pOutBuf = PADD (pCtx->tmpBuffer, r);
    data_section = pOutBuf;

    rtp_sig_mutex_claim((RTP_MUTEX) prtsmb_browse_ctx->mutex);

    header.entry_count = 0;
    header.available_entries = 0;
    info.info_total = 0;

    if (pCtx->state == BROWSE_FAIL)
    {
        /* domain is invalid.   tell client */
        header.status = RAP_NERR_INVALID_DOMAIN;
        srv_cmd_fill_rap_share_enum_header (pCtx->tmpBuffer, pCtx->tmpBuffer,
            size_left, pOutHdr, &header);
        return r;
    }
    else if (pCtx->state == BROWSE_FINISH)
    {
        /* we have previously been here and punted our netenum2 to another
           server.  here, we have the data now and we want to ship it out. */
        plist = prtsmb_srv_ctx->enum_results;
        max_possible = prtsmb_srv_ctx->enum_results_size;
    }
    /* is this a domain enum or server enum? */
    else if (command.server_type == SV_TYPE_DOMAIN_ENUM)
    {
        plist = prtsmb_srv_ctx->domain_table;
        max_possible = prtsmb_srv_ctx->domain_table_size;
    }
    else
    {
        char group_name [RTSMB_NB_NAME_SIZE + 1];

        plist = prtsmb_srv_ctx->server_table;
        max_possible = prtsmb_srv_ctx->server_table_size;

        rtsmb_util_rtsmb_to_ascii (command.domain, group_name, CFG_RTSMB_USER_CODEPAGE);

        /* if the group name is null or the same as our group, we just get it from
           our own list.  else, we need to outsource the netenum2 */
        if (group_name[0] && rtsmb_strcasecmp (group_name, rtsmb_srv_nbns_get_our_group (), CFG_RTSMB_USER_CODEPAGE) != 0)
        {
            rtp_sig_mutex_release((RTP_MUTEX) prtsmb_browse_ctx->mutex);

            /* we have a server enum request outside of our own workgroup. */
            /* punt it off to the browse layer, which will come up with something to hand over */
            pCtx->state = BROWSE_MUTEX;
            pCtx->server_enum_type = command.server_type;
            tc_strcpy (pCtx->server_enum_domain, group_name);

            rtsmb_srv_browse_finish_server_enum (pCtx);

            return -2; /* tell upper layers to not send response yet */
        }
    }

    // find out how many servers there are.
    for (i = 0; i < max_possible; i++)
    {
        if (plist[i].type & command.server_type)
        {
            info.info_total++;
        }
    }

    // pack each server into the buffer.
    for (i = 0, j = 0, r = 0; i < max_possible; i++)
    {
        int this_r;
        rtsmb_char comment [RTSMB_MAX_COMMENT_SIZE + 1];

        /* take care of non-used types (0-value 'type') and
           servers we aren't interested in */
        if ((plist[i].type & command.server_type) == 0)
        {
            continue;
        }

        info.info_num = info.info_total - (j++) - 1;

        rtsmb_util_ascii_to_rtsmb (plist[i].name, info.name, CFG_RTSMB_USER_CODEPAGE);
        info.type = plist[i].type;
        rtsmb_util_ascii_to_rtsmb (plist[i].comment, comment, CFG_RTSMB_USER_CODEPAGE);
        info.comment = comment;
        info.version_minor = plist[i].version_minor;
        info.version_major = plist[i].version_major;

        header.entry_count++;
        header.available_entries++;

        if (command.information_level == 0)
        {
            this_r = srv_cmd_fill_rap_server_enum_info_0 (pCtx->tmpBuffer, pOutBuf,
                size_left, pOutHdr, &info);
        }
        else /* must be one... */
        {
            this_r = srv_cmd_fill_rap_server_enum_info_1 (pCtx->tmpBuffer, pOutBuf,
                size_left, pOutHdr, &info);
        }

        if (this_r == -1)
            break;

        r += this_r;
    }

    rtp_sig_mutex_release((RTP_MUTEX) prtsmb_browse_ctx->mutex);

    if (r == -1)
    {
        header.status = RAP_NERR_BUFTOOSMALL;
        header.converter = 0;
        r = 0;
    }
    else
    {
        header.status = RAP_NERR_SUCCESS;
        header.converter = (word)(((int) data_section) & 0xFFFF);
    }

    srv_cmd_fill_rap_share_enum_header (pCtx->tmpBuffer, pCtx->tmpBuffer,
        size_left, pOutHdr, &header);

    return r;
}
Example #27
0
static void _rtp_AddMemBlock(void *ptr, unsigned long size, const char *file, long line,const char *comment, unsigned long flags)
{
RTPMemBlockHeader *pNewBlock = (RTPMemBlockHeader *) ptr;
void (*fn)(const char *, long, void *);
void* ctx;

  fn = 0;
  ctx = 0;
  rtp_memset((void *) pNewBlock,0, sizeof(*pNewBlock));
  #ifdef RTP_MEM_DEBUG_MULTITHREAD
	if (_rtp_InitMemDebug())
	{
		rtp_sig_mutex_claim(rtpMemDebugLock);
  #endif

	  #if (RTP_MEM_BLOCK_ID_SIZE > 0)
		memset(pNewBlock->id, RTP_MEM_BLOCK_ID_BYTE, RTP_MEM_BLOCK_ID_SIZE);
	  #endif

	  #if (RTP_MEM_BLOCK_PREPAD_SIZE > 0)
		memset(pNewBlock->prepad, RTP_MEM_BLOCK_PREPAD_BYTE, RTP_MEM_BLOCK_PREPAD_SIZE);
	  #endif

		if (file && (flags&dbMFlagIgnore)==0)
		{
			giMemAlloced += size;
			if (flags&dbMFlagNewEntry)
				giMemNewed += size;
			else
				giMemUsed += size;
			if (giMemUsed+giMemNewed > giMaxMemUsed)
			{
				guMaxUsageSeq = guMallocSequence;
				giMaxMemUsed = giMemUsed+giMemNewed;
				if (giMaxMemUsed>gpMemHighWaterThreshhold)
				{
					fn = gMemHighWaterCallbackFn;
					ctx = gpMemHighWaterCallbackCtx;
				}
			}
		}

		pNewBlock->size = size;
		pNewBlock->seq  = guMallocSequence++;
		pNewBlock->file = file;
		pNewBlock->line = line;
		pNewBlock->comment = comment;
		pNewBlock->flags  = flags;
	  #ifdef RTP_MEM_DEBUG_LOG_SIZE
		pNewBlock->logIndex = rtpMemDebugLogIndex++;

		if (rtpMemDebugLogIndex >= RTP_MEM_DEBUG_LOG_SIZE)
		{
			rtpMemDebugLogWrap = 1;
			rtpMemDebugLogIndex = 0;
		}

		rtpMemDebugLog[pNewBlock->logIndex].location = ptr;
		rtpMemDebugLog[pNewBlock->logIndex].size = size;
		rtpMemDebugLog[pNewBlock->logIndex].allocedFromFile = file;
		rtpMemDebugLog[pNewBlock->logIndex].allocedFromLine = line;
		rtpMemDebugLog[pNewBlock->logIndex].allocedAtTime = rtpMemDebugLogTime++;
		rtpMemDebugLog[pNewBlock->logIndex].freedFromFile = 0;
		rtpMemDebugLog[pNewBlock->logIndex].freedFromLine = 0;
		rtpMemDebugLog[pNewBlock->logIndex].freedAtTime = 0;
		rtpMemDebugLog[pNewBlock->logIndex].freed = 0;

		if (rtpMemDebugLogPrint)
		{
			_rtp_debug_print_log("memlog.csv", "wb+");
			rtpMemDebugLogPrint = 0;
			rtpMemDebugLogPrintFilter = 0;
		}

	  #endif /* RTP_MEM_DEBUG_LOG_SIZE */

		/* ----------------------------------- */
		/*        link pNewBlock onto          */
		/*        the end of the list          */
		/* ----------------------------------- */
		pNewBlock->prev = gpMemBlockList;
		pNewBlock->next = 0;

		if (gpMemBlockList)
		{
			gpMemBlockList->next = pNewBlock;
		}
		gpMemBlockList = pNewBlock;

  #ifdef RTP_MEM_DEBUG_MULTITHREAD
		rtp_sig_mutex_release(rtpMemDebugLock);
	}
  #endif

	if (fn)
	{
		fn(file, line, ctx);
	}
}
Example #28
0
void rtsmb_srv_browse_cycle (void)
{
    unsigned long current_time;

    rtp_sig_mutex_claim((RTP_MUTEX) prtsmb_browse_ctx->mutex);

    if (!rtsmb_srv_browse_announcement_send)
    {

        rtp_sig_mutex_release((RTP_MUTEX) prtsmb_browse_ctx->mutex);
        return;
    }

    current_time = rtp_get_system_msec ();

    /* Now, do periodic items that we need to fulfill our role.   */

    if (IS_PAST_THIS (current_time, rtsmb_srv_browse_announcement_next_base,
                      rtsmb_srv_browse_announcement_next_delay))
    {
        rtsmb_srv_browse_send_host_announcement (FALSE);
        rtsmb_srv_browse_announcement_next_base = current_time;
        rtsmb_srv_browse_announcement_next_delay = rtsmb_srv_browse_get_announcement_interval ();
    }

    if (rtsmb_srv_browse_election_win_count > 0 && rtsmb_srv_browse_election_waiting_to_send &&
        IS_PAST_THIS (current_time, rtsmb_srv_browse_election_next_base, rtsmb_srv_browse_election_next_delay))
    {
        rtsmb_srv_browse_send_request_election ();
        rtsmb_srv_browse_election_waiting_to_send = FALSE;
    }

    if (rtsmb_srv_browse_election_win_count > 0 &&
        IS_PAST_THIS (current_time,
                      rtsmb_srv_browse_election_last_send, RTSMB_SRV_BROWSE_ELECTION_TIMEOUT))
    {
        /* no one has responded to our election request.  try again or takeover   */
        rtsmb_srv_browse_election_win_count ++;

        if (rtsmb_srv_browse_election_win_count > 4)
        {
            rtsmb_srv_browse_election_takeover ();
        }
        else
        {
            rtsmb_srv_browse_send_request_election ();
        }
    }

    /* do routine job-specific duties   */
    switch (rtsmb_srv_browse_get_role ())
    {
    case RTSMB_SRV_BROWSE_ROLE_BACKUP_BROWSER:
        rtsmb_srv_browse_backup_cycle ();

        /* INTENTIONAL FALLTHROUGH   */

    /* check for existance of master browser   */
    case RTSMB_SRV_BROWSE_ROLE_POTENTIAL_BROWSER:
        rtsmb_srv_browse_check_master_browser ();
        break;

    case RTSMB_SRV_BROWSE_ROLE_MASTER_BROWSER:
        rtsmb_srv_browse_check_dead_servers ();

        if (IS_PAST_THIS (current_time,
                          rtsmb_srv_browse_master_last_domain_announcement,
                          RTSMB_SRV_BROWSE_DOMAIN_ANNOUNCE_DELAY))
        {
            rtsmb_srv_browse_send_domain_announcement ();
            rtsmb_srv_browse_master_last_domain_announcement = rtp_get_system_msec ();
        }

        break;
    }

    rtp_sig_mutex_release((RTP_MUTEX) prtsmb_browse_ctx->mutex);
}