2 次代码提交 2182e72083 ... 0339d2052a

作者 SHA1 备注 提交日期
  NanashiNoGombe 0339d2052a strftime implementation on mingw doesn't support %T 1 年之前
  NanashiNoGombe 2f9b3e4008 --subject-to-lastmodify option accepts comma-separated list of target hosts 1 年之前
共有 4 个文件被更改,包括 25 次插入7 次删除
  1. 2 2
      BBS2chProxyBoardManager.cpp
  2. 4 1
      BBS2chProxyConnection.cpp
  3. 2 2
      BBS2chProxyHTML2Dat.cpp
  4. 17 2
      main.cpp

+ 2 - 2
BBS2chProxyBoardManager.cpp

@@ -162,7 +162,7 @@ end:
 	struct tm lastModified_tm = {};
 	char dateStr[256] = "";
 	localtime_r(&modifiedBase, &lastModified_tm);
-	strftime(dateStr, 256, "%Y/%m/%d(%a) %T", &lastModified_tm);
+	strftime(dateStr, 256, "%Y/%m/%d(%a) %H:%M:%S", &lastModified_tm);
 	json_object_set_string(rootMixed, "last_modify_string", dateStr);
 	json_object_set_number(rootMixed, "last_modify", modifiedBase);
 	json_object_set_string(rootMixed, "description", "");
@@ -256,7 +256,7 @@ std::string BBS2chProxyBoardManager::getBoardJSONForTalkAndFake5ch()
 	struct tm now_tm = {};
 	char nowStr[256];
 	localtime_r(&now, &now_tm);
-	strftime(nowStr, 256, "%Y/%m/%d(%a) %T", &now_tm);
+	strftime(nowStr, 256, "%Y/%m/%d(%a) %H:%M:%S", &now_tm);
 	if (!jsonTalk || !json5ch) goto end;
 	if (json_type(jsonTalk) != JSONObject || json_type(json5ch) != JSONObject ) {
 		goto end;

+ 4 - 1
BBS2chProxyConnection.cpp

@@ -62,6 +62,7 @@ extern int direct_dat;
 extern int fool_janestyle;
 extern int talk_to_5ch;
 extern int subject_to_lastmodify;
+extern std::set<std::string> subject_to_lastmodify_hosts;
 #ifdef USE_MITM
 extern unsigned int mitm_mode;
 #endif
@@ -694,7 +695,9 @@ beginHandleRequest:
 				statusCode = 404;
 			}
 		}
-		else if (subject_to_lastmodify && requestURL.isFamilyOf5chNet() && requestURL.pathEndsWith("/subject.txt") && requestURL.numberOfPathComponents() == 2) {
+		else if (((subject_to_lastmodify == 1 && requestURL.isFamilyOf5chNet()) ||
+			      (subject_to_lastmodify == 2 && subject_to_lastmodify_hosts.find(requestURL.getHost()) != subject_to_lastmodify_hosts.end())) &&
+			     requestURL.pathEndsWith("/subject.txt") && requestURL.numberOfPathComponents() == 2) {
 			log_printf(1, "Running as subject.txt to lastmodify.txt proxy...\n");
 			statusCode = subjectTxtProxy(requestURL, method, requestHeaders);
 		}

+ 2 - 2
BBS2chProxyHTML2Dat.cpp

@@ -1064,8 +1064,8 @@ std::string BBS2chProxyHTML2DatTalk::json2dat(JSON_Value *json, int startFrom, t
 			timestamp += 32400;
 			gmtime_r(&timestamp, &timestamp_tm);
 			strftime(dateStr, 256, "%Y/%m/%d(", &timestamp_tm);
-			line << dateStr << wdays[timestamp_tm.tm_wday];
-			strftime(dateStr, 256, ") %T", &timestamp_tm);
+			line << dateStr << wdays[timestamp_tm.tm_wday] << ") ";
+			strftime(dateStr, 256, "%H:%M:%S", &timestamp_tm);
 			line << dateStr;
 			if (id) {
 				line << " ID:" << id;

+ 17 - 2
main.cpp

@@ -2,6 +2,7 @@
 #include <vector>
 #include <map>
 #include <stack>
+#include <set>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -79,6 +80,7 @@ int direct_dat = 0;
 int fool_janestyle = 0;
 int talk_to_5ch = 0;
 int subject_to_lastmodify = 0;
+std::set<std::string> subject_to_lastmodify_hosts;
 static pthread_mutex_t lockarray[NUM_LOCKS];
 
 void log_printf(int level, const char *format ...)
@@ -379,7 +381,7 @@ int main(int argc, char *argv[])
 		{"fool-janestyle", 0, NULL, 0},
 		{"keystore", 1, NULL, 0},
 		{"talk-to-5ch", 0, NULL, 0},
-		{"subject-to-lastmodify", 0, NULL, 0},
+		{"subject-to-lastmodify", 2, NULL, 0},
 #ifdef USE_MITM
 		{"mitm", 1, NULL, 0},
 		{"mitm-ca-cert", 1, NULL, 0},
@@ -625,7 +627,20 @@ int main(int argc, char *argv[])
 					talk_to_5ch = 1;
 				}
 				else if(!strcmp(options[option_index].name, "subject-to-lastmodify")) {
-					subject_to_lastmodify = 1;
+					if (optarg) {
+						for (char *ptr = optarg; *ptr;) {
+							char *next = strchr(ptr, ',');
+							if (!next) {
+								subject_to_lastmodify_hosts.insert(std::string(ptr));
+								break;
+							} else {
+								if (next > ptr) subject_to_lastmodify_hosts.insert(std::string(ptr, next-ptr));
+								ptr = next + 1;
+							}
+						}
+						subject_to_lastmodify = 2;
+					}
+					else subject_to_lastmodify = 1;
 				}
 				break;
 			case 'p':