📄 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 + -