?? maillip.c
字號:
GET_DAY (date), months [month - 1], GET_CCYEAR (date), GET_HOUR (time), GET_MINUTE (time), GET_SECOND (time) ); return (buffer); } else return ("?"); } /****************************************************************************將時間(日期和時間)轉換成格林尼治標準時間,以兩個參數返回時間****************************************************************************/void local_to_gmt (long date, long time, long *gmt_date, long *gmt_time) { time_t time_value; time_value = date_to_timer (date, time); *gmt_date = timer_to_gmdate (time_value); *gmt_time = timer_to_gmtime (time_value); } /****************************************************************************將當地時間進行轉換成time_t格式(00:00:00 GMT Jan 1, 1970),如果輸入時間不正確則返回0****************************************************************************/time_t date_to_timer (long date, long time) { struct tm time_struct; time_t timer; time_struct.tm_sec = GET_SECOND (time); time_struct.tm_min = GET_MINUTE (time); time_struct.tm_hour = GET_HOUR (time); time_struct.tm_mday = GET_DAY (date); time_struct.tm_mon = GET_MONTH (date) - 1; time_struct.tm_year = GET_CCYEAR (date) - 1900; time_struct.tm_isdst = -1; timer = mktime (&time_struct); if (timer == -1) return (0); else return (timer); } /****************************************************************************將當地時間進行轉換,以ccyymmdd方式存儲,如果當地時間是0則返回0,如果當地時間超過范圍則返回(1 January, 1970 (19700101))****************************************************************************/long timer_to_date (time_t time_secs) { struct tm *time_struct; if (time_secs == 0) return (0); else { //轉換成CCYYMMDD格式 time_struct = localtime (&time_secs); if (time_struct) { time_struct-> tm_year += 1900; return (MAKE_DATE (time_struct-> tm_year / 100, time_struct-> tm_year % 100, time_struct-> tm_mon + 1, time_struct-> tm_mday)); } else return (19700101); } } /****************************************************************************將當地時間轉換成:hhmmssoo的格式并存儲,如果時間不夠1%秒則設置成0,如果當地時間是0或者非法則返回0****************************************************************************/long timer_to_time (time_t time_secs) { struct tm *time_struct; if (time_secs == 0) return (0); else { //轉換成:HHMMSS00 time_struct = localtime (&time_secs); if (time_struct) return (MAKE_TIME (time_struct-> tm_hour, time_struct-> tm_min, time_struct-> tm_sec, 0)); else return (0); } } /****************************************************************************將當地時間(提供的時間)轉換成格林尼治標準時間存儲,日期以:CCYYMMDD。如果當地時間是0則返回0,如果超過范圍則返回(1 January, 1970 (19700101))****************************************************************************/long timer_to_gmdate (time_t time_secs) { struct tm *time_struct; if (time_secs == 0) return (0); else { //轉換成:CCYYMMDD time_struct = gmtime (&time_secs); if (time_struct == NULL) //如果標準時間沒有實現 time_struct = localtime (&time_secs); if (time_struct) { time_struct-> tm_year += 1900; return (MAKE_DATE (time_struct-> tm_year / 100, time_struct-> tm_year % 100, time_struct-> tm_mon + 1, time_struct-> tm_mday)); } else return (19700101); //非法格式返回 } } /***************************************************************************轉換當地時間成格林尼治標準時間,時間以:HHMMSS00存儲,大多數系統都不能存儲1%秒,如果當地時間是0或者是非法的則返回0***************************************************************************/long timer_to_gmtime (time_t time_secs) { struct tm *time_struct; if (time_secs == 0) return (0); else { //轉換成:HHMMSS00 time_struct = gmtime (&time_secs); if (time_struct == NULL) //如果標準時間不實現 time_struct = localtime (&time_secs); if (time_struct) return (MAKE_TIME (time_struct-> tm_hour, time_struct-> tm_min, time_struct-> tm_sec, 0)); else return (0); } }/*************************************************************************返回時間(0是星期天),應用(Zeller's Congurence)算法*************************************************************************/int day_of_week (long date) { int year = GET_CCYEAR (date), month = GET_MONTH (date), day = GET_DAY (date); if (month > 2) month -= 2; else { month += 10; year--; } day = ((13 * month - 1) / 5) + day + (year % 100) + ((year % 100) / 4) + ((year / 100) / 4) - 2 * (year / 100) + 77; return (day - 7 * (day / 7)); } /****************************************************************************以hhmmsscc返回當前時間,如果系統時鐘不能返回1%秒則將其設為0****************************************************************************/long time_now (void) { struct timeval time_struct; gettimeofday (&time_struct, 0); return (timer_to_time (time_struct.tv_sec) + time_struct.tv_usec / 10000); } /************************************************************************** Synopsis: Returns the current date as a long value (CCYYMMDD). Since most system clocks do not return a century, this function assumes that all years 80 and above are in the 20th century, and all years 00 to 79 are in the 21st century. For best results, consume before 1 Jan 2080.**************************************************************************/long date_now (void) { return (timer_to_date (time (NULL))); } /******************************************************************************郵件信息的初始化******************************************************************************/void mail(unsigned char *dst,unsigned char *src,unsigned char tittle[30], \ unsigned char body[200],unsigned char attachment[200]) { unsigned int length; char tmpstr[255]; char value[20]; char mail_dst[255]; char mail_tittle[255]; char mail_src[255]; char mail_body[255]; char messageattachment[255]; length=strlen(attachment); strcpy(mail_dst,dst); strcpy(mail_tittle,tittle); strcpy(mail_src,src); strcpy(mail_body,body); strcpy(messageattachment,encode(attachment,length)); smtp_clear(&smtp); /* Subject Line --*/#ifdef CONFIG_NETtel search_config_file("/etc/config/config","ipeth0",value); strcat(tmpstr,value);#else strcpy(tmpstr,mail_tittle);#endif smtp.strSubject = tmpstr; /* Message--*/ smtp.strattachment =messageattachment; smtp.strMessageBody =mail_body; /* Sender Email --*/ strcpy(smtp.strSenderUserId,mail_src); smtp.strFullSenderUserId = ""; /*Destination */ smtp.strFullDestUserIds = ""; strcpy(smtp.strRplyPathUserId,mail_src); //this is who the return receipt goes back to smtp.strRrcptUserId = ""; //override the name of the mailing function with this field smtp.strMailerName = ""; //add a comment here if necessary smtp.strMsgComment = ""; //Desitination addresses smtp.strDestUserIds = smtp_fill_in_addresses(mail_dst); if (smtp.strDestUserIds == NULL) exit(-1); smtp.strSmtpServer = "192.168.0.102"; smtp_print(&smtp); smtp_send_mail(&smtp,1); free(smtp.strDestUserIds); printf("Finished.\n\r"); } /**************************************************************************** search_config_file - (ripped from cgi database.c) This function opens up the file specified 'filename' and searches through the file for 'keyword'. If 'keyword' is found any string following it is stored in 'value'.. If 'value' is NULL we assume the function was called simply to determing if the keyword exists in the file. args: filename (IN) - config filename keyword (IN) - word to search for in config file value (OUT) - value of keyword (if value not NULL) retn: -1 on error, 0 if keyword not found, 1 if found ****************************************************************************/int search_config_file(char *filename, char *keyword, char *value) { FILE *in; int len; char buffer[MAX_CONFIG_LINE_SIZE], w[MAX_CONFIG_LINE_SIZE], v[MAX_CONFIG_LINE_SIZE]; in = fopen(filename, "r"); if(in == NULL) { /* Couldn't find config file, or permission denied */ return -1; } while((fgets(buffer, MAX_CONFIG_LINE_SIZE - 1, in)) != NULL) { /* short-circuit comments */ if(buffer[0] == '#') continue; /* check if it's what we want */ if((sscanf(buffer, "%s %s", w, v) >= 1) \ && (strcmp(w, keyword) == 0)) { /* found it :-) */ if(value == NULL) { return 1; } else { strcpy(value, v); fclose(in); /* tell them we got it */ return 1; } } } fclose(in); return 0;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -