void ZatData::loadAppId() { HTTPSocket *httpSocket = new HTTPSocketRaw(); Request request; request.url = "zattoo.com"; Response response; httpSocket->Execute(request, response); appToken = ""; std::string html = response.body; std::smatch m; std::regex e ("appToken.*\\'(.*)\\'"); std::string token = ""; if (std::regex_search(html, m, e)) { token = m[1]; } cout << token << endl; appToken = token; XBMC->Log(LOG_DEBUG, "Loaded App token %s", XBMC->UnknownToUTF8(appToken.c_str())); }
void sendRequest() { // Create a new HTTPSocket for the request HTTPSocket *sock = new HTTPSocket(this->parent, false); sock->connectToHost("www.google.co.uk", 80); connect(sock, SIGNAL(responseReady(const QString &, const QString &, const QMultiMap<QString, QString> &)), this->parent, SLOT(onResponseReady(const QString &, const QString &, const QMultiMap<QString, QString> &))); sock->write("GET / HTTP/1.1\r\n\r\n"); }
bool Init() { XBMC->Log(LOG_DEBUG, "%s", __FUNCTION__); HTTPSocket sock; std::string resp_headers; std::string resp_body; size_t pos; std::string locationUrl; sock.SetURL(g_strServer); if (!sock.Execute(&resp_headers, &resp_body)) { XBMC->Log(LOG_ERROR, "%s: api init failed", __FUNCTION__); return false; } // xpcom.common.js > get_server_params() // check for location header if ((pos = resp_headers.find("Location: ")) != std::string::npos) { locationUrl = resp_headers.substr(pos + 10, resp_headers.find("\r\n", pos) - (pos + 10)); } else { XBMC->Log(LOG_DEBUG, "%s: failed to get api endpoint from location header", __FUNCTION__); // convert to lower case std::transform(resp_body.begin(), resp_body.end(), resp_body.begin(), ::tolower); // check for meta refresh tag if ((pos = resp_body.find("url=")) != std::string::npos) { locationUrl = g_strServer + "/" + resp_body.substr(pos + 4, resp_body.find("\"", pos) - (pos + 4)); } else { XBMC->Log(LOG_DEBUG, "%s: failed to get api endpoint from meta refresh tag", __FUNCTION__); // assume current url is the intended location XBMC->Log(LOG_DEBUG, "%s: assuming current url is the intended location", __FUNCTION__); locationUrl = g_strServer; } } if ((pos = locationUrl.find_last_of("/")) == std::string::npos || locationUrl.substr(pos - 2, 3).compare("/c/") != 0) { XBMC->Log(LOG_ERROR, "%s: failed to get api endpoint", __FUNCTION__); return false; } // strip tail from url path and set api endpoint and referer g_strApiBasePath = locationUrl.substr(0, pos - 1); g_api_endpoint = g_strApiBasePath + "server/load.php"; g_referer = locationUrl.substr(0, pos + 1); XBMC->Log(LOG_DEBUG, "api endpoint: %s", g_api_endpoint.c_str()); XBMC->Log(LOG_DEBUG, "referer: %s", g_referer.c_str()); return true; }
char* OnRequest(Request *req) { HTTPClientRequest *httpreq = (HTTPClientRequest *)req; if (!strcmp(httpreq->GetId(), HTTP_CLIENT_REQUEST)) { HTTPSocket *sock = new HTTPSocket(ServerInstance, this); sock->DoRequest(httpreq); // No return value } return NULL; }
/* * Get() * URLから取得 */ uint O2Boards:: Get(const char *url) { const char *target_url = url ? url : DEFAULT_BBSMENU_URL; HTTPSocket *socket = new HTTPSocket(SELECT_TIMEOUT_MS, Profile->GetUserAgentA()); HTTPHeader h(HTTPHEADERTYPE_REQUEST); if (LastModified) h.AddFieldDate("If-Modified-Since", LastModified); string out; HTTPHeader oh(HTTPHEADERTYPE_RESPONSE); if (!socket->request(target_url, h, NULL, 0)) { delete socket; return (0); } while (socket->response(out, oh) >= 0) { if (oh.contentlength) { if (out.size() - oh.length >= oh.contentlength) break; } } delete socket; if (oh.status != 200) return (oh.status); if (!Update(&out[oh.length])) return (0); strmap::iterator it = oh.fields.find("Last-Modified"); if (it == oh.fields.end()) it = oh.fields.find("Date"); if (it == oh.fields.end()) return (0); time_t t = oh.httpdate2time_t(it->second.c_str()); LastModified = t; /* TRACEA(it->first.c_str()); TRACEA(": "); TRACEA(it->second.c_str()); TRACEA("\n"); TRACEA(ctime(&LastModified)); */ return (oh.status); }
bool ZatData::LoadEPG(time_t iStart, time_t iEnd) { // iStart -= (iStart % (3600/2)) - 86400; // Do s // iEnd = iStart + 3600*3; //Do some time magic that the start date is not to far in the past because zattoo doesnt like that time_t tempStart = iStart - (iStart % (3600/2)) - 86400; time_t tempEnd = tempStart + 3600*5; //Add 5 hours while(tempEnd < iEnd) { ostringstream urlStream; urlStream << "zattoo.com/zapi/v2/cached/program/power_guide/" << powerHash << "?end=" << tempEnd << "&start=" << tempStart << "&format=json"; HTTPSocket *socket = new HTTPSocketRaw(); Request request; request.url = urlStream.str(); request.AddHeader("Cookie", cookie); Response response; socket->Execute(request,response); cookie = response.cookie; std::string jsonString = response.body; Json::Value json; Json::Reader reader; bool parsingSuccessful = reader.parse(jsonString,json); //D(cout << json << endl); Json::Value channels = json["channels"]; //Load the channel groups and channels for ( int index = 0; index < channels.size(); ++index ) { string cid = channels[index]["cid"].asString(); for (int i = 0; i < channels[index]["programs"].size(); ++i) { Json::Value program = channels[index]["programs"][i]; int channelId = GetChannelId(cid.c_str()); ZatChannel *channel = FindChannel(channelId); if (!channel) { continue; } PVRIptvEpgEntry entry; entry.strTitle = program["t"].asString(); entry.startTime = program["s"].asInt(); entry.endTime = program["e"].asInt(); entry.iBroadcastId = program["id"].asInt(); entry.strIconPath = program["i_url"].asString(); entry.iChannelId = channel->iChannelNumber; entry.strPlot = program["et"].asString(); Json::Value genres = program["g"]; ostringstream generesStream; for (int genre = 0; genre < genres.size(); genre++) { generesStream << genres[genre].asString() << " "; } entry.strGenreString = generesStream.str(); if (channel) channel->epg.insert(channel->epg.end(), entry); } } tempStart = tempEnd; tempEnd = tempStart + 3600*5; //Add 5 hours } return true; }
bool StalkerCall(sc_identity_t *identity, sc_param_request_t *params, std::string *resp_headers, std::string *resp_body, Json::Value *parsed) { XBMC->Log(LOG_DEBUG, "%s", __FUNCTION__); sc_request_t request; sc_request_header_t *header; HTTPSocket sock; size_t pos; Json::Reader reader; memset(&request, 0, sizeof(request)); if (!sc_request_build(identity, params, &request)) { XBMC->Log(LOG_ERROR, "sc_request_build failed"); } header = request.headers; while (header) { std::string strValue; strValue = header->value; //TODO url encode while ((pos = strValue.find(":")) != std::string::npos) { strValue.replace(pos, 1, "%3A"); } while ((pos = strValue.find("/")) != std::string::npos) { strValue.replace(pos, 1, "%2F"); } sock.AddHeader(header->name, strValue); header = header->next; } sock.AddHeader("Referer", g_referer); sock.AddHeader("X-User-Agent", "Model: MAG250; Link: WiFi"); //TODO url encode std::string query; query = request.query; while ((pos = query.find(" ")) != std::string::npos) { query.replace(pos, 1, "%20"); } sock.SetURL(g_api_endpoint + "?" + query); sc_request_free_headers(request.headers); if (!sock.Execute(resp_headers, resp_body)) { XBMC->Log(LOG_ERROR, "%s: api call failed", __FUNCTION__); return false; } if (!reader.parse(*resp_body, *parsed)) { XBMC->Log(LOG_ERROR, "%s: parsing failed", __FUNCTION__); if (resp_body->compare(AUTHORIZATION_FAILED) == 0) { XBMC->Log(LOG_ERROR, "%s: authorization failed", __FUNCTION__); } return false; } return true; }
void OnLookupComplete(const string &result, unsigned int ttl, bool cached) { socket->Connect(result); }