Ejemplo n.º 1
0
void datetime::generateImpl
	(const generationContext& /* ctx */, utility::outputStream& os,
	 size_t curLinePos, size_t* newLinePos) const
{
	static const char* dayNames[] =
		{ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
	static const char* monthNames[] =
		{ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
		  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };

	int z = ((m_zone < 0) ? -m_zone : m_zone);
	int zh = z / 60;
	int zm = z % 60;

	std::ostringstream oss;
	oss.imbue(std::locale::classic());

	oss << dayNames[getWeekDay()] << ", "
	    << m_day << " " << monthNames[m_month - 1] << " " << m_year
	    << " " << std::setfill('0') << std::setw(2) << m_hour << ":"
	    << std::setfill('0') << std::setw(2) << m_minute << ":"
	    << std::setfill('0') << std::setw(2) << m_second
	    << " " << ((m_zone < 0) ? '-' : '+') << std::setfill('0') << std::setw(2) << zh
	    << std::setfill('0') << std::setw(2) << zm;

	const string& str = oss.str();
	os << str;

	if (newLinePos)
		*newLinePos = curLinePos + str.length();
}
Ejemplo n.º 2
0
/**
 * Form the date
 **/
char* setDate() {
	time_t t = time(0);   // get time now
	struct tm * now = localtime(&t);
	char* result = malloc(sizeof(char) * 40 + 1);
	result[40] = '\0';
	// this is not the best possible solution (i can use direclty time.h to format the result)
	char* wday = getWeekDay(now->tm_wday);
	char* month = getMonthName(now->tm_mon + 1);
	sprintf(result, "Date: %s, %d %s %d %d:%d:%d GMT\r\n", wday, now->tm_mday,
			month, now->tm_year + 1900, now->tm_hour, now->tm_min, now->tm_sec);
	return result;
}
Ejemplo n.º 3
0
main()
{
  int year;     /* 西暦 */
  int month;    /* 月   */
  int days;     /* 月の日数 */
  int youbi;    /* 最初の日の曜日番号 */

  getYearMonth(&year, &month);
  days = getMonthDays(year, month);
  youbi = getWeekDay(year, month, 1);
  printf("西暦%d年 %d月\n", year, month);
  PrintCalendar(days, youbi);
}
Ejemplo n.º 4
0
/**
 * Form Last Modified
 **/
char* setModified(struct fileInfo informator) {
	struct stat b;
	char* inf = malloc(sizeof(char) * 100);
	if (!stat(informator.filename, &b)) {
		struct tm *timenfo = localtime(&b.st_mtime);
		char* wday = getWeekDay(timenfo->tm_wday);
		char* month = getMonthName(timenfo->tm_mon + 1);
		sprintf(inf, "Last-Modified: %s, %d %s %d %d:%d:%d GMT \r\n\0", wday,
				timenfo->tm_mday, month, timenfo->tm_year + 1900,
				timenfo->tm_hour, timenfo->tm_min, timenfo->tm_sec);
	}
	return inf;
}
Ejemplo n.º 5
0
/*****************************************************
**
**   HoraExpert   ---   update
**
******************************************************/
void HoraExpert::update( const double &jd )
{
	const ObjectId lordseq[7] = { OSATURN, OJUPITER, OMARS, OSUN, OVENUS, OMERCURY, OMOON };
	const ObjectId rev_lordseq[7] = { OVENUS, OSATURN, OMERCURY, OJUPITER, OMOON, OMARS, OSUN };

	Calculator *calculator = CalculatorFactory().getCalculator();
	DateTimeFormatter *formatter = DateTimeFormatter::get();

	int i, weekday, day, month, year;

	double sunrise = calculator->calcNextSolarEvent( SOLAR_EVENT_SUNRISE, jd, location->getLatitude(), location->getLongitude());
	double sunset = calculator->calcNextSolarEvent( SOLAR_EVENT_SUNSET, sunrise, location->getLatitude(), location->getLongitude());
	double sunrise_next = calculator->calcNextSolarEvent( SOLAR_EVENT_SUNRISE, sunset, location->getLatitude(), location->getLongitude());

	weekday = getWeekDay( sunrise );
	dinaLord = lordseq[ ( rev_lordseq[weekday] ) % 7 ];



#ifdef HORA_DEB
	wxString s;
	printf( "##################  DEBUG ######################\n" );
	location->dump( s );
	s = formatter->getFullDateStringFromJD( jd );
	printf( "full date: %s\n", str2char( s ));
	printf( "jd: %s\n", str2char( formatter->getFullDateStringFromJD( jd )));
	printf( "sunrise: %s\n", str2char( formatter->getFullDateStringFromJD( sunrise )));
	printf( "sunset: %s\n", str2char( formatter->getFullDateStringFromJD( sunset )));
	printf( "sunrise NEXT: %s\n", str2char( formatter->getFullDateStringFromJD( sunrise_next )));
	printf( "WEEKDAY %d\n", weekday );
	printf( "dinalord %d\n", dinaLord );
	printf( "##################  END DEBUG  ######################\n" );
#endif

	for ( i = 0; i < 24; i++ )
	{
		horaLord[i] = lordseq[ ( rev_lordseq[weekday] + i ) % 7 ];
	}

	double daydur = sunset - sunrise;
	double daystep = daydur / 12;

	double nightdur = sunrise_next - sunset;
	double nightstep = nightdur / 12;

	currentHoraLord = horaLord[0];
	horaStart[24] = sunrise_next;

	for ( i = 0; i < 12; i++ )
	{
		horaStart[i] = sunrise + i * daystep;
		if ( horaStart[i] < jd ) currentHoraLord = horaLord[i];
	}
	for ( i = 0; i < 12; i++ )
	{
		horaStart[i+12] = sunset + i * nightstep;
		if ( horaStart[i+12] < jd ) currentHoraLord = horaLord[i+12];
	}

	// calculate lords of month and year
	formatter->calculateDateIntegers( sunrise, day, month, year );

	// lord of 1st day of year
	weekday = getWeekDay( calculator->calc_jd( year, 1, 1, 12 ));
	varshaLord = lordseq[ ( rev_lordseq[weekday] ) % 7 ];

	// lord of 1st day ov month
	weekday = getWeekDay( calculator->calc_jd( year, month, 1, 12 ));
	masaLord = lordseq[ ( rev_lordseq[weekday] ) % 7 ];
}
Ejemplo n.º 6
0
int main(int argc, char* argv[]){
	//FILE* fp;
	struct sockaddr_in serv_addr;
	int server_fd;
	int req, nreq, resp, nresp;
	char user[STR_MAX], date[12],day[4];
	int len, nlen, rlen, slen;

	if(argc != 3){
		fprintf(stderr, "Argument error : %s user date\n", argv[0]);
		exit(1);
	}
	strcpy(user, argv[1]);
	strcpy(date, argv[2]);
	//strcpy(filename, argv[3]);

	set_env();

	getWeekDay(date, day);

	memset((char*)&serv_addr, '\0', sizeof(serv_addr));
	serv_addr.sin_family = AF_INET;
	serv_addr.sin_port = htons(PORT);
	serv_addr.sin_addr.s_addr = inet_addr(SERVER_IP);
#if DEBUG
	printf("user : %s, date : %s, filename : %s\n", user, date, filename);
#endif

	if((server_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0){
		perror("socket");
		exit(1);
	}

	if(connect(server_fd, (struct sockaddr*) &serv_addr, sizeof(serv_addr)) < 0){
		perror("connect");
		exit(1);
	}

	/**********************************************
	**	send request
	**********************************************/

	req = BACKUP_COMPLETE_REQUEST;
	nreq = htonl(req);
	if((slen = send(server_fd, &nreq, sizeof(nreq), 0)) < 0){
		perror("send req | send : ");
		exit(1);
	}

	/***********************************************
	** send user
	***********************************************/
	
	len = strlen(user) + 1;
	nlen = htonl(len);
	if((slen = send(server_fd, &nlen, sizeof(nlen), 0)) < 0){
		perror("send user's len | send : ");
		exit(1);
	}

	if((slen = send(server_fd, user, len, 0)) < 0){
		perror("send user | send : ");
		exit(1);
	}

	if((rlen = recv(server_fd, &nresp, sizeof(nresp), 0)) < 0){
		perror("get resp | recv : ");
		exit(1);
	}

	resp = ntohl(nresp);

	/***********************************************
	** if the user is valid, then
	***********************************************/
	if(resp){
		//set rec directory
		//remove_create_dir(REC_DIR);

		//set rec.list
		/*
		if( (rfp = fopen(REC_LIST_PATH, "w")) == NULL){
			perror("rec list open fail | open : ");
			exit(1);
		}*/

		/*******************************************
		** send date, filename
		********************************************/

		//send date length
		len = strlen(date) + 1;
		nlen = htonl(len);
		if((slen = send(server_fd, &nlen, sizeof(nlen), 0)) < 0){
			perror("send date's len | send : ");
			exit(1);
		}
		//send date
		if((slen = send(server_fd, date, len, 0)) < 0){
			perror("send date | send : ");
			exit(1);
		}

	}

	/*************************************************
	**	if user is invalid or the work is done, then
	*************************************************/
	if(server_fd) close(server_fd);
	//if(fp) fclose(fp);
	//if(rfp) fclose(rfp);
	return 0;
}
Ejemplo n.º 7
0
//@see Design-page 9
void handle_recovery_req(int sd, char* clientIP){
	char buf[RBUFMAX];
	char log_buf[STR_MAX];
	char user[STR_MAX];
	char filename[STR_MAX];
	char filepath[STR_MAX];
	char backup_dir_path[STR_MAX];
	char day[4];
	char date[12];
	char date_list[8][12];
	unsigned int d_list_idx;
	unsigned int i;
	//char cmd[STR_MAX];
	int response, len, fid;
	const int endQ = -1;
	int Q, tlen, tresp;

	tlen = 0;
	logger(SVR, "RECOVERY REQUEST START");
	
	read(sd, &len, sizeof(len));
	len = ntohl(len);//
	read(sd, user, len);
	
	response = isMatch(user, clientIP);
	tresp = htonl(response);//
	write(sd, &tresp, sizeof(tresp));//

	sprintf(backup_dir_path, "%s/%s", BACKUP_DIR, user);
	logger(SVR, "set path");

	if(response){
		//get file
		read(sd, &len, sizeof(len));
		len = ntohl(len);//
		read(sd, date, len);
		printf("%d %s\n", len, date);
		
		d_list_idx = 0;
		d_list_idx = getDateList(date, date_list);
		
		for(i = 0; i <= d_list_idx; i++){
			getWeekDay(date_list[i], day);
			sprintf(filename, "%s.tgz", date_list[i]);
			sprintf(filepath, "%s/%s/%s", backup_dir_path, day, filename);
			
			if( (fid = open(filepath, O_RDONLY)) < 0){
				sprintf(log_buf, "There is no File : %s\n", filepath);
				logger(SVR, log_buf);
				continue;
			}

			//transmit file if it exist

			len = strlen(filename) + 1;
			tlen = htonl(len);//
#if DEBUG
			printf("%d %d %s\n", len, tlen, filename);
#endif
			write(sd, &tlen, sizeof(tlen));
			write(sd, filename, len);

			while( (len = read(fid, buf, sizeof(buf))) > 0 ){
#if DEBUG
				printf("%d %d %d\n", len, htonl(len), sizeof(buf));
#endif
				tlen = htonl(len);//
				write(sd, &tlen, sizeof(tlen));
				write(sd, buf, len);
			}

			printf("%d %d\n", endQ, htonl(endQ));
			Q = htonl(endQ);
			write(sd, &Q, sizeof(Q));

			if(fid) close(fid);

		}
		Q = htonl(endQ);
		write(sd, &Q, sizeof(Q));		
	}
	
	logger(SVR, "RECOVERY REQUEST END");
	if(sd) close(sd);
	exit(1);

}