예제 #1
0
파일: rtpdate.c 프로젝트: layerfsd/cifssmb
/** @memo   Set the current system date.

    @doc    Sets the system date to the new date passed in.

    @return 0 on success. -1 otherwise.
 */
int rtp_set_date (
  RTP_DATE * date               /** The new system date to be set. */
  )
{
    baseReference.syncTime = rtp_get_system_sec();
    baseReference.referenceDate.year     = date->year;
    baseReference.referenceDate.month    = date->month;
    baseReference.referenceDate.day      = date->day;
    baseReference.referenceDate.hour     = date->hour;
    baseReference.referenceDate.minute   = date->minute;
    baseReference.referenceDate.second   = date->second;
    baseReference.referenceDate.msec     = date->msec;
    baseReference.referenceDate.dlsTime  = date->dlsTime;
    baseReference.referenceDate.tzOffset = date->tzOffset;

	return (0);
}
예제 #2
0
파일: rtpdate.c 프로젝트: layerfsd/cifssmb
/** @memo   Retrieve the current system date.

    @doc    Retrieves the current system date and returns it in the
    storage location.

    @precondition The baseReference must refer to a valid date.

    @return 0 on success. -1 otherwise.
 */
int rtp_get_date (
  RTP_DATE *date                /** Storage location for the current system date. */
  )
{
unsigned long deltaSecs;

	*date = baseReference.referenceDate;

    deltaSecs = rtp_get_system_sec() - baseReference.syncTime;
    
    if (deltaSecs > 0)
    {
		date->second += deltaSecs;  
		date->second %= 60;    
		deltaSecs /= 60;

	    if (deltaSecs > 0)
	    {
			date->minute += deltaSecs;  
			date->minute %= 60;    
			deltaSecs /= 60;

		    if (deltaSecs > 0)
		    {
				date->hour += deltaSecs;  
				date->hour %= 24;    
				deltaSecs /= 24;

			    if (deltaSecs > 0)
			    {
			    	int total_days;
			    	
					date->day += deltaSecs;  
					date->day %= 24;    
					deltaSecs /= 24;
					
					if (_is_leap_year(date->year))
					{
						total_days = month_start_leap[date->month] + date->day + deltaSecs;
					}
					else
					{
						total_days = month_start[date->month] + date->day + deltaSecs;
					}
					
					while (1)
					{
						if (_is_leap_year(date->year))
						{
							if (total_days < 366)
							{
								break;
							}							
							total_days -= 366;
						}
						else
						{
							if (total_days < 365)
							{
								break;
							}
							total_days -= 365;
						}
						
						date->year++;
					}

					if (_is_leap_year(date->year))
					{
						for (date->month=0; 
						     date->month < 11 && month_start_leap[date->month + 1] < total_days; 
						     date->month++) 
						{;}
						
						date->day = total_days - month_start_leap[date->month] + 1;
					}
					else
					{
						for (date->month=0; 
						     date->month < 11 && month_start[date->month + 1] < total_days; 
						     date->month++) 
						{;}
						
						date->day = total_days - month_start[date->month] + 1;
					}
					
					date->month++;					
			    }
		    }
	    }
	}

	return (0);
}
예제 #3
0
파일: upnp.c 프로젝트: maojxsir/upnp
/*----------------------------------------------------------------------------*
                               UPnP_ProcessState
 *----------------------------------------------------------------------------*/
int  _UPnP_ProcessState (
		UPnPRuntime* rt,       /** pointer to \Ref{UPnPRuntime} struct */
		UPNP_INT32 msecTimeout /** time in miliseconds for which the function blocks */
	)
{
	RTP_FD_SET readList;
	RTP_FD_SET writeList;
	RTP_FD_SET errList;
	RTP_INT32 timeout;
	RTP_UINT32 currentTimeSec;

	/* reset the select lists */
	rtp_fd_zero(&readList);
	rtp_fd_zero(&writeList);
	rtp_fd_zero(&errList);

	currentTimeSec = rtp_get_system_sec();

	/* --- DEVICE Announcements ------------------------------ */
	if (rt->deviceRuntime)
	{
		timeout = rt->deviceRuntime->nextAnnounceTimeSec - currentTimeSec;
		if (timeout < 0)
		{
			timeout = 0;
		}
	}
	else
	{
		timeout = msecTimeout;
	}

	/* --- SSDP ---------------------------------------------- */
	timeout = _UPnP_UpdateTimeout(
			SSDP_ServerAddToSelectList (
					&rt->ssdpContext,
					&readList,
					&writeList,
					&errList
				),
			timeout
		);

	/* --- HTTP Server --------------------------------------- */
	rtp_fd_set(&readList, HTTP_ServerGetSocket(&rt->httpServer));

	/* --- CONTROL POINT-------------------------------------- */
	if (rt->controlPoint)
	{
	  	UPNP_RUNTIME_EXIT_CRITICAL(rt);

		timeout = _UPnP_UpdateTimeout(
				rtp_net_sm_add_to_select_list (
						&rt->controlPoint->requestManager,
						&readList,
						&writeList,
						&errList
					),
				timeout
			);
	}
	else
	{
  		UPNP_RUNTIME_EXIT_CRITICAL(rt);
  	}

	rtp_net_select(&readList, &writeList, &errList, timeout);

  	UPNP_RUNTIME_ENTER_CRITICAL(rt);

	/* --- SSDP ---------------------------------------------- */
	SSDP_ServerProcessState (
			&rt->ssdpContext,
			&readList,
			&writeList,
			&errList
		);

	/* --- HTTP Server --------------------------------------- */
	if (rtp_fd_isset(&readList, HTTP_ServerGetSocket(&rt->httpServer)))
	{
	  	UPNP_RUNTIME_EXIT_CRITICAL(rt);
		HTTP_ServerProcessOneRequest(&rt->httpServer, 0);
	  	UPNP_RUNTIME_ENTER_CRITICAL(rt);
	}

	/* --- CONTROL POINT-------------------------------------- */
	if (rt->controlPoint)
	{
	  	UPNP_RUNTIME_EXIT_CRITICAL(rt);

		rtp_net_sm_process_state (
				&rt->controlPoint->requestManager,
				&readList,
				&writeList,
				&errList
			);

	  	UPNP_RUNTIME_ENTER_CRITICAL(rt);
	}

	/* --- DEVICE Announcements ------------------------------ */
	if (rt->deviceRuntime)
	{
		currentTimeSec = rtp_get_system_sec();

		if ((long)(currentTimeSec - rt->deviceRuntime->nextAnnounceTimeSec) >= 0)
		{
			rt->deviceRuntime->nextAnnounceTimeSec = currentTimeSec + rt->deviceRuntime->announceFrequencySec;
			rt->deviceRuntime->announceAll(rt->deviceRuntime);
		}
	}

	return (0);
}