bool CIwGameAds::ExtractLinkAndImageFromtHTML(CIwGameAd& ad, CIwGameString& html) { int pos, offset; // Check to see if the html has a clickable link pos = html.Find("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) CIwGameError::LogError("Info: Ad Link URL: ", ad.LinkURI.c_str()); #endif // _DEBUG // Check to see if the html has an image available pos = html.Find("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) CIwGameError::LogError("Info: Ad Image URL: ", ad.ImageURI.c_str()); #endif // _DEBUG return true; } } } } } return false; }
bool CIwGameAds::ExtractAdAdModa(CIwGameAd& ad, CIwGameString& ad_body) { int len, offset; ad.isHtml = false; ad.isText = false; ad.ImageURI = ""; ad.LinkURI = ""; ad.Text = ""; ad.AdTime = s3eTimerGetMs(); 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) CIwGameError::LogError("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) CIwGameError::LogError("Info: Ad Click URL: ", ad.LinkURI.c_str()); #endif // _DEBUG } if (ad.ImageURI.IsEmpty() || ad.LinkURI.IsEmpty()) return false; return true; }
bool CIwGameAds::ExtractAdInnerActive(CIwGameAd& ad, CIwGameString& 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 = s3eTimerGetMs(); // 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) CIwGameError::LogError("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) CIwGameError::LogError("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) CIwGameError::LogError("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) CIwGameError::LogError("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) CIwGameError::LogError("Info: Ad Image URL: ", ad.ImageURI.c_str()); #endif // _DEBUG } } return true; }
bool CIwGameAds::ExtractAdAdFonic(CIwGameAd& ad, CIwGameString& 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 = s3eTimerGetMs(); // 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) { CIwGameString format; format.setString(ad_body.getString() + offset, len); if (format == "banner") ad.isText = false; else ad.isText = true; #if defined(_DEBUG) CIwGameError::LogError("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) CIwGameError::LogError("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) CIwGameError::LogError("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) CIwGameError::LogError("Info: Ad Image URL: ", ad.ImageURI.c_str()); #endif // _DEBUG } } return true; }
bool CIwGameAds::ExtractAdMobFox(CIwGameAd& ad, CIwGameString& 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 = s3eTimerGetMs(); // 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) CIwGameError::LogError("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) CIwGameError::LogError("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) CIwGameError::LogError("Info: Ad Image URL: ", ad.ImageURI.c_str()); #endif // _DEBUG } } return true; }