MovieListRequest Class Reference

This class is used to request to movielist from the mediaserver (by HTTP) and write it to a file. More...

#include <MovieListRequest.hpp>

List of all members.


Public Member Functions

 MovieListRequest ()
 default constructor
 ~MovieListRequest ()
 default destructor
bool requestMovieList (const char *hostname, int port=80)
 Requests the movielist from a specified server.

Detailed Description

This class is used to request to movielist from the mediaserver (by HTTP) and write it to a file.

Also the descriptive images, which are specified in this file will be requested by HTTP and stored in a file.

Author:
Klaus Schoeffmann

Definition at line 87 of file MovieListRequest.hpp.


Member Function Documentation

bool MovieListRequest::requestMovieList const char *  hostname,
int  port = 80
 

Requests the movielist from a specified server.

Also looks for images in this file and requests them too. Definition at line 163 of file MovieListRequest.cpp.

References Globals::getAbsoluteImagesFilePath(), and semifunc::newStrCpy().

00164 { 00165 00166 //find out IP-Address of specified host 00167 // hostent *host = gethostbyname(hostname); 00168 // char *address = inet_ntoa(*(reinterpret_cast<in_addr*>(host->h_addr))); 00169 00170 //buffer used for receiving 00171 char *buffer = new char[MAX_RECBUFFER_SIZE]; 00172 char *bufferStart = buffer; 00173 uint contentLength; 00174 00175 //send HTTP GET message for movielist 00176 ostringstream httpMsg; 00177 //httpMsg << "GET http://" << address << "/MovieList.xml HTTP/1.1\r\n\r\n"; httpMsg.flush(); 00178 httpMsg << "GET /MovieList.xml HTTP/1.1\r\n\r\n"; httpMsg.flush(); 00179 if ((buffer = makeHttpRequest(hostname, port, httpMsg.str(), buffer, contentLength))) 00180 { 00181 00182 //write this content to a file, where the semiserver has access to 00183 writeToFile(Globals::getMoviesFileName(), buffer, contentLength); 00184 00185 //search for images 00186 list<char*> imgList; 00187 char *imgStart, *imgEnd; //37 00188 while ((imgStart = strstr(buffer, "<Resource mimeType=\"image/jpeg\" ref=\"")) != NULL) 00189 { 00190 imgEnd = strstr(imgStart+strlen("<Resource mimeType=\"image/jpeg\" ref=\""), "\""); 00191 if (imgEnd != NULL) 00192 { 00193 char *foundImg = semifunc::newStrCpy( 00194 imgStart+strlen("<Resource mimeType=\"image/jpeg\" ref=\""), 00195 imgEnd-(imgStart+strlen("<Resource mimeType=\"image/jpeg\" ref=\""))); 00196 Globals::sdebug << "\nFound Image: " << foundImg; 00197 //add this image to the list, if not already there 00198 addIfNotExists(imgList, foundImg); 00199 } 00200 buffer = imgEnd; 00201 } 00202 00203 //now request all images 00204 list<char*>::iterator iter = imgList.begin(); 00205 while (iter != imgList.end()) 00206 { 00207 char *img = *iter; 00208 ostringstream httpMsgImg; 00209 //httpMsgImg << "GET http://" << address << "/" << img << " HTTP/1.1\r\n\r\n"; 00210 httpMsgImg << "GET /" << img << " HTTP/1.1\r\n\r\n"; 00211 Globals::sdebug << "\n" << httpMsgImg.str().c_str(); 00212 if ((buffer = makeHttpRequest(hostname, port, httpMsgImg.str(), bufferStart, contentLength))) 00213 { 00214 ostringstream filename; 00215 filename << Globals::getAbsoluteImagesFilePath() << img; 00216 writeToFile(filename.str().c_str(), buffer, contentLength); 00217 } 00218 00219 iter++; 00220 } 00221 imgList.clear(); //clear list 00222 00223 delete bufferStart; 00224 bufferStart = NULL; 00225 return true; 00226 00227 } 00228 00229 00230 return false; 00231 }


The documentation for this class was generated from the following files: