bool CzAds::ExtractLinkAndImageFromtHTML(CzAd& ad, CzString& html) { int pos, offset; // Check to see if the html has a clickable link html.FindReset(); pos = html.FindNext("href="); if (pos > 0) { // Get the click link int idx = html.getFindIndex(); int len = html.GetNextMarkedString('"', '"', offset); if (len < 0) { html.setFindIndex(idx); len = html.GetNextMarkedString('\'', '\'', offset); } if (len > 0) { ad.LinkURI.setString(html.getString() + offset, len); #if defined(_DEBUG) CzDebug::Log(CZ_DEBUG_CHANNEL_INFO, "Ad Link URL: ", ad.LinkURI.c_str()); #endif // _DEBUG // Check to see if the html has an image available pos = html.FindNext("img "); if (pos > 0) { // Grab the image url pos = html.FindNext("src="); if (pos > 0) { idx = html.getFindIndex(); len = html.GetNextMarkedString('"', '"', offset); if (len < 0) { html.setFindIndex(idx); len = html.GetNextMarkedString('\'', '\'', offset); } if (len > 0) { ad.ImageURI.setString(html.getString() + offset, len); #if defined(_DEBUG) CzDebug::Log(CZ_DEBUG_CHANNEL_INFO, "Ad Image URL: ", ad.ImageURI.c_str()); #endif // _DEBUG return true; } } } } } return false; }
bool CzAds::ExtractAdAdModa(CzAd& ad, CzString& ad_body) { int len, offset; ad.isHtml = false; ad.isText = false; ad.ImageURI = ""; ad.LinkURI = ""; ad.Text = ""; ad.AdTime = PLATFORM_SYS->getTimeInMs(); ad_body.FindReset(); // Get Ad image len = ad_body.GetNextMarkedString('|', '|', offset); if (len > 0) { ad.ImageURI.setString(ad_body.getString() + offset, len); #if defined(_DEBUG) CzDebug::Log(CZ_DEBUG_CHANNEL_INFO, "Ad Image: ", ad.ImageURI.c_str()); #endif // _DEBUG } ad_body.StepFindIndex(-1); // Get Ad link len = ad_body.GetNextMarkedString('|', '|', offset); if (len > 1) { ad.LinkURI.setString(ad_body.getString() + offset, len - 1); #if defined(_DEBUG) CzDebug::Log(CZ_DEBUG_CHANNEL_INFO, "Ad Click URL: ", ad.LinkURI.c_str()); #endif // _DEBUG } if (ad.ImageURI.isEmpty() || ad.LinkURI.isEmpty()) return false; return true; }
bool CzAds::ExtractAdMobFox(CzAd& ad, CzString& ad_body) { // We dont use a full on XML parser to parse the returned XML, instead we just search for the required info int pos, offset, len; ad.isHtml = false; ad.isText = false; ad.ImageURI = ""; ad.LinkURI = ""; ad.Text = ""; ad.AdTime = PLATFORM_SYS->getTimeInMs(); // Get Error Response ad_body.FindReset(); pos = ad_body.FindNext("<request type="); if (pos >= 0) { len = ad_body.GetNextMarkedString('"', '"', offset); if (len > 0) { ErrorString.setString(ad_body.getString() + offset, len); if (ErrorString == "noAd") { Error = ErrorNoAd; return false; } else Error = ErrorNone; if (ErrorString == "textAd") { ad.isHtml = true; ad.isText = true; } } } // Get Ad text pos = ad_body.FindNext("<htmlString>"); if (pos >= 0) { // Find closeing tag int end_pos = ad_body.FindNext("</htmlString>"); if (end_pos > 0) { ad.Text.setString(ad_body.getString() + pos, end_pos - pos); ad.Text.ReplaceHTMLCodes(); #if defined(_DEBUG) CzDebug::Log(CZ_DEBUG_CHANNEL_INFO, "Ad Text: ", ad.Text.c_str()); #endif // _DEBUG } // If we can successfully extract the link and banner information from the text ad then unmark the ad as html/text if (ExtractLinkAndImageFromtHTML(ad, ad.Text)) { ad.isHtml = false; ad.isText = false; return true; } } else ad_body.FindReset(); // Get Ad link pos = ad_body.FindNext("<clickurl"); if (pos >= 0) { len = ad_body.GetNextMarkedString('>', '<', offset); if (len > 0) { ad.LinkURI.setString(ad_body.getString() + offset, len); #if defined(_DEBUG) CzDebug::Log(CZ_DEBUG_CHANNEL_INFO, "Ad Click URL: ", ad.LinkURI.c_str()); #endif // _DEBUG } } // Get Ad image pos = ad_body.FindNext("<imageurl"); if (pos >= 0) { len = ad_body.GetNextMarkedString('>', '<', offset); if (len > 0) { ad.ImageURI.setString(ad_body.getString() + offset, len); #if defined(_DEBUG) CzDebug::Log(CZ_DEBUG_CHANNEL_INFO, "Ad Image URL: ", ad.ImageURI.c_str()); #endif // _DEBUG } } return true; }
bool CzAds::ExtractAdInnerActive(CzAd& ad, CzString& ad_body) { // We dont use a full on XML parser to parse the returned XML, instead we just search for the required info int pos, offset, len; ad.isHtml = HtmlAds; ad.isText = false; ad.ImageURI = ""; ad.LinkURI = ""; ad.Text = ""; ad.AdTime = PLATFORM_SYS->getTimeInMs(); // Get Error Response ad_body.FindReset(); pos = ad_body.FindNext("<tns:Response Error="); if (pos >= 0) { len = ad_body.GetNextMarkedString('"', '"', offset); if (len > 0) { ErrorFromResponse(ad_body.getString() + offset, len); #if defined(_DEBUG) CzDebug::Log(CZ_DEBUG_CHANNEL_INFO, "Response: ", ErrorString.c_str()); #endif // _DEBUG } } // Get Client ID (we store this for future ad requests during the same session) pos = ad_body.FindNext("<tns:Client Id="); if (pos >= 0) { len = ad_body.GetNextMarkedString('"', '"', offset); if (len > 0) { ClientID.setString(ad_body.getString() + offset, len); #if defined(_DEBUG) CzDebug::Log(CZ_DEBUG_CHANNEL_INFO, "Client ID: ", ClientID.c_str()); #endif // _DEBUG } } // Get Ad text pos = ad_body.FindNext("<tns:Text"); if (pos >= 0) { len = ad_body.GetNextMarkedString('>', '<', offset); if (len > 0) { ad.Text.setString(ad_body.getString() + offset, len); #if defined(_DEBUG) CzDebug::Log(CZ_DEBUG_CHANNEL_INFO, "Ad Text: ", ad.Text.c_str()); #endif // _DEBUG } } // Get Ad link pos = ad_body.FindNext("<tns:URL"); if (pos >= 0) { len = ad_body.GetNextMarkedString('>', '<', offset); if (len > 0) { ad.LinkURI.setString(ad_body.getString() + offset, len); #if defined(_DEBUG) CzDebug::Log(CZ_DEBUG_CHANNEL_INFO, "Ad Click URL: ", ad.LinkURI.c_str()); #endif // _DEBUG } } // Get Ad image pos = ad_body.FindNext("<tns:Image"); if (pos >= 0) { len = ad_body.GetNextMarkedString('>', '<', offset); if (len > 0) { ad.ImageURI.setString(ad_body.getString() + offset, len); #if defined(_DEBUG) CzDebug::Log(CZ_DEBUG_CHANNEL_INFO, "Ad Image URL: ", ad.ImageURI.c_str()); #endif // _DEBUG } } return true; }
bool CzAds::ExtractAdKomliMobile(CzAd& ad, CzString& ad_body) { return false; // We dont use a full on XML parser to parse the returned XML, instead we just search for the required info int pos; ad.isHtml = false; ad.isText = false; ad.ImageURI = ""; ad.LinkURI = ""; ad.Text = ""; ad.AdTime = PLATFORM_SYS->getTimeInMs(); ad_body.FindReset(); // Find render section if (ad_body.FindNext("\"action\"") < 0) { return false; } // Find click URL pos = ad_body.GetNextMarkedStringAfterString("\"data\"", '"', '"', ad.LinkURI); if (pos >= 0) { #if defined(_DEBUG) CzDebug::Log(CZ_DEBUG_CHANNEL_INFO, "Ad Click URL: ", ad.LinkURI.c_str()); #endif // _DEBUG } else return false; // Find render section if (ad_body.FindNext("\"render\"") < 0) { return false; } // Find Image URL pos = ad_body.GetNextMarkedStringAfterString("\"data\"", '"', '"', ad.ImageURI); if (pos > 0) { #if defined(_DEBUG) CzDebug::Log(CZ_DEBUG_CHANNEL_INFO, "Ad Image URL: ", ad.ImageURI.c_str()); #endif // _DEBUG } else return false; /* // Find click URL pos = ad_body.GetNextMarkedStringAfterString("\"notify\"", '"', '"', ad.LinkURI); if (pos >= 0) { #if defined(_DEBUG) CzDebug::Log(CZ_DEBUG_CHANNEL_INFO, "Ad Click URL: ", ad.LinkURI.c_str()); #endif // _DEBUG } else return false;(*/ return true; }
bool CzAds::ExtractAdAdFonic(CzAd& ad, CzString& ad_body) { // We dont use a full on XML parser to parse the returned XML, instead we just search for the required info int pos, offset, len; ad.isHtml = false; ad.isText = false; ad.ImageURI = ""; ad.LinkURI = ""; ad.Text = ""; ad.AdTime = PLATFORM_SYS->getTimeInMs(); // Get Error Response ad_body.FindReset(); pos = ad_body.FindNext("<status"); if (pos >= 0) { len = ad_body.GetNextMarkedString('>', '<', offset); if (len > 0) { ErrorString.setString(ad_body.getString() + offset, len); if (ErrorString == "error") { Error = ErrorInternalError; return false; } else Error = ErrorNone; } } // Get Ad format pos = ad_body.FindNext("<format"); if (pos >= 0) { len = ad_body.GetNextMarkedString('>', '<', offset); if (len > 0) { CzString format; format.setString(ad_body.getString() + offset, len); if (format == "banner") ad.isText = false; else ad.isText = true; #if defined(_DEBUG) CzDebug::Log(CZ_DEBUG_CHANNEL_INFO, "Ad Format: ", ad.Text.c_str()); #endif // _DEBUG } } // Get Ad text pos = ad_body.FindNext("<![CDATA["); if (pos >= 0) { int end_pos = ad_body.FindNext("]]>"); if (end_pos > 0) { ad.Text.setString(ad_body.getString() + pos + 9, end_pos - pos - 9); #if defined(_DEBUG) CzDebug::Log(CZ_DEBUG_CHANNEL_INFO, "Ad Text: ", ad.Text.c_str()); #endif // _DEBUG ad.isHtml = true; } } ad_body.FindReset(); // Get Ad link pos = ad_body.FindNext("url="); if (pos >= 0) { len = ad_body.GetNextMarkedString('"', '"', offset); if (len > 0) { ad.LinkURI.setString(ad_body.getString() + offset, len); #if defined(_DEBUG) CzDebug::Log(CZ_DEBUG_CHANNEL_INFO, "Ad Click URL: ", ad.LinkURI.c_str()); #endif // _DEBUG } } // Get Ad image pos = ad_body.FindNext("src="); if (pos >= 0) { len = ad_body.GetNextMarkedString('"', '"', offset); if (len > 0) { ad.ImageURI.setString(ad_body.getString() + offset, len); #if defined(_DEBUG) CzDebug::Log(CZ_DEBUG_CHANNEL_INFO, "Ad Image URL: ", ad.ImageURI.c_str()); #endif // _DEBUG } } return true; }