public static string MakeGccOptions(string[] macros, string[] includeDirs, string[] options, string[] libs) { List <string> o = new List <string>(); foreach (string macro in macros) { o.Add(string.Format("-D{0}", macro)); } foreach (string dir in includeDirs) { o.Add(string.Format("-I{0}", dir)); } foreach (string opt in options) { o.Add(opt); } if (libs != null) { o.Add("-L./"); foreach (string lib in libs) { o.Add(lib); } } return(Str.CombineStringArray(o.ToArray(), " ")); }
public static void DefaultSetDestinationsProc(DataVaultServerReceivedData data, DataVaultServerOptions options) { FileSystem fs = options.DestFileSystem; PathParser parser = fs.PathParser; string root = options.DestRootDirName; DataVaultData d = data.JsonData !; string timeStampStr; if (d.WithTime == false) { timeStampStr = Str.DateToStrShort(d.TimeStamp.LocalDateTime.Date); } else { timeStampStr = Str.DateTimeToStrShortWithMilliSecs(d.TimeStamp.LocalDateTime); } string relativePath = Str.CombineStringArray("/", d.SystemName, d.LogName, d.KeyType, d.KeyShortValue, d.KeyFullValue, $"{timeStampStr}-{d.SystemName}-{d.LogName}-{d.KeyType}-{d.KeyFullValue}.json"); if (d.WriteCompleteFlag ?? false) { relativePath += ".completed"; } data.AddDestinationFileName(parser.NormalizeDirectorySeparator(parser.Combine(root, relativePath))); }
public override string ToString() { string[] strs = new string[this.ValueList.Length]; int i; for (i = 0; i < this.ValueList.Length; i++) { strs[i] = this.ValueList[i].ToString(); } return(Str.CombineStringArray(strs, ", ")); }
// Generate Makefile for compilation public virtual StringWriter GenerateMakeFileForCompile(string outDir, bool debugMode, bool crossCompile) { string[] programNames = { "Ham", "vpnserver", "vpnbridge", "vpnclient", "vpncmd", }; string gccOptionForLinkDebug, gccOptionForLinkRelease; string gccOptionForCompileDebug, gccOptionForCompileRelease; generateGccOptions(outDir, false, crossCompile, out gccOptionForLinkRelease, out gccOptionForCompileRelease); generateGccOptions(outDir, true, crossCompile, out gccOptionForLinkDebug, out gccOptionForCompileDebug); StringWriter sr = new StringWriter(); #if !BU_SOFTETHER sr.WriteLine("# PacketiX VPN Source Code"); sr.WriteLine("# Copyright (c) SoftEther Corporation. All Rights Reserved."); #else sr.WriteLine("# SoftEther VPN Source Code"); sr.WriteLine("# Copyright (c) SoftEther VPN Project at University of Tsukuba, Japan. All Rights Reserved."); #endif sr.WriteLine("# Platform: {0}", this.CrossLibName); sr.WriteLine(); // Variable declaration sr.WriteLine("# Variables"); sr.WriteLine("CC={0}", this.Compiler); sr.WriteLine(); sr.WriteLine("OPTIONS_COMPILE_DEBUG={0}", gccOptionForCompileDebug); sr.WriteLine(); sr.WriteLine("OPTIONS_LINK_DEBUG={0}", gccOptionForLinkDebug); sr.WriteLine(); sr.WriteLine("OPTIONS_COMPILE_RELEASE={0}", gccOptionForCompileRelease); sr.WriteLine(); sr.WriteLine("OPTIONS_LINK_RELEASE={0}", gccOptionForLinkRelease); sr.WriteLine(); sr.WriteLine("ifeq ($(DEBUG),YES)"); sr.WriteLine("\tOPTIONS_COMPILE=$(OPTIONS_COMPILE_DEBUG)"); sr.WriteLine("\tOPTIONS_LINK=$(OPTIONS_LINK_DEBUG)"); sr.WriteLine("else"); sr.WriteLine("\tOPTIONS_COMPILE=$(OPTIONS_COMPILE_RELEASE)"); sr.WriteLine("\tOPTIONS_LINK=$(OPTIONS_LINK_RELEASE)"); sr.WriteLine("endif"); sr.WriteLine(); string[] mayaquaHeaders = generateFileList(Path.Combine(outDir, "Mayaqua"), outDir, "*.h"); string[] cedarHeaders = generateFileList(Path.Combine(outDir, "Cedar"), outDir, "*.h"); string[] mayaquaSrcs = generateFileList(Path.Combine(outDir, "Mayaqua"), outDir, "*.c"); string[] cedarSrcs = generateFileList(Path.Combine(outDir, "Cedar"), outDir, "*.c"); List <string> mayaquaObjs = new List <string>(); List <string> cedarObjs = new List <string>(); List <string> progSrcs = new List <string>(); List <string> progObjs = new List <string>(); List <string> progAs = new List <string>(); List <string> progBins = new List <string>(); foreach (string progName in programNames) { string progName2 = progName; if (progName2.Equals("vpnclient", StringComparison.InvariantCultureIgnoreCase) == false) { progSrcs.Add(string.Format("{0}/{0}.c", progName2)); } else { progSrcs.Add(string.Format("{0}/vpncsvc.c", progName2)); } progObjs.Add(string.Format("object/{0}.o", progName2)); progAs.Add(string.Format("code/{0}.a", progName)); progBins.Add(string.Format("bin/{0}", progName.ToLower())); } int i; for (i = 0; i < mayaquaSrcs.Length; i++) { mayaquaObjs.Add(string.Format("object/Mayaqua/{0}.o", Path.GetFileNameWithoutExtension(mayaquaSrcs[i]))); } for (i = 0; i < cedarSrcs.Length; i++) { cedarObjs.Add(string.Format("object/Cedar/{0}.o", Path.GetFileNameWithoutExtension(cedarSrcs[i]))); } sr.WriteLine("# Files"); sr.WriteLine("HEADERS_MAYAQUA={0}", Str.CombineStringArray(mayaquaHeaders, " ")); sr.WriteLine("HEADERS_CEDAR={0}", Str.CombineStringArray(cedarHeaders, " ")); sr.WriteLine("OBJECTS_MAYAQUA={0}", Str.CombineStringArray(mayaquaObjs.ToArray(), " ")); sr.WriteLine("OBJECTS_CEDAR={0}", Str.CombineStringArray(cedarObjs.ToArray(), " ")); sr.WriteLine(); // Behavior sr.WriteLine("# Build Action"); sr.WriteLine("default:\tbuild"); sr.WriteLine(); sr.WriteLine("build:\t$(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) {0}", Str.CombineStringArray(progBins.ToArray(), " ")); sr.WriteLine(); sr.WriteLine("# Mayaqua Kernel Code"); for (i = 0; i < mayaquaSrcs.Length; i++) { sr.WriteLine("{0}: {1} $(HEADERS_MAYAQUA)", mayaquaObjs[i], mayaquaSrcs[i]); if (i == 0) { sr.WriteLine("\t@mkdir -p object/"); sr.WriteLine("\t@mkdir -p object/Mayaqua/"); sr.WriteLine("\t@mkdir -p object/Cedar/"); sr.WriteLine("\t@mkdir -p code/"); } sr.WriteLine("\t$(CC) $(OPTIONS_COMPILE) -c {0} -o {1}", mayaquaSrcs[i], mayaquaObjs[i]); sr.WriteLine(); } sr.WriteLine("# Cedar Communication Module Code"); for (i = 0; i < cedarSrcs.Length; i++) { string line = string.Format("{0}: {1} $(HEADERS_MAYAQUA) $(HEADERS_CEDAR)", cedarObjs[i], cedarSrcs[i]); if (cedarSrcs[i].EndsWith("Bridge.c", StringComparison.InvariantCultureIgnoreCase)) { line += " Cedar/BridgeUnix.c"; } sr.WriteLine(line); sr.WriteLine("\t$(CC) $(OPTIONS_COMPILE) -c {0} -o {1}", cedarSrcs[i], cedarObjs[i]); sr.WriteLine(); } for (i = 0; i < programNames.Length; i++) { sr.WriteLine("# {0}", programNames[i]); sr.WriteLine("{0}: {1} $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)", progBins[i], progAs[i]); sr.WriteLine("\t$(CC) {0} $(OPTIONS_LINK) -o {1}", progAs[i], progBins[i]); sr.WriteLine(); sr.WriteLine("{0}: {1} $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)", progAs[i], progObjs[i]); sr.WriteLine("\trm -f {0}", progAs[i]); sr.WriteLine("\tar r {0} $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR) {1}", progAs[i], progObjs[i]); sr.WriteLine("\tranlib {0}", progAs[i]); sr.WriteLine(); sr.WriteLine("{0}: {1} $(HEADERS_MAYAQUA) $(HEADERS_CEDAR) $(OBJECTS_MAYAQUA) $(OBJECTS_CEDAR)", progObjs[i], progSrcs[i]); sr.WriteLine("\t$(CC) $(OPTIONS_COMPILE) -c {0} -o {1}", progSrcs[i], progObjs[i]); sr.WriteLine(); } sr.WriteLine("# Clean"); sr.WriteLine("clean:"); sr.WriteLine("\t-rm -f $(OBJECTS_MAYAQUA)"); sr.WriteLine("\t-rm -f $(OBJECTS_CEDAR)"); for (i = 0; i < programNames.Length; i++) { sr.WriteLine("\t-rm -f {0}", progObjs[i]); sr.WriteLine("\t-rm -f {0}", progAs[i]); sr.WriteLine("\t-rm -f {0}", progBins[i]); } sr.WriteLine(); sr.WriteLine("# Help Strings"); sr.WriteLine("help:"); sr.WriteLine("\t@echo \"make [DEBUG=YES]\""); sr.WriteLine(); return(sr); }
public async Task <string> Test7(string[] p) { return(Str.CombineStringArray(p, ",")); }
public async Task <string> Test3(int a, int b, int c) { //await TaskUtil.PreciseDelay(500); return(Str.CombineStringArray(",", a, b, c)); }
DnsMessageBase?processDnsQuery(DnsMessageBase message, IPAddress clientAddress) { try { bool is_fix_record = false; DnsMessage?q = message as DnsMessage; string? domainname = null; List <string> matchIPList = new List <string>(); if (q == null) { return(null); } if (hc.IsEmpty) { return(null); } q.IsQuery = false; q.ReturnCode = ReturnCode.ServerFailure; // 2022.8.18 dnsdist のキャッシュを効かせるためすべての AdditionalRecords を無視 if (Ini["CopyQueryAdditionalRecordsToResponse"].BoolValue == false) { q.AdditionalRecords.Clear(); } List <DnsRecordBase> answers = new List <DnsRecordBase>(); int num_match = 0; string queryDomainName = ""; foreach (DnsQuestion question in q.Questions) { q.ReturnCode = ReturnCode.NoError; string tmp; //Con.WriteLine("{0}: Query - {2} '{1}'", Str.DateTimeToStrShort(DateTime.Now), question.Name, question.RecordType); if (question.RecordType == RecordType.Ns) { bool b = false; foreach (string dom in ValidDomainNames) { string qname = question.Name.ToString(); if (qname.EndsWith(".")) { qname = qname.Substring(0, qname.Length - 1); } if (Str.StrCmpi(qname, dom)) { string[] keys = Ini.GetKeys(); int num_ns = 0; foreach (string key in keys) { if (key.StartsWith("NS", StringComparison.OrdinalIgnoreCase)) { string ns = Ini[key].StrValue; answers.Add(new NsRecord(DomainName.Parse(dom), (int)Ini["TtlFix"].IntValue, DomainName.Parse(ns))); num_ns++; } } if (num_ns == 0) { answers.Add(new NsRecord(DomainName.Parse(dom), (int)Ini["TtlFix"].IntValue, DomainName.Parse(Ini["PrimaryServer"].StrValue))); } num_match++; b = true; } if (qname.EndsWith(dom) && (Str.StrCmpi(qname, dom) == false)) { string[] keys = Ini.GetKeys(); //int num_ns = 0; q.IsAuthoritiveAnswer = true; q.AuthorityRecords.Add(new SoaRecord(DomainName.Parse(dom), (int)Ini["Ttl"].IntValue, DomainName.Parse(Ini["PrimaryServer"].StrValue), DomainName.Parse(Ini["EMail"].StrValue), DnsUtil.GenerateSoaSerialNumberFromDateTime(this.hc.LastHealthyTime), (int)Ini["Ttl"].IntValue, (int)Ini["Ttl"].IntValue, 88473600, (int)Ini["Ttl"].IntValue)); num_match++; /* if (num_ns == 0) * { * answers.Add(new NsRecord(dom, (int)Ini["TtlFix"].IntValue, Ini["PrimaryServer"].StrValue)); * } */ num_match++; b = true; } } if (b) { break; } } queryDomainName = question.Name.ToString(); List <IPAddress>?ret = nameToIpAddresses(queryDomainName, question.RecordType, out tmp, out is_fix_record); if (ret == null) { q.ReturnCode = ReturnCode.Refused; break; } else { if (Str.IsEmptyStr(tmp) == false) { domainname = tmp; } foreach (IPAddress addr in ret) { num_match++; int ttl = (int)Ini["Ttl"].IntValue; int ttl_fix = (int)Ini["TtlFix"].IntValue; if (is_fix_record) { ttl = ttl_fix; } if (addr.AddressFamily == AddressFamily.InterNetwork && (question.RecordType == RecordType.A || question.RecordType == RecordType.Any)) { answers.Add(new ARecord(question.Name, ttl, addr)); } else if (addr.AddressFamily == AddressFamily.InterNetworkV6 && (question.RecordType == RecordType.Aaaa || question.RecordType == RecordType.Any)) { answers.Add(new AaaaRecord(question.Name, ttl, addr)); } else if (question.RecordType == RecordType.Ns) { answers.Add(new NsRecord(DomainName.Parse(domainname), ttl_fix, DomainName.Parse(Ini["PrimaryServer"].StrValue))); } // ログ if (addr.AddressFamily == AddressFamily.InterNetwork || addr.AddressFamily == AddressFamily.InterNetworkV6) { matchIPList.Add(addr.ToString()); } } } } if (q.ReturnCode == ReturnCode.NoError) { if (num_match >= 1) { q.AnswerRecords = answers; q.IsAuthoritiveAnswer = true; } else { q.ReturnCode = ReturnCode.NxDomain; } if (Ini["SaveAccessLog"].BoolValue) { string logStr = string.Format("Query Domain={0} From={1} ", queryDomainName, clientAddress.ToString()); if (matchIPList.Count == 0) { logStr += "Result: Not Found"; } else { logStr += "Result: " + Str.CombineStringArray(matchIPList.ToArray(), " "); } write(logStr); } } // SOA if (Str.IsEmptyStr(domainname) == false) { q.IsAuthoritiveAnswer = true; q.AuthorityRecords.Add(new SoaRecord(DomainName.Parse(domainname), (int)Ini["Ttl"].IntValue, DomainName.Parse(Ini["PrimaryServer"].StrValue), DomainName.Parse(Ini["EMail"].StrValue), DnsUtil.GenerateSoaSerialNumberFromDateTime(this.hc.LastHealthyTime), (int)Ini["Ttl"].IntValue, (int)Ini["Ttl"].IntValue, 88473600, (int)Ini["Ttl"].IntValue)); } q.IsRecursionAllowed = false; return(q); } catch (Exception ex) { ex._Debug(); return(null); } }
public void WriteRecordToBuffer(LogInfoOptions opt, MemoryBuffer <byte> b) { if (opt.WriteAsJsonFormat && Dbg.IsJsonSupported) { // JSON text LogJsonData jc = new LogJsonData(); if (opt.WithTimeStamp) { jc.TimeStamp = this.TimeStamp; } if (opt.WithGuid) { jc.Guid = this.Guid; } if (opt.WithMachineName) { jc.MachineName = opt.MachineName; } if (opt.WithAppName) { jc.AppName = opt.AppName; } if (opt.WithKind) { jc.Kind = opt.Kind; } if (opt.WithPriority) { jc.Priority = this.Priority.ToString(); } if (opt.WithTag) { jc.Tag = this.Tag._FilledOrDefault(LogTag.None); } if (opt.WithTypeName) { jc.TypeName = this.Data?.GetType().Name ?? "null"; } jc.Data = this.Data; string jsonText = jc._GetObjectDump(jsonIfPossible: true); b.Write(jsonText._GetBytes_UTF8()); b.Write(CrLfByte); } else { // Normal text StringBuilder sb = new StringBuilder(); // Timestamp if (opt.WithTimeStamp) { sb.Append(this.TimeStamp._ToDtStr(true, DtStrOption.All, false)); sb.Append(" "); } // Additional strings List <string?> additionalList = new List <string?>(); if (opt.WithGuid) { additionalList.Add(this.Guid); } if (opt.WithMachineName) { additionalList.Add(opt.MachineName); } if (opt.WithAppName) { additionalList.Add(opt.AppName); } if (opt.WithKind) { additionalList.Add(opt.Kind); } if (opt.WithPriority) { additionalList.Add(this.Priority.ToString()); } if (opt.WithTag) { additionalList.Add(this.Tag._FilledOrDefault(LogTag.None)); } if (opt.WithTypeName) { additionalList.Add(this.Data?.GetType().Name ?? "null"); } string additionalStr = Str.CombineStringArray(" ", additionalList.ToArray()); if (additionalStr._IsFilled()) { sb.Append("["); sb.Append(additionalStr); sb.Append("] "); } // Log text string logText = GetMultilineText(GetTextFromData(this.Data, opt), opt); sb.Append(logText); sb.Append("\r\n"); b.Write(sb.ToString()._GetBytes_UTF8()); } }
public static string Combine(this string[] t, string sepstr) => Str.CombineStringArray(t, sepstr);