static size_t onWrite(char *ptr, size_t size, size_t nmemb, void *userdata)
    {
        WebRequestInternalState *is_(reinterpret_cast<WebRequestInternalState*>(userdata));
        is_->state = HTTP_OPEN;
        if (is_->isAborted)
        {
            is_->state = HTTP_CLOSED;
            // This should probably be CURL_WRITEFUNC_ABORT, but that doesn't
            // exist. It probably would be the same numeric value, if it did.
            // The docs say that it just has to be a number of bytes that is
            // not "size * nmemb" to abort.
            return CURL_READFUNC_ABORT;
        }

        // Find the size in bytes.
        size_t real_size(size * nmemb);

        // Write the date into the download buffer queue.
        Serializer* download(dynamic_cast<Serializer*>(is_->download.Get()));
        download->Write(ptr, (unsigned int)real_size);

        // Emit a "download_chunk" event.
        VariantMap eventData;
        eventData.Insert(MakePair(StringHash("download"), Variant(is_->download)));
        eventData.Insert(MakePair(StringHash("size"), Variant((unsigned int)real_size)));
        is_->es.SendEvent("download_chunk", eventData);

        return real_size;
    }
    static size_t onRead(char *buffer, size_t size, size_t nitems, void *instream)
    {
        WebRequestInternalState *is_(reinterpret_cast<WebRequestInternalState*>(instream));
        is_->state = HTTP_OPEN;
        if (is_->isAborted)
        {
            is_->state = HTTP_CLOSED;
            return CURL_READFUNC_ABORT;
        }

        // Find the size in bytes.
        size_t real_size(size * nitems);

        // Read as much as we can from the upload buffer queue.
        Deserializer* upload(dynamic_cast<Deserializer*>(is_->upload.Get()));
        size_t size_queued(upload->GetSize());
        size_t size_left(real_size);
        if ((size_left > 0) && (size_queued > 0))
        {
            size_t read_size(std::min(size_queued, size_left));
            upload->Read(buffer, (unsigned int)read_size);
            size_left -= read_size;
        }

        // If we still have bytes to fill, then emit a "upload_chunk" event.
        if (size_left > 0)
        {
            VariantMap eventData;
            eventData.Insert(MakePair(StringHash("upload"), Variant(is_->upload)));
            eventData.Insert(MakePair(StringHash("size"), Variant((unsigned int)size_left)));
            is_->es.SendEvent("upload_chunk", eventData);
        }

        // Read as much as we can from the upload buffer queue (again).
        size_queued = upload->GetSize();
        size_left = real_size;
        if ((size_left > 0) && (size_queued > 0))
        {
            size_t read_size(std::min(size_queued, size_left));
            upload->Read(buffer, (unsigned int)read_size);
            size_left -= read_size;
        }

        // If we still have bytes to fill, then something went wrong, so we should abort.
        if (size_left > 0)
        {
            is_->isAborted = true;
            return CURL_READFUNC_ABORT;
        }

        return real_size;
    }
    static size_t onHeader(char *ptr, size_t size, size_t nmemb, void *userdata)
    {
        WebRequestInternalState *is_(reinterpret_cast<WebRequestInternalState*>(userdata));
        if (is_->isAborted)
        {
            is_->state = HTTP_CLOSED;
            // This should probably be CURL_HEADERFUNC_ABORT, but that doesn't
            // exist. It probably would be the same numeric value, if it did.
            // The docs say that it just has to be a number of bytes that is
            // not "size * nmemb" to abort.
            return CURL_READFUNC_ABORT;
        }

        // Find the size in bytes.
        size_t real_size(size * nmemb);

        // Check for some known values.
        if (real_size == 2 && ptr[0] == '\r' && ptr[1] == '\n')
        {
            return real_size;
        }
        if (real_size > 5 && !strncmp(ptr, "HTTP/", 5))
        {
            return real_size;
        }

        // Get the header key and value, and add them to the map.
        unsigned int key_end = 0;
        unsigned int value_begin = 2;
        while (value_begin < real_size)
        {
            if (ptr[key_end] == ':' && ptr[key_end + 1] == ' ')
            {
                break;
            }
            ++key_end;
            ++value_begin;
        }
        if (value_begin == real_size)
        {
            String key(ptr, (unsigned int)real_size);
            is_->responseHeaders.InsertNew(key.ToUpper(), MakePair(key, String()));
        }
        else
        {
            String key(ptr, (unsigned int)key_end);
            is_->responseHeaders.InsertNew(key.ToUpper(), MakePair(key, String(ptr + value_begin, (unsigned int)real_size - value_begin - 2)));
        }

        return real_size;
    }
    static int onProgress(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
    {
        WebRequestInternalState *is_(reinterpret_cast<WebRequestInternalState*>(clientp));
        if (is_->isAborted)
        {
            // This should probably be CURL_XFERINFO_ABORT, but that doesn't
            // exist. It probably would be the same numeric value, if it did.
            // The docs say that it just has to be a nonzero to abort.
            return CURL_READFUNC_ABORT;
        }

        VariantMap eventData;
        eventData.Insert(MakePair(StringHash("down_total"), Variant((double)dltotal)));
        eventData.Insert(MakePair(StringHash("down_loaded"), Variant((double)dlnow)));
        eventData.Insert(MakePair(StringHash("up_total"), Variant((double)ultotal)));
        eventData.Insert(MakePair(StringHash("up_loaded"), Variant((double)ulnow)));
        is_->es.SendEvent("progress", eventData);
        return 0;
    }
示例#5
0
static int checkConflict(
	Tcl_Interp * interp,
	char *path,
	char **modulelist,
	unsigned int nummodules
) {
	uvec           *new_modulelist;
	int             new_nummodules, k;
	is_Result       fstate;
	char           *buffer;

	memset(error_module, '\0', MOD_BUFSIZE);

    /**
     **  Check all modules passed to me as parameter
     **  At first clarify if they really do exist ...
     **/
	for (k = 0; k < nummodules; k++) {
		if (!(buffer = stringer(NULL,0,path,psep,modulelist[k],NULL)))
			if (OK != ErrorLogger(ERR_STRING, LOC, NULL))
				goto unwind0;
		if (!(fstate = is_("what", buffer))) {
			if (OK != ErrorLogger(ERR_FILEINDIR, LOC,
				modulelist[k], path, NULL))
				if (!stringer(error_module, MOD_BUFSIZE,
					     modulelist[k], NULL))
					if (OK !=
					    ErrorLogger(ERR_STRING, LOC, NULL))
						goto unwind1;
			goto unwind1;
		}
	/**
	 **  Is it a directory what has been passed? If it is, list the
	 **  according directory and call myself recursively in order to
	 **/
		if (fstate == IS_DIR) {
			if (!(new_modulelist = SortedDirList(path,
				modulelist[k], &new_nummodules)))
				continue;

			if (TCL_ERROR == checkConflict(interp, path,
			uvec_vector(new_modulelist), new_nummodules)) {
				FreeList(&new_modulelist);
				goto unwind1;
			}
			FreeList(&new_modulelist);
	/**
	 **  If it isn't a directory, check the current one for to be the
	 **  required module file
	 **/
		} else {
			if (IsLoaded_ExactMatch (interp,modulelist[k],NULL,NULL)
			    && strcmp(g_current_module, modulelist[k])) {

		/**
                 **  Save the name of the offending module in a buffer
                 **  for reporting purposes when we get back to the top.
                 **/

				if (!stringer(error_module, MOD_BUFSIZE,
					     modulelist[k], NULL))
					if (OK !=
					    ErrorLogger(ERR_STRING, LOC, NULL))
						goto unwind1;
				goto unwind1;
			}

		} /** if( directory) **/
	} /** for **/
    /**
     ** free resources
     **/
	null_free((void *)&buffer);

	return (TCL_OK);		/** -------- EXIT (SUCCESS) -------> **/

unwind1:
	null_free((void *)&buffer);
unwind0:
	return (TCL_ERROR);		/** -------- EXIT (FAILURE) -------> **/

} /** End of 'checkConflict' **/
示例#6
0
int main() {
	test_plan(60);

	ok(0);
	ok(1);
	ok_(3, "My third test");
    int ia, ib, ic;
    ia = 123, ib = 123, ic = 132; 
    short int sia, sib, sic;
    sia = 123, sib = 123, sic = 132;
    long int lia, lib, lic;
    lia = 123, lib = 123, lic = 132;
    double da, db, dc;
    da = 1.2222222, db = 1.2222222, dc = 1.2333333;
    float fa, fb, fc;
    fa = 1.2222222, fb = 1.2222222, fc = 1.2333333; 

	is("abc", "abc");
    is("abc", "ab");
	is_("abc", "abc", "My char test");    
	is_("abc", "ab", "Failed test");


    is(ia, ib);
    is(ia, ic);
	is_(ia, ib, "My int test");    
	is_(ia, ic, "Failed test");


    is(sia, sib);
    is(sia, sic);
	is_(sia, sib, "My  short int test");    
	is_(sia, sic, "Failed test");


    is(lia, lib);
    is(lia, lic);
	is_(lia, lib, "My int test");    
	is_(lia, lic, "Failed test");


    is(da, db);
    is(da, dc);
	is_(da, db, "My double test");    
	is_(da, dc, "Failed test");
    

    is(fa, fb);
    is(fa, fc);
	is_(fa, fb, "My float test");    
	is_(fa, fc, "Failed test");



    isnt("abc", "abc");
    isnt("abc", "ab");
	isnt_("abc", "abc", "My char test");    
	isnt_("abc", "ab", "Failed test");

    isnt(ia, ib);
    isnt(ia, ic);
	isnt_(ia, ic, "My int test");    
	isnt_(ia, ib, "Failed test");

    isnt(sia, sib);
    isnt(sia, sic);
	isnt_(sia, sic, "My  short int test");    
	isnt_(sia, sib, "Failed test");

    isnt(lia, lib);
    isnt(lia, lic);
	isnt_(lia, lic, "My int test");    
	isnt_(lia, lib, "Failed test");


    isnt(da, db);
    isnt(da, dc);
	isnt_(da, dc, "My double test");    
	isnt_(da, db, "Failed test");

    isnt(fa, fb);
    isnt(fa, fc);
	isnt_(fa, fc, "My float test");    
	isnt_(fa, fb, "Failed test");

	summary();
	return 0;
}