Beispiel #1
0
bool TEnv::GetIfArgPrefixBool(const TStr& PrefixStr,
                              const bool& DfVal,
                              const TStr& DNm) const {
    if (Env.GetArgs() <= MnArgs) {
        // 'usage' argument message
        if (!SilentP) {
            printf("   %s%s (default:'%s')\n",
                   PrefixStr.CStr(), DNm.CStr(),
                   TBool::GetStr(DfVal).CStr());
        }
        return DfVal;
    } else {
        // argument & value message
        bool Val;
        if ((PrefixStr.Len() > 0) &&
            (PrefixStr.LastCh() == ':')) {
            if (Env.IsArgPrefix(PrefixStr)) {
                // try to find one of boolean string value
                // representations
                TStr ValStr = Env.GetArgPostfix(PrefixStr);
                Val = TBool::GetValFromStr(ValStr, DfVal);
            } else {
                // remove ':' and try to find option
                TStr RedPrefixStr = PrefixStr;
                RedPrefixStr.DelSubStr(PrefixStr.Len() - 1,
                                       PrefixStr.Len() - 1);
                if (Env.IsArgPrefix(RedPrefixStr)) {
                    Val = true;
                } else {
                    Val = DfVal;
                }
            }
        } else {
            if (Env.IsArgPrefix(PrefixStr)) {
                Val = true;
            } else {
                Val = DfVal;
            }
        }
        TStr MsgStr = DNm + " (" + PrefixStr + ")=" +
                      TBool::GetYesNoStr(Val);
        if (!SilentP) {
            TNotify::OnStatus(Notify, MsgStr);
        }
        return Val;
    }
}
Beispiel #2
0
TEST(TStr, Del) {
	TStr Str = "aabbaabb";
	TStr Empty = "";
	
	TStr Test = Str;
	Test.DelChAll('a');
	EXPECT_EQ(Test, "bbbb");
	Test.DelChAll('c');
	EXPECT_EQ(Test, "bbbb");
	
	Test = Str;
	Test.DelSubStr(2, 3);
	EXPECT_EQ(Test, "aaaabb");
	
	Test.DelSubStr(0, 1);
	EXPECT_EQ(Test, "aabb");
	Test.DelSubStr(2, 3);
	EXPECT_EQ(Test, "aa");
	
	EXPECT_ANY_THROW(Test.DelSubStr(-1, 5));
	
	Test.DelSubStr(0, 1);
	EXPECT_EQ(Test, "");
	Test = Str;
	Test.DelSubStr(0, 0);
	EXPECT_EQ(Test, "abbaabb");
	

	Test = Str;
	EXPECT_TRUE(Test.DelStr("ab"));
	EXPECT_EQ(Test, "abaabb");
	EXPECT_FALSE(Test.DelStr("fs"));
	EXPECT_EQ(Test, "abaabb");

	Test = Str;
	EXPECT_EQ(2, Test.DelStrAll("ab"));
	EXPECT_EQ(Test, "abab");
}
void TMongSrv::OnHttpRq(const int& SockId, const PHttpRq& HttpRq) {
	// check http-request correctness - return if error
	if (!HttpRq->IsOk()) {
		TNotify::OnNotify(Notify, ntInfo, "Web-Server: Bad Http Request.");
		return;
	}
	// check url correctness - return if error
	PUrl RqUrl = HttpRq->GetUrl();
	if (!RqUrl->IsOk()) {
		TNotify::OnNotify(Notify, ntInfo, "Web-Server: Bad Url Requested.");
		return;
	}

	// construct http-response
	PHttpResp HttpResp;
	if (!RqUrl->GetPathStr().Empty()) {
		// get request-file-name
		TStr ExeFPath = TSysProc::GetExeFNm().GetFPath();
		TStr RqFNm = RqUrl->GetPathStr();
		if (RqFNm.LastCh() == '/') {
			RqFNm = RqFNm + "default.htm";
		}
		if ((RqFNm[0] == '/') || (RqFNm[0] == '\\')) {
			RqFNm.DelSubStr(0, 0);
		}
		RqFNm = ExeFPath + RqFNm;
		// open file
		bool RqFOpened = false;
		PSIn RqSIn = TFIn::New(RqFNm, RqFOpened);
		if (!RqFOpened) {
			// prepare default html with time
			TChA HtmlChA;
			HtmlChA += "<html><title>Error - Not Found</title><body>";
			HtmlChA += "File: ";
			HtmlChA += RqUrl->GetPathStr();
			HtmlChA += " not found.";
			HtmlChA += "</body></html>";
			PSIn BodySIn = TMIn::New(HtmlChA);
			HttpResp = PHttpResp(
					new THttpResp(THttp::ErrNotFoundStatusCd,
							THttp::TextHtmlFldVal, false, BodySIn, ""));
		} else {
			// file successfully opened
			PSIn BodySIn = RqSIn;
			if (THttp::IsHtmlFExt(RqFNm.GetFExt())) {
				// send text/html mime type if Html filemg_callback_t
				HttpResp = PHttpResp(
						new THttpResp(THttp::OkStatusCd, THttp::TextHtmlFldVal,
								false, BodySIn, ""));
			} else if (THttp::IsGifFExt(RqFNm.GetFExt())) {
				// send image/gif mime type if Gif file
				HttpResp = PHttpResp(
						new THttpResp(THttp::OkStatusCd, THttp::ImageGifFldVal,
								false, BodySIn, ""));
			} else {
				// send application/octet mime type
				HttpResp = PHttpResp(
						new THttpResp(THttp::OkStatusCd, THttp::AppOctetFldVal,
								false, BodySIn, ""));
			}
		}
	} else {
		// prepare default html with time
		TChA HtmlChA;
		HtmlChA += "<html><title>Welcome to TWebSrv (powered by mongoose 3.1)</title><body>";
		HtmlChA += TSecTm::GetCurTm().GetStr();
		HtmlChA += "</body></html>";
		PSIn BodySIn = TMIn::New(HtmlChA);
		HttpResp = THttpResp::New(THttp::OkStatusCd, THttp::TextHtmlFldVal,
				false, BodySIn);
	}

	// construct & send response
	SendHttpResp(SockId, HttpResp);
	// notify
	if (RqUrl->IsOk()) {
		TChA MsgChA;
		MsgChA += "Web-Server: Request for '";
		MsgChA += RqUrl->GetUrlStr();
		MsgChA += "'.";
		TNotify::OnNotify(Notify, ntInfo, MsgChA);
	}
}