dish/src/dish.cxx
//----------------------------------------------------------------
// This static function will send access command to the given socket
// wrapping it fo fit HTTP protocol.
//
// "server" defines object which will process request on the server.
// "accessCmd" is an access command which will be processed by the server object.
// If "usePost" is set POST command will be used, if not - GET command will  be used.
// Will return 1 if everything is OK and 0 if error during transmission.
//----------------------------------------------------------------
This static function will send access command to the given socket
wrapping it fo fit HTTP protocol.

"server" defines object which will process request on the server.
"accessCmd" is an access command which will be processed by the server object.
If "usePost" is set POST command will be used, if not - GET command will  be used.
Will return 1 if everything is OK and 0 if error during transmission.
This static function will send access command to the given socket wrapping it fo fit HTTP protocol . " server " defines object which will process request on the server . " accessCmd " is an access command which will be processed by the server object . If " usePost " is set POST command will be used if not - GET command will be used . Will return 1 if everything is OK and 0 if error during transmission .
static int sendHttpRequest(int socket, char* server, char* accessCmd,int usePost)
{
    const char* Accept          = "Accept: %s\r\n";
    const char* AcceptLanguage  = "Accept-Language: %s\r\n";
    const char* AcceptEncoding  = "Accept-Encoding: %s\r\n";
    const char* ContentType     = "Content-Type: %s\r\n";
    const char* UserAgent       = "User-Agent: %s\r\n";
    const char* Connection      = "Connection: %s\r\n";
    const char* Host            = "Host: %s\r\n";
    const char* ContentLength   = "Content-Length: %d\r\n";
    char* hostIp;
    char* package;
    char  one_header[1024];
    char  buf[1024];
    struct hostent *ent;
    gethostname(buf,1024);
    ent = gethostbyname(buf);
    if(ent!=NULL) {
        hostIp = inet_ntoa(*(in_addr *)*ent->h_addr_list);
        if(hostIp==NULL) {
            hostIp = "127.0.0.1";
        }
    } else {
        hostIp = "127.0.0.1";
    }
    if(accessCmd) package = new char[strlen(accessCmd)+5000];
    else          package = new char[5000];
    if(usePost)  strcpy(package,"POST ");
    else         strcpy(package,"GET "); 
    if(server)   {
        strcat(package," ");
        strcat(package,server);
        strcat(package," ");
    } else {
        strcat(package," / ");
    }
    strcat(package,"HTTP/1.1\r\n");
    sprintf(one_header,Accept,"*/*");
    strcat(package,one_header);
    sprintf(one_header,AcceptLanguage,"en-us");
    strcat(package,one_header);
    sprintf(one_header,AcceptEncoding,"gzip,deflate");
    strcat(package,one_header);
    sprintf(one_header,ContentType,"application/discover");
    strcat(package,one_header);
    sprintf(one_header,UserAgent,"discover");
    strcat(package,one_header);
    if(accessCmd!=NULL && strlen(accessCmd)>0) {
        sprintf(one_header,ContentLength,strlen(accessCmd));
        strcat(package,one_header);
    }
    sprintf(one_header,Host,hostIp);
    strcat(package,one_header);
    sprintf(one_header,Connection,"Keep-Alive");
    strcat(package,one_header);
    strcat(package,"\r\n");
    if(accessCmd!=NULL && strlen(accessCmd)>0) {
        strcat(package,accessCmd);
    }
    if(send(socket,package, strlen(package),0)>0) return 1;
    return 0;
}
static int sendHttpRequest ( int socket , char * server , char * accessCmd , int usePost ) { const char * Accept = " \r \n " ; const char * AcceptLanguage = " \r \n " ; const char * AcceptEncoding = " \r \n " ; const char * ContentType = " \r \n " ; const char * UserAgent = " \r \n " ; const char * Connection = " \r \n " ; const char * Host = " \r \n " ; const char * ContentLength = " \r \n " ; char * hostIp ; char * package ; char one_header [ 1024 ] ; char buf [ 1024 ] ; struct hostent * ent ; gethostname ( buf , 1024 ) ; ent = gethostbyname ( buf ) ; if ( ent != NULL ) { hostIp = inet_ntoa ( * ( in_addr * ) * ent -> h_addr_list ) ; if ( hostIp == NULL ) { hostIp = " " ; } } else { hostIp = " " ; } if ( accessCmd ) package = new char [ strlen ( accessCmd ) + 5000 ] ; else package = new char [ 5000 ] ; if ( usePost ) strcpy ( package , " " ) ; else strcpy ( package , " " ) ; if ( server ) { strcat ( package , " " ) ; strcat ( package , server ) ; strcat ( package , " " ) ; } else { strcat ( package , " " ) ; } strcat ( package , " \r \n " ) ; sprintf ( one_header , Accept , " " ) ; strcat ( package , one_header ) ; sprintf ( one_header , AcceptLanguage , " " ) ; strcat ( package , one_header ) ; sprintf ( one_header , AcceptEncoding , " " ) ; strcat ( package , one_header ) ; sprintf ( one_header , ContentType , " " ) ; strcat ( package , one_header ) ; sprintf ( one_header , UserAgent , " " ) ; strcat ( package , one_header ) ; if ( accessCmd != NULL && strlen ( accessCmd ) > 0 ) { sprintf ( one_header , ContentLength , strlen ( accessCmd ) ) ; strcat ( package , one_header ) ; } sprintf ( one_header , Host , hostIp ) ; strcat ( package , one_header ) ; sprintf ( one_header , Connection , " " ) ; strcat ( package , one_header ) ; strcat ( package , " \r \n " ) ; if ( accessCmd != NULL && strlen ( accessCmd ) > 0 ) { strcat ( package , accessCmd ) ; } if ( send ( socket , package , strlen ( package ) , 0 ) > 0 ) return 1 ; return 0 ; }
This static function will send access command to the given socket
wrapping it fo fit HTTP protocol.
This static function will send access command to the given socket wrapping it fo fit HTTP protocol .
// Determining current host ip string // Forming HTTP command // Forming HTTP MIME headers