Ejemplo n.º 1
1
void select_multiple::load(cgicc::Cgicc const &cgi)
{
	chosen.clear();
	cgicc::const_form_iterator p=cgi.getElements().begin(),e=cgi.getElements().end();
	for(;p!=e;++p) {
		if(p->getName()==name) {
			map<string,string>::iterator orig=available.find(p->getValue());
			if(orig!=available.end()) 
				chosen.insert(orig->first);
		}
	}
	is_set=true;
}
Ejemplo n.º 2
0
void submit::load(cgicc::Cgicc const &cgi)
{
	is_set=true;
	cgicc::const_form_iterator v=cgi.getElement(name);
	if(v!=cgi.getElements().end())
		pressed=true;
}
Ejemplo n.º 3
0
void text::load(cgicc::Cgicc const &cgi)
{
	cgicc::const_form_iterator v=cgi.getElement(name);
	if(v!=cgi.getElements().end()) {
		value=**v;
		is_set=true;
	}
}
Ejemplo n.º 4
0
void select_base::load(cgicc::Cgicc const &cgi)
{
	cgicc::const_form_iterator p=cgi.getElement(name);
	if(p==cgi.getElements().end()) {
		is_set=false;
	}
	else {
		value=**p;
		is_set=true;
	}
}
Ejemplo n.º 5
0
void checkbox::load(cgicc::Cgicc const &cgi)
{
	cgicc::const_form_iterator p=cgi.getElements().begin(),e=cgi.getElements().end();
	while(p!=e) {
		if(p->getName()==name && p->getValue()==input_value) {
			value=true;
			return;
		}
		++p;
	}
	value=false;
}
Ejemplo n.º 6
0
bool Server::init(cgicc::Cgicc cgicc) {
    std::cout << "Access-Control-Allow-Origin: \"*\"\r\n";

    serverReceiveImageTime = timestamp_usec();

    //gets the fields of the request
    cgicc::form_iterator fiImage = cgicc.getElement("image");
    cgicc::form_iterator fiScreenWidthPixel = cgicc.getElement("screenWidthPixel");
    cgicc::form_iterator fiScreenHeightPixel = cgicc.getElement("screenHeightPixel");
    cgicc::form_iterator fiNumSnapshot = cgicc.getElement("numSnapshot");
    cgicc::form_iterator fiSnapshotType = cgicc.getElement("snapshotType");
    cgicc::form_iterator fiIsBoundingBox = cgicc.getElement("isBoundingBox");
    //    cgicc::form_iterator fiSeed = cgicc.getElement("seed");
    //    cgicc::form_iterator fiToken = cgicc.getElement("token");
    //    cgicc::form_iterator fiSessionName = cgicc.getElement("sessionName");
    cgicc::form_iterator fiOldIp = cgicc.getElement("ip");
    if (((fiImage != (*cgicc).end()) && (!fiImage->isEmpty()))
            && ((fiScreenWidthPixel != (*cgicc).end()) && (!fiScreenWidthPixel->isEmpty()))
            && ((fiScreenHeightPixel != (*cgicc).end()) && (!fiScreenHeightPixel->isEmpty()))
            && ((fiNumSnapshot != (*cgicc).end()) && (!fiNumSnapshot->isEmpty()))
            && ((fiSnapshotType != (*cgicc).end()) && (!fiSnapshotType->isEmpty()))
            && ((fiIsBoundingBox != (*cgicc).end()) && (!fiIsBoundingBox->isEmpty()))
            //            && ((fiSeed != (*cgicc).end()) && (!fiSeed->isEmpty()))
            //            && ((fiToken != (*cgicc).end()) && (!fiToken->isEmpty()))
            //            && ((fiSessionName != (*cgicc).end()))
            && ((fiOldIp != (*cgicc).end()))
            ) {

        //TODO: if the diff flag is true, use the difference construction of the image
        //      using the rules in the .js file

        std::string stringUrlImage = (**fiImage);
        const char * urlImage = stringUrlImage.c_str();

        if (strlen(urlImage) > 4) {
            char * imageDecoded;

            //if the url has not the "data:" in the firsts characters, probably is because isn't decoded
            if (urlImage[4] != ':') {
                imageDecoded = CGI_decode_url(urlImage);
            }
            else {
                imageDecoded = new char[stringUrlImage.size() + 1];
                copy(stringUrlImage.begin(), stringUrlImage.end(), imageDecoded);
                imageDecoded[stringUrlImage.size()] = '\0';
            }

            //find the comma that splits the header of the url image, to the data of the image
            int iPreviousComma = -1;
            int strlenImageDecoded = strlen(imageDecoded);
            for (int i = 0; i < strlenImageDecoded; i++) {
                if (imageDecoded[i] == ',') {
                    iPreviousComma = i + 1;
                    break;
                }
            }

            if (iPreviousComma > -1) {
                //takes the data of the image
                char imageDecodeWithoutContent[strlenImageDecoded - iPreviousComma];
                for (int i = iPreviousComma, j = 0; i < strlenImageDecoded; i++, j++) {
                    imageDecodeWithoutContent[j] = imageDecoded[i];
                }

                //convert the url image in a byte array
                std::vector<BYTE> imageByteArray = base64_decode(imageDecodeWithoutContent);

                //convert the byte array in a Mat
                cv::Mat image = cv::imdecode(imageByteArray, CV_LOAD_IMAGE_COLOR);


                /*SAVE THE IMAGE*/
                long long now = timestamp_usec();
                std::stringstream fileName;
                fileName << "stream/" << now << ".jpeg";
                int i = 0;
                while (fileExists(fileName.str().c_str())) {
                    fileName << "stream/" << now << i << ".jpeg";
                    i++;
                }
                cv::imwrite(fileName.str(), image);

                numSnapshot = atoi((**fiNumSnapshot).c_str());
                snapshotType = (**fiSnapshotType).c_str();
                screenWidthPixel = atoi((**fiScreenWidthPixel).c_str());
                screenHeightPixel = atoi((**fiScreenHeightPixel).c_str());
                isBoundingBox = atoi((**fiIsBoundingBox).c_str());
                //                seed = atoi((**fiSeed).c_str());
                //                token = atoi((**fiSeed).c_str());
                //                sessionName = (**fiSessionName).c_str();
                std::string oldIp = (**fiOldIp).c_str();

                ip = cgicc.getEnvironment().getRemoteAddr();


                //activate those lines to see the print of the code and see the debug in the webservice mode
                //                                saveCookies();
                std::cout << "Content-type:text/html\r\n\r\n";

                createSessionName();

                if (oldIp.compare("") != 0) {
                    if (ip.compare(oldIp) != 0) {
                        if (copyInfo(oldIp, ip) == -1) {
                            //error on copy
                            eraseSessionInfo();
                        }
                        std::stringstream filePath;
                        filePath << "session/" << oldIp << "/";
                        removeDirectoryElements(filePath.str().c_str(), "");
                    }
                }

                readInfo();

                setPreviousFrame(getPersistentImage("frame"));
                setFrame(image);
                setPersistentImage("frame", image);
                setPersistentImage("previousFrame", previousFrame);

                /*GET COOKIES*/

                // get environment variables
                //initCookies(cgicc.getEnvironment().getCookieList());
                //                const cgicc::CgiEnvironment& env = cgicc.getEnvironment();
                //                cgicc::const_cookie_iterator cci;
                //                for(cci = env.getCookieList().begin(); cci != env.getCookieList().end(); cci++) {
                //                    Server::getServer()->setCookie(cci->getName(), cci->getValue());
                //                    //std::cout << "<tr><td>" << cci->getName() << "</td><td>";
                //                    //std::cout << cci->getValue();
                //                    //std::cout << "</td></tr>\n";
                //                }
                //std::cout << "</table><\n";

                //std::cout << "<br/>\n";
                //std::cout << "</body>\n";
                //std::cout << "</html>\n";

                return true;
            }
        }
    }

    return false;
}