Пример #1
0
std::string DateTime::to_string() const
{
	throw_if_null();
	// Mon Feb 3 12:32:54 2008
	std::string months[] =
	{
		"Jan",
		"Feb",
		"Mar",
		"Apr",
		"May",
		"Jun",
		"Jul",
		"Aug",
		"Sep",
		"Oct",
		"Nov",
		"Dec"
	};
	
	std::string days[] =
	{
		"Sun",
		"Mon",
		"Tue",
		"Wed",
		"Thu",
		"Fri",
		"Sat"
	};

	StringFormat format("%1 %2 %3 %4:%5:%6 %7");
	format.set_arg(1, days[get_day_of_week()]);
	format.set_arg(2, months[get_month() - 1]);
	format.set_arg(3, get_day());
	format.set_arg(4, get_hour(), 2);
	format.set_arg(5, get_minutes(), 2);
	format.set_arg(6, get_seconds(), 2);
	format.set_arg(7, get_year());
	return format.get_result();
}
//---------------------------------------------------------------------------------------
//Output Date (dd-mm-yy) & Time (hh:mm:ss)
int output_date_time(void){
	// Get the current date and time
	ds1307_read_date_time();
	// Get binary values + convert to ascii string
	bin_to_ascii(get_seconds(), secondASCII);
	bin_to_ascii(get_minutes(), minuteASCII);
	bin_to_ascii(get_hours(), hourASCII);
	bin_to_ascii(get_day(), dayASCII);
	bin_to_ascii(get_month(), monthASCII);
	bin_to_ascii(get_year(), yearASCII);
	// Send to LCD
	lcd_send_cmd(LINE1);
	lcd_printf(hourASCII); lcd_printf(":");
	lcd_printf(minuteASCII); lcd_printf(":");
	lcd_printf(secondASCII);
	lcd_send_cmd(LINE2);
	lcd_printf(dayASCII); lcd_printf("-");
	lcd_printf(monthASCII); lcd_printf("-");
	lcd_printf(yearASCII);
		
	return 0;
}
Пример #3
0
int main(int argc, char* argv[]){

	int year, month, day;

	year = get_year("Please Input the Year: ");
	month = get_month("the Month: ");
	day = get_day("the Day: ", year, month);

	if( is_leap(year) ){
		months[1] = 29;
	}

	int i, days = 0;
	
	for(i = 0; i < month - 1; i++){
		days += months[i];
	}

	days += day;

	printf("%d.%d.%d is the %d days of this year.\n", year, month, day, days);

	return 0;
}
Пример #4
0
Ustring
Date::get_weekday_str() const
{
    // from wikipedia: http://en.wikipedia.org/wiki/Calculating_the_day_of_the_week
    const unsigned int year = get_year();
    const unsigned int century = ( year - ( year % 100 ) ) / 100;
    int c = 2 * ( 3 - ( century % 4 ) );
    int y = year % 100;
    y = y + floor( y / 4 );

    static const int t_m[] = { 0, 3, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5 };
    struct tm ti;

    int m = get_month() - 1;
    int d = ( c + y + t_m[ m ] + get_day() );

    if( !( get_year() % 4 ) && m < 2 )  // leap year!
        d += 6;

    ti.tm_wday = ( d % 7 );
    char buf[ 32 ];
    strftime( buf, 32, "%A", &ti );
    return Ustring( buf );
}
Пример #5
0
void mc146818_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
{
	switch (id)
	{
	case TIMER_PERIODIC:
		m_data[REG_C] |= REG_C_PF;
		update_irq();
		break;

	case TIMER_CLOCK:
		if (!(m_data[REG_B] & REG_B_SET))
		{
			/// TODO: find out how the real chip deals with updates when binary/bcd values are already outside the normal range
			int seconds = get_seconds() + 1;
			if (seconds < 60)
			{
				set_seconds(seconds);
			}
			else
			{
				set_seconds(0);

				int minutes = get_minutes() + 1;
				if (minutes < 60)
				{
					set_minutes(minutes);
				}
				else
				{
					set_minutes(0);

					int hours = get_hours() + 1;
					if (hours < 24)
					{
						set_hours(hours);
					}
					else
					{
						set_hours(0);

						int dayofweek = get_dayofweek() + 1;
						if (dayofweek <= 7)
						{
							set_dayofweek(dayofweek);
						}
						else
						{
							set_dayofweek(1);
						}

						int dayofmonth = get_dayofmonth() + 1;
						if (dayofmonth <= gregorian_days_in_month(get_month(), get_year() + 2000))
						{
							set_dayofmonth(dayofmonth);
						}
						else
						{
							set_dayofmonth(1);

							int month = get_month() + 1;
							if (month <= 12)
							{
								set_month(month);
							}
							else
							{
								set_month(1);

								set_year((get_year() + 1) % 100);
							}
						}
					}
				}
			}

			if ((m_data[REG_ALARM_SECONDS] == m_data[REG_SECONDS] || (m_data[REG_ALARM_SECONDS] & ALARM_DONTCARE) == ALARM_DONTCARE) &&
				(m_data[REG_ALARM_MINUTES] == m_data[REG_MINUTES] || (m_data[REG_ALARM_MINUTES] & ALARM_DONTCARE) == ALARM_DONTCARE) &&
				(m_data[REG_ALARM_HOURS] == m_data[REG_HOURS] || (m_data[REG_ALARM_HOURS] & ALARM_DONTCARE) == ALARM_DONTCARE))
			{
				// set the alarm interrupt flag AF
				m_data[REG_C] |= REG_C_AF;
			}

			// set the update-ended interrupt Flag UF
			m_data[REG_C] |=  REG_C_UF;
			update_irq();

			m_last_refresh = machine().time();
		}
		break;
	}
}
Пример #6
0
static time_t
decode_broken_date (struct _date_token *tokens, int *tzone)
{
	gboolean got_wday, got_month, got_tzone;
	int hour, min, sec, offset, n;
	struct _date_token *token;
	struct tm tm;
	time_t time;

	memset ((void *) &tm, 0, sizeof (struct tm));
	got_wday = got_month = got_tzone = FALSE;
	offset = 0;

	token = tokens;
	while (token) {
		if (is_weekday (token) && !got_wday) {
			if ((n = get_wday (token->start, token->len)) != -1) {
				d(printf ("weekday; "));
				got_wday = TRUE;
				tm.tm_wday = n;
				goto next_token;
			}
		}

		if (is_month (token) && !got_month) {
			if ((n = get_month (token->start, token->len)) != -1) {
				d(printf ("month; "));
				got_month = TRUE;
				tm.tm_mon = n;
				goto next_token;
			}
		}

		if (is_time (token) && !tm.tm_hour && !tm.tm_min && !tm.tm_sec) {
			if (get_time (token->start, token->len, &hour, &min, &sec)) {
				d(printf ("time; "));
				tm.tm_hour = hour;
				tm.tm_min = min;
				tm.tm_sec = sec;
				goto next_token;
			}
		}

		if (is_tzone (token) && !got_tzone) {
			struct _date_token *t = token;

			if ((n = get_tzone (&t)) != -1) {
				d(printf ("tzone; "));
				got_tzone = TRUE;
				offset = n;
				goto next_token;
			}
		}

		if (is_numeric (token)) {
			if (token->len == 4 && !tm.tm_year) {
				if ((n = get_year (token->start, token->len)) != -1) {
					d(printf ("year; "));
					tm.tm_year = n - 1900;
					goto next_token;
				}
			} else {
				if (!got_month && !got_wday && token->next && is_numeric (token->next)) {
					d(printf ("mon; "));
					n = decode_int (token->start, token->len);
					got_month = TRUE;
					tm.tm_mon = n - 1;
					goto next_token;
				} else if (!tm.tm_mday && (n = get_mday (token->start, token->len)) != -1) {
					d(printf ("mday; "));
					tm.tm_mday = n;
					goto next_token;
				} else if (!tm.tm_year) {
					d(printf ("2-digit year; "));
					n = get_year (token->start, token->len);
					tm.tm_year = n - 1900;
					goto next_token;
				}
			}
		}

		d(printf ("???; "));

	next_token:

		token = token->next;
	}

	d(printf ("\n"));

	time = e_mktime_utc (&tm);

	/* time is now GMT of the time we want, but not offset by the timezone ... */

	/* this should convert the time to the GMT equiv time */
	time -= ((offset / 100) * 60 * 60) + (offset % 100) * 60;

	if (tzone)
		*tzone = offset;

	return time;
}
Пример #7
0
void another_hour(int mode) {
  char moon[20], buf[100];
  int tmp, i;

  time_info.hours++;

  tmp = time_info.hours;

  if (mode) {                   /* tick */

    /* as a test, save a piece of the world every mud hour */
    save_the_world();
    if (tmp == 0) {
      for (i = 0; i < 29; i++)  /* save the rest of the world automatically */
        save_the_world();
    }
    if (tmp == gMoonRise) {
      if (moontype < 4) {
        strcpy(moon, "new");
      }
      else if (moontype < 12) {
        strcpy(moon, "waxing");
      }
      else if (moontype < 20) {
        strcpy(moon, "full");
      }
      else if (moontype < 28) {
        strcpy(moon, "waning");
      }
      else {
        strcpy(moon, "new");
      }
      switch_light(MOON_RISE);
      SPRINTF(buf, "The %s moon slowly rises from the western horizon.\n\r",
              moon);
      send_to_outdoor(buf);
      if ((moontype > 16) && (moontype < 22)) {
        gLightLevel++;          /* brighter during these moons */
      }
    }
    if (tmp == gSunRise) {
      weather_info.sunlight = SUN_RISE;
      send_to_outdoor("The sun begins to rise from the western horizon.\n\r");
    }
    if (tmp == gSunRise + 1) {
      weather_info.sunlight = SUN_LIGHT;
      switch_light(SUN_LIGHT);
      send_to_outdoor("The day has begun.\n\r");
      global_sun_problem_check(TRUE);
    }
    if (tmp == gSunSet) {
      weather_info.sunlight = SUN_SET;
      send_to_outdoor
        ("The sun slowly disappears into the eastern horizon.\n\r");
    }
    if (tmp == gSunSet + 1) {
      weather_info.sunlight = SUN_DARK;
      switch_light(SUN_DARK);
      send_to_outdoor("Nightime has settled upon the realms.\n\r");
      global_sun_problem_check(FALSE);
    }
    if (tmp == gMoonSet) {
      if ((moontype > 15) && (moontype < 25)) {
        switch_light(MOON_SET);
        send_to_outdoor
          ("Darkness once again fills the realm as the moon sets.\n\r");
      }
      else {
        send_to_outdoor("The moon sets.\n\r");
      }

    }
    if (tmp == 12) {
      send_to_outdoor("It is noon.\n\r");
    }

    if (time_info.hours > 23) { /* Changed by HHS due to bug ??? */
      time_info.hours -= 24;
      time_info.day++;
      switch (time_info.day) {
      case 0:
      case 6:
      case 13:
      case 20:
      case 27:
      case 34:
        pulse_mobiles(EVENT_WEEK);
        break;
      }
      /* check the season */
      change_season(time_info.month);

      moontype++;
      if (moontype > 32)
        moontype = 1;

      if (time_info.day > 34) {
        time_info.day = 0;
        time_info.month++;
        get_month(time_info.month);
        pulse_mobiles(EVENT_MONTH);

        if (time_info.month > 16) {
          time_info.month = 0;
          time_info.year++;
        }
      }

      change_season(time_info.month);
    }
  }
}
Пример #8
0
char* create_HTTP_response_header(const char *filename, char buffer[])
{
	//printf("................\n");
	char* response_header = (char*) malloc(BUFFER_SIZE);
	int range_end;
	int range_start = 0;
	int content_length;
	char *ptr;
	char *lineRange = NULL;
	//char *lineModified = NULL;



	if(response_header == NULL)
	{
		error("Error allocating response_header");
	}
	char status_text[100] = "HTTP/1.1 %i Partial Content\r\n";
	char date_text[100] = "DATUM Funktion einbauen\r\n";
	char server_text[100] = "Server: TinyWeb (Build Jun 12 2014)\r\n";
	char accept_range_text[100] = "Accept-Ranges: bytes\r\n";
	char last_modified_text[100] = "Last-Modified: Thu, 12 Jun 2014\r\n";
	char content_type_text[100] = "Content-Type: text/html\r\n";
	char content_length_text[100] = "Content-Length: 1004\r\n";
	char content_range_text[100] = "Content-Range: bytes 6764-7767/7768\r\n";
	char connection_text[100] = "Connection: Close\r\n\r\n";

	//file length calculating
	struct stat buf;
	if(stat(filename, &buf) != 0)
	{
		printf("Error in file length calculating.\n");
	}

   	//set_http_status(HTTP_STATUS_PARTIAL_CONTENT);
   	time_t t;
   	struct tm *ts;

   	t = time(NULL);
   	ts = localtime(&t);

   	struct stat file_Info;





	sprintf(status_text, "HTTP/1.1 %i %s\r\n", http_status_list[get_http_status()].code, http_status_list[get_http_status()].text ); //TODO: status dynamisch uebergeben
	sprintf(date_text, "Date: %s, %i %s %i %02i:%02i:%02i GMT\r\n", get_weekday(ts->tm_wday), ts->tm_mday, get_month(ts->tm_mon), ts->tm_year + 1900, ts->tm_hour, ts->tm_min, ts->tm_sec); //TODO: Reutemann fragen ob das Format so passt
	//sprintf(server_text, "Server: TinyWeb (Build Jun 12 2014)", ); //TODO: Buildzeit dynamisch einfuegen


	ptr = strtok(NULL, "\n");
	while (ptr != NULL) {
		// extract line with the range if existing
		if (strncmp(ptr,"Range",5) == 0) {
			lineRange = ptr;
		}
		else if ((strncmp(ptr,"If-Modified-Since",strlen("If-Modified-Since"))) == 0) {
			//lineModified = ptr;
		}
		ptr = strtok(NULL, "\n");
	}

	if (lineRange != NULL) {
		char *range = malloc(strlen(lineRange)+1);
		if (range == NULL) {
			perror("Malloc():");
		}
		strtok(lineRange,"=");
		range = strtok(NULL,"="); // after "="
		range_start = atoi(strtok(range,"-"));
		range_end = atoi(strtok(NULL,"-"));

		//printf("Start: %i End: %i", range_start, range_end);
	}



		int check;
		check = stat(filename, &file_Info);

		if (check < 0) {
			printf("NOT FOUND ACCESS CHECK ");
			set_http_status(HTTP_STATUS_NOT_FOUND);
		}

	   	// get last modified
		char* last_modified = malloc(32);
	   	struct tm * timeinfo;
	   	timeinfo = localtime(&file_Info.st_mtim.tv_sec);

	   	strftime (last_modified,32,"%a, %d %b %Y %H:%M:%S %Z",timeinfo);

	sprintf(last_modified_text, "Last-Modified: %s\n", last_modified); //TODO: Dateidatum einfuegen
	sprintf(content_type_text, "Content-Type: %s\r\n",  get_http_content_type_str(get_http_content_type(filename)));



	range_end = file_Info.st_size;

	if(range_end < 0)
	{
		error("Error with range");
	}
	else
	{
		content_length = range_end - range_start;
	}

	sprintf(content_length_text, "Content-Length: %i\r\n", content_length);
	sprintf(content_range_text, "Content-Range: bytes %i-%i/%i\n", range_start, range_end, content_length ); //TODO: Frage was das ist und wie dynamisch abgefragt wird

	strcat(response_header, status_text);
	strcat(response_header, date_text);
	strcat(response_header, server_text);
	strcat(response_header, accept_range_text);
	strcat(response_header, last_modified_text);
	strcat(response_header, content_type_text);
	strcat(response_header, content_length_text);
	strcat(response_header, content_range_text);
	strcat(response_header, connection_text);
	printf("\n------------Response-----------------\n%s------------Response-----------------\n", response_header);

	return response_header;
}
Пример #9
0
int del_oldest_file_ext_fun()
{
	int i = 0;
	int j = 0;
	int ret = 0;
	int year = 0;
	int month = 0;
	int day = 0;
	int hour = 0;
	char dir_name[MAX_PATH];
	int  cur_year, cur_month, cur_day, cur_hour;
	int  disk_num;
	int  channel_num = get_av_channel_num();

	cur_year = get_year();		//获取当前时间-
	cur_month = get_month();	//获取当前时间-
	cur_day = get_day();		//获取当前时间-
	cur_hour = get_hour();

	do
	{
#ifdef SD_STORAGE
		
#endif

#if 1
		ret = get_oldest_time(&year, &month, &day, &hour);
		if (ret != 0)
		{
			del_file_status = -1;
			break;
		}
#endif		
		printf("the old time: %d %d %d %d\n", year, month, day, hour);
		//
		if (year < 1970 || year >2100 || month < 1 || month > 12 || day < 1 || day >31 || hour<0 || hour>=24)
		{
			del_file_status = -2;
			break;
		}
		/*
		//
		if (year == cur_year && month == cur_month && day == cur_day && hour == cur_hour)
		{
			del_file_status = -3;
			break;
		}
		*/

#ifdef SD_STORAGE
		for (j=0; j<channel_num; j++)
		{
			sprintf(dir_name,"/record/hd%02d/%02d/ch%02d/%04d-%02d-%02d/%02d",i,0,j,year,month,day,hour);
			//printf("Delete: %s\n", dir_name);
			delete_dir(dir_name);
		}
#else
		//
		disk_num = get_hard_disk_num();
		
		for (i=0; i<disk_num; i++)
		{
			//
			if (hd_get_mount_flag(i, 0) != 1)
			{
				continue;
			}

			//
			for (j=0; j<channel_num; j++)
			{
				sprintf(dir_name,"/record/hd%02d/%02d/ch%02d/%04d-%02d-%02d/%02d",i,0,j,year,month,day,hour);
				delete_dir(dir_name);
			}
		}
#endif
	}while(0);

	if (del_file_status == 1)
	{
		del_file_status = 0;
	}

	return 0;
}
Пример #10
0
void WidgetChatBubble::add_message(Line new_line) {
    auto msg_time = Glib::DateTime::create_now_utc(new_line.timestamp);
    // remove seconds
    msg_time = Glib::DateTime::create_utc(msg_time.get_year(),
                                          msg_time.get_month(),
                                          msg_time.get_day_of_month(),
                                          msg_time.get_hour(),
                                          msg_time.get_minute(),
                                          0);

    bool display_time = true;

    if (m_last_timestamp != 0) {
        auto old_time = Glib::DateTime::create_now_utc(m_last_timestamp);
        // remove seconds
        old_time = Glib::DateTime::create_utc(old_time.get_year(),
                                              old_time.get_month(),
                                              old_time.get_day_of_month(),
                                              old_time.get_hour(),
                                              old_time.get_minute(),
                                              0);
        // check
        display_time = !(msg_time.compare(old_time) == 0);
    }

    // create a new row
    auto msg  = Gtk::manage(new WidgetChatLabel());
    auto time = Gtk::manage(new Gtk::Label());
    m_last_timestamp = new_line.timestamp;

    // get local time
    msg_time = Glib::DateTime::create_now_local(m_last_timestamp);

    time->set_text(msg_time.format("%R"));
    msg->set_text(new_line.message);

    // add to grid
    if (m_side == RIGHT) {
        rows.emplace_back(m_grid, m_row_count, *msg, *time);
    } else {
        rows.emplace_back(m_grid, m_row_count, *time, *msg);
    }
    if (new_line.wait_for_receipt) {
        rows.back().set_class("message_pending");
        //callback !
        auto nr = new_line.nr;
        auto receipt = new_line.receipt;
        auto index = rows.size() - 1;
        rows.back().tox_callback = observer_add([this, index, nr, receipt](const ToxEvent &ev) {
            //wait for receipt
            if (ev.type() == typeid(Toxmm::EventReadReceipt)) {
                auto& row = rows[index];
                auto data = ev.get<Toxmm::EventReadReceipt>();
                if (data.nr == nr) {
                    if (data.receipt > receipt) {
                        //message failed !
                        row.set_class("message_failed");
                        row.tox_callback.reset();
                    } else if (data.receipt == receipt) {
                        //message got !
                        row.set_class("message_receipt");
                        row.tox_callback.reset();
                    }
                }
            }
        });
    }
    if (new_line.error) {
        rows.back().set_class("message_failed");
    }
    for(size_t i = 0; i < rows.size(); ++i) {
        rows[i].set_class(i == 0, i == rows.size()-1);
    }
    m_row_count += 1;

    // styling
    time->set_halign(Gtk::ALIGN_CENTER);
    time->set_valign(Gtk::ALIGN_START);
    time->get_style_context()->add_class("bubble_chat_line_time");

    msg->set_halign(Gtk::ALIGN_START);
    msg->set_valign(Gtk::ALIGN_CENTER);

    msg->show_all();
    time->show_all();
    time->set_no_show_all();
    if (!display_time) {
        time->hide();
    }
}
Пример #11
0
static int 
parse_unix(struct ftpparse *f, char *buf, int len, 
  char *p[], int l[], unsigned int count)
{

  /* the horror ... */

  /* this list has been taken from Daniel Bernsteins ftpparse.c */

  /* UNIX-style listing, without inum and without blocks */
  /* "-rw-r--r--   1 root     other        531 Jan 29 03:26 README" */
  /* "dr-xr-xr-x   2 root     other        512 Apr  8  1994 etc" */
  /* "dr-xr-xr-x   2 root     512 Apr  8  1994 etc" */
  /* "lrwxrwxrwx   1 root     other          7 Jan 25 00:17 bin -> usr/bin" */
  /* Also produced by Microsoft's FTP servers for Windows: */
  /* "----------   1 owner    group         1803128 Jul 10 10:18 ls-lR.Z" */
  /* "d---------   1 owner    group               0 May  9 19:45 Softlib" */
  /* Also WFTPD for MSDOS: */
  /* "-rwxrwxrwx   1 noone    nogroup      322 Aug 19  1996 message.ftp" */
  /* Also NetWare: */
  /* "d [R----F--] supervisor            512       Jan 16 18:53    login" */
  /* "- [R----F--] rhesus             214059       Oct 20 15:27    cx.exe" */
  /* Also NetPresenz for the Mac: */
  /* "-------r--         326  1391972  1392298 Nov 22  1995 MegaPhone.sit" */
  /* "drwxrwxr-x               folder        2 May 10  1996 network" */
  /*restructured: */
  /* -PERM   1    user  group  531      Jan  29      03:26  README           */
  /* dPERM   2    user  group  512      Apr  8       1994   etc              */
  /* dPERM   2    user  512    Apr      8    1994    etc                     */
  /* lPERM   1    user  group  7        Jan  25      00:17  bin -> usr/bin   */
  /* -PERM   1    user  group  1803128  Jul  10      10:18  ls-lR.Z          */
  /* dPERM   1    user  group  0        May  9       19:45  Softlib          */
  /* -PERM   1    user  group  322      Aug  19      1996   message.ftp      */
  /* d [R----F--] user  512    Jan      16   18:53   login                   */
  /* - [R----F--] user  214059 Oct      20   15:27   cx.exe                  */
  /* -PERM  326   NUMB  NUMBER Nov      22   1995    MegaPhone.sit           */
  /* dPERM  folder 2    May    10       1996 network                         */
  /* handled as: */
  /* dPERM  folder      2      May      10   1996    network                 */
  /* 0      1     2     3      4        5    6       7       8 */

  /* note the date system: MON DAY [YEAR|TIME] */


  int mon=-1; /* keep gcc quiet */
  unsigned long day;
  unsigned long year;
  unsigned long hour;
  unsigned long min;
  unsigned long sec;
  uint64 size;
  int flagtrycwd=0;
  int flagtryretr=0;
  unsigned int i;
  int x;
  int mtimetype;
  int may_have_size=0;

  switch(p[0][0]) {
  case 'd': flagtrycwd=1; break;
  case '-': flagtryretr=1; break;
  case 'l': flagtryretr=flagtrycwd=1; break;
  }
  i=3;
  if (l[1]==6 && my_byte_equal(p[1],l[1],"folder"))
    i=2;

  x=get_uint64(p[i],l[i],&size);
  if (x==l[i]) may_have_size=1;
  i++;

  while (i<count) {
    mon=get_month(p[i],l[i]);
    if (-1==mon) {
      /* may be size */
      x=get_uint64(p[i],l[i],&size);
      if (x==l[i]) may_have_size=1;
    }
    i++;
    if (-1!=mon) break;
  }
  if (i==count) return 0;

  x=get_ulong(p[i],l[i],&day);
  if (!x) return 0;
  if (p[i][x]!=' ') return 0;
  if (++i==count) return 0;

  x=get_ulong(p[i],l[i],&year);
  if (!x) return 0;
  if (p[i][x]==':') {
    x=scan_time(p[i],l[i],&hour,&min,&sec,&mtimetype);
    if (x!=l[i]) return 0;
    year=guess_year(mon,day);
  } else {
    mtimetype=FTPPARSE_MTIME_REMOTEDAY;
    hour=min=sec=0;
/* may be this case: */
/* - [-RWCE-F-] mlm                   11820 Feb  3 93 12:00  drivers.doc */
    if (i+2<count) {
      x=scan_time(p[i+1],l[i+1],&hour,&min,&sec,&mtimetype);
      if (x!=l[i+1]) {
	hour=min=sec=0;
	mtimetype=FTPPARSE_MTIME_REMOTEDAY;
      } else
	i++;
    }
    if (!fix_year(&year)) return 0;
  }
  if (++i==count) return 0;
  /* note: dosplit eats spaces - but we need them here. So go back. */
  f->name=p[i];
  f->namelen=buf+len-p[i];
  /* "-rwxrwxrwx   1 noone    nogroup      322 Aug 19  1996 message.ftp" */
  /* "-rwxrwxrwx   1 noone    nogroup      322 Aug 19  1996   spacy" */
  /* but: */
  /* "d [R----F--] supervisor            512       Jan 16 18:53    login" */
  if (p[0][1]!=' ') {
    while (f->name[-2]==' ') {
      f->name--;
      f->namelen++;
    }
  }
  if (may_have_size) {
    f->sizetype=FTPPARSE_SIZE_BINARY;
    f->size=size;
  }
  f->flagtryretr=flagtryretr;
  f->flagtrycwd=flagtrycwd;
  utcdate2tai (&f->mtime,year,mon,day,hour,min,sec);
  f->mtimetype=mtimetype;
  f->format=FTPPARSE_FORMAT_LS; /* for programs dealing with symlinks */

  if ('l'==*buf) {
    unsigned int j;
    for (j=1;j<f->namelen-4;j++) /* 1, -4: no empty names, please */
      if (f->name[j]==' '
       && f->name[j+1]=='-'
       && f->name[j+2]=='>'
       && f->name[j+3]==' ') {
	f->symlink=f->name+j+4;
	f->symlinklen=f->namelen-j-4;
	f->namelen=j;
	break;
      }
  }
  return 1;
}
Пример #12
0
static int parse_multinet(struct ftpparse *f, char *p[], int l[], 
  unsigned int count)
{
/* "CORE.DIR;1          1  8-SEP-1996 16:09 [SYSTEM] (RWE,RWE,RE,RE)" */
/* "[VMSSERV.FILES]ALARM.DIR;1      1/3          5-MAR-1993 18:09:" */
  int mon;
  unsigned long day;
  unsigned long year;
  unsigned long hour;
  unsigned long min;
  unsigned long sec;
  int mtimetype;
  int x;
  char *q;
  int m;
  if (count<4) return 0;

  q=p[2];
  m=l[2];

  x=get_ulong(q,m,&day);
  if (!x || x>2 || day>31) return 0;
  if (q[x] != '-') return 0;
  q+=x+1;
  m-=x+1;
  mon=get_month(q,m);
  if (-1==mon) return 0;
  if (q[3]!='-') return 0;
  q+=4;
  if (m<5) return 0;
  m-=4;
  x=get_ulong(q,m,&year);
  if (!x || q[x]!=' ') return 0;
  if (!fix_year(&year)) return 0;

  x=scan_time(p[3],l[3],&hour,&min,&sec,&mtimetype);
  if (x!=l[3]) return 0;

  f->mtimetype = mtimetype;;
  utcdate2tai (&f->mtime,year,mon,day,hour,min,sec);

  for (x=0;x<l[0];x++)
    if (p[0][x]==';')
      break;
  if (x>4) 
    if (p[0][x-4]=='.'
     && p[0][x-3]=='D'
     && p[0][x-2]=='I'
     && p[0][x-1]=='R') {
      x-=4;
      f->flagtrycwd=1;
    }
  if (!f->flagtrycwd)
    f->flagtryretr=1;

  f->namelen=x;
  f->name=p[0];
  if (f->name[0]=='[') {
    /* [dir]file.maybe */
    unsigned int y;
    for (y=1;y<f->namelen;y++)
      if (f->name[y]==']')
	break;
    if (y!=f->namelen) y++; /* skip ] */
    if (y!=f->namelen) {
      f->name+=y;
      f->namelen-=y;
    }
  }
  return 1;
}
Пример #13
0
// 0 for no, 1 for yes
int is_in_range(char * start_date_string, char * end_date_string, long * date_column, int * time_column) {
    
    int start_month = get_month(start_date_string);
    int start_day = get_day(start_date_string);
    int start_year = get_year(start_date_string);
    int start_hour = get_hour(start_date_string);
    int start_minute = get_minute(start_date_string);
    
    int end_month = get_month(end_date_string);
    int end_day = get_day(end_date_string);
    int end_year = get_year(end_date_string);
    int end_hour = get_hour(end_date_string);
    int end_minute = get_minute(end_date_string);
    
    int row_year = ((int)*date_column) / 10000;
    int row_month = ((int)*date_column) / 100;
    row_month = row_month % 100;
    int row_day =((int)*date_column) % 100;
    
    if (*time_column > 2359 || *time_column < 0) {
        return -1;
    }
    
    int row_hour = *time_column / 100;
    int row_minute = *time_column % 100;

    if (start_year > end_year) {
        return -1;
    }
    if (start_year == end_year && start_month > end_month) {
        return -1;
    }
    if (start_year == end_year && start_month == end_month && start_day > end_day) {
        return -1;
    }
    if (start_year == end_year && start_month == end_month && start_day == end_day && start_hour > end_hour) {
        return -1;
    }
    if (start_year == end_year && start_month == end_month && start_day == end_day && start_hour == end_hour && start_minute > end_minute) {
        return -1;
    }
    
    // check if measurement was taken after start time, if not return 0
    if (row_year >= start_year) {
        if (row_year == start_year) {
            if (row_month >= start_month) {
                if (row_month == start_month) {
                    if (row_day >= start_day) {
                        if (row_day == start_day) {
                            if (row_hour >= start_hour) {
                                if (row_hour == start_hour) {
                                    if (row_minute >= start_minute) {
                                    } else return 0;
                                }
                            } else return 0;
                        }
                    } else return 0;
                }
            } else return 0;
        }
    } else return 0;
    
    if (row_year <= end_year) {
        if (row_year == end_year) {
            if(row_month <= end_month) {
                if (row_month == end_month) {
                    if (row_day <= end_day) {
                        if (row_day == end_day) {
                            if (row_hour <= end_hour) {
                                if (row_hour == end_hour) {
                                    if (row_minute <= end_minute) {
                                    } else return 0;
                                }
                            } else return 0;
                        }
                    } else return 0;
                }
            } else return 0;
        }
    } else return 0;
    
    return 1;
}
Пример #14
0
int validate_avg_min_or_max(char * query) {
    char * command;
    command = (char *)calloc(11, sizeof(char));
    char * header;
    header = (char *)calloc(17, sizeof(char));
    char * header_word_2;
    header_word_2 = (char *)calloc(4, sizeof(char));
    char * header_word_3;
    header_word_3 = (char *)calloc(2, sizeof(char));
    char * start_date;
    start_date = (char *)calloc(17, sizeof(char));
    char * end_date;
    end_date = (char *)calloc(19, sizeof(char));
    
    // count whitespace in query to determine if header is multiple words
    int query_length = (int)strlen(query);
    int num_spaces = 0;
    for (int i=0; i<query_length; i++) {
        if (query[i] == ' ') {
            num_spaces++;
        }
    }
    if (num_spaces == 5) {
        sscanf(query, "%s %s %s %s %s %s", command, header, header_word_2, header_word_3, start_date, end_date);
        for (int i=0; i<40; i++) {
            if (header[i] == '\0') {
                header[i] = ' ';
                for (int k=0; k<40; k++) {
                    if (header_word_2[k] != '\0') {
                        header[i+k+1] = header_word_2[k];
                    } else {
                        header[i+k+1] = ' ';
                        header[i+k+2] = header_word_3 [0];
                        header[i+k+3] = '\0';
                        break;
                    }
                }
                break;
            }
        }
    } else if (num_spaces == 4) {
        sscanf(query, "%s %s %s %s %s", command, header, header_word_2, start_date, end_date);
        for (int i=0; i<40; i++) {
            if (header[i] == '\0') {
                header[i] = ' ';
                for (int k=0; k<40; k++) {
                    if (header_word_2[k] != '\0') {
                        header[i+k+1] = header_word_2[k];
                    } else {
                        break;
                    }
                }
                break;
            }
        }
    } else {
        sscanf(query, "%s %s %s %s", command, header, start_date, end_date);
    }
    
    // check if <header> is valid. Must contain numerical values only. Must be a string.
    Type_t data_type;
    data_type = column_type(header);
    if (data_type == UNKNOWN || data_type == STRING || data_type == CHAR) {
        printf("ERROR invalid query: %s\nreason: %s is not valid", query, header);
        return 0;
    }
    
    // check if <start date/time> and <end date/time> are valid. Must be mm/dd/yyyy-hh:mm eg: 02/22/1995-22:57
    if (strlen(start_date) != 16 || get_month(start_date) <= 0 || get_month(start_date) > 12 || get_day(start_date) <= 0 || get_day(start_date) > 31 || get_hour(start_date) < 0 || get_hour(start_date) > 23 || get_minute(start_date) < 0 || get_minute(start_date) > 59) {
        printf("ERROR invalid query: %s\nreason: %s is an invalid start date \n", query, start_date);
        return 0;
    }
    if (strlen(end_date) != 16 || get_month(end_date) <= 0 || get_month(end_date) > 12 || get_day(end_date) <= 0 || get_day(end_date) > 31 || get_hour(end_date) < 0 || get_hour(end_date) > 23 || get_minute(end_date) < 0 || get_minute(end_date) > 59) {
        printf("ERROR invalid query: %s\nreason: %s is an invalid end date \n", query, end_date);
        return 0;
    }
    
    return 1;
}
Пример #15
0
void write_to_logfile(struct sockaddr_in cli_addr, char *path_to_file_relativ, char buffer[], int read_count_bytes)
{
	FILE *f = fopen("logfile.txt", "a");
	if (f == NULL)
	{
	    printf("Error opening file!\n");
	    exit(1);
	}
   	time_t t;
   	struct tm *ts;

   	t = time(NULL);
   	ts = localtime(&t);

	char *p;
	struct sockaddr_in* pV4Addr = (struct sockaddr_in*)&cli_addr;
	struct in_addr ipAddr = pV4Addr->sin_addr;
	char str[INET_ADDRSTRLEN];
	inet_ntop( AF_INET, &ipAddr, str, INET_ADDRSTRLEN );
	p = strtok(buffer, " ");
	//printf("%s - - [%i/%s/%i:%02i:%02i:%02i +0200] \"%s %s\" %i %s %i\n", str, ts->tm_mday, get_month(ts->tm_mon), ts->tm_year + 1900, ts->tm_hour, ts->tm_min, ts->tm_sec, p, path_to_file_relativ, http_status_list[get_http_status()].code, http_status_list[get_http_status()].text, read_count_bytes);
	fprintf(f, "%s - - [%i/%s/%i:%02i:%02i:%02i +0200] \"%s %s\" %i %s %i\n", str, ts->tm_mday, get_month(ts->tm_mon), ts->tm_year + 1900, ts->tm_hour, ts->tm_min, ts->tm_sec, p, path_to_file_relativ, http_status_list[get_http_status()].code, http_status_list[get_http_status()].text, read_count_bytes);

}
Пример #16
0
        InputIterator get(
            iter_type b, iter_type e,
            std::ios_base& iob,
            std::ios_base::iostate& err,
            std::tm* tm,
            char fmt, char) const
        {
            err = std::ios_base::goodbit;
            const std::ctype<char_type>& ct = std::use_facet<std::ctype<char_type> >(iob.getloc());

            switch (fmt)
            {
            case 'a':
            case 'A':
              {
                std::tm tm2;
                std::memset(&tm2, 0, sizeof(std::tm));
                that_.get_weekday(b, e, iob, err, &tm2);
                //tm->tm_wday = tm2.tm_wday;
              }
              break;
            case 'b':
            case 'B':
            case 'h':
              {
                std::tm tm2;
                std::memset(&tm2, 0, sizeof(std::tm));
                that_.get_monthname(b, e, iob, err, &tm2);
                //tm->tm_mon = tm2.tm_mon;
              }
              break;
//            case 'c':
//              {
//                const string_type& fm = c();
//                b = get(b, e, iob, err, tm, fm.data(), fm.data() + fm.size());
//              }
//              break;
            case 'd':
            case 'e':
              get_day(tm->tm_mday, b, e, err, ct);
              break;
            case 'D':
              {
                const char_type fm[] = {'%', 'm', '/', '%', 'd', '/', '%', 'y'};
                b = get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0]));
              }
              break;
            case 'F':
              {
                const char_type fm[] = {'%', 'Y', '-', '%', 'm', '-', '%', 'd'};
                b = get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0]));
              }
              break;
            case 'H':
              get_hour(tm->tm_hour, b, e, err, ct);
              break;
            case 'I':
              get_12_hour(tm->tm_hour, b, e, err, ct);
              break;
            case 'j':
              get_day_year_num(tm->tm_yday, b, e, err, ct);
              break;
            case 'm':
              get_month(tm->tm_mon, b, e, err, ct);
              break;
            case 'M':
              get_minute(tm->tm_min, b, e, err, ct);
              break;
            case 'n':
            case 't':
              get_white_space(b, e, err, ct);
              break;
//            case 'p':
//              get_am_pm(tm->tm_hour, b, e, err, ct);
//              break;
            case 'r':
              {
                const char_type fm[] = {'%', 'I', ':', '%', 'M', ':', '%', 'S', ' ', '%', 'p'};
                b = get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0]));
              }
              break;
            case 'R':
              {
                const char_type fm[] = {'%', 'H', ':', '%', 'M'};
                b = get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0]));
              }
              break;
            case 'S':
              get_second(tm->tm_sec, b, e, err, ct);
              break;
            case 'T':
              {
                const char_type fm[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'};
                b = get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0]));
              }
              break;
            case 'w':
              {
                get_weekday(tm->tm_wday, b, e, err, ct);
              }
              break;
            case 'x':
              return that_.get_date(b, e, iob, err, tm);
//            case 'X':
//              return that_.get_time(b, e, iob, err, tm);
//              {
//                const string_type& fm = X();
//                b = that_.get(b, e, iob, err, tm, fm.data(), fm.data() + fm.size());
//              }
//              break;
//            case 'y':
//              get_year(tm->tm_year, b, e, err, ct);
                break;
            case 'Y':
              get_year4(tm->tm_year, b, e, err, ct);
              break;
            case '%':
              get_percent(b, e, err, ct);
              break;
            default:
                err |= std::ios_base::failbit;
            }
            return b;
        }
Пример #17
0
/******************************************************************************
* 函数名称:del_oldest_file_fun
* 功能描述:以天为单位删除最老的录像文件(线程实现函数)
*
*
*
* 修改记录:
* 其他说明:
********************************************************************************/
int del_oldest_file_fun()
{
	int  i,j;
	int  ret;
	int  year,month,day;
	char dir_name[MAX_PATH];
	int  cur_year, cur_month, cur_day;
	int  disk_num;
	int  channel_num = get_av_channel_num();

	cur_year   = get_year();	//获取当前时间-
	cur_month  = get_month();	//获取当前时间-
	cur_day    = get_day();		//获取当前时间-

	do
	{
		ret = get_oldest_date(&year, &month, &day);
		if (ret != 0)
		{
			printf("get_oldest_date: Failed!\n");
			del_file_status = -1;
			break;
		}

		//
		if (year < 1970 || year >2100 || month < 1 || month > 12 || day < 1 || day >31 )
		{
			del_file_status = -2;
			break;
		}

		//
		if (year == cur_year && month == cur_month && day == cur_day )
		{
			del_file_status = -3;
			break;
		}

#ifdef SD_STORAGE
		disk_num = 1;
#else
		//
		disk_num = get_hard_disk_num();
#endif
		
		for (i=0; i<disk_num; i++)
		{
#ifdef SD_STORAGE

#else
			//
			if (hd_get_mount_flag(i, 0) != 1)
			{
				continue;
			}
#endif

			//
			for (j=0; j<channel_num; j++)
			{
				sprintf(dir_name,"/record/hd%02d/%02d/ch%02d/%04d-%02d-%02d",i,0,j,year,month,day);
				printf("Delete the oldest file: %s\n", dir_name);
				delete_dir(dir_name);
			}
		}
	}while(0);

	if (del_file_status == 1)
	{
		del_file_status = 0;
	}

	//pthread_exit(NULL);

	return 0;
}