Beispiel #1
0
void gfal2_test_gfal_select_best_protocol_and_endpointG()
{
	char endpoint[2048];
	memset(endpoint, '\0', sizeof(char)*2048);
	enum gfal_srm_proto srm_type;
	GError * err= NULL;
	gfal_handle handle  = gfal_initG(&err);
	assert_true_with_message(handle != NULL, " handle is not properly allocated");
	if(handle==NULL)
		return;
	gfal_plugins_instance(handle, NULL);
	gfal_srmv2_opt opts;
	gfal_srm_opt_initG(&opts, handle);
	gfal_set_default_storageG(&opts, PROTO_SRMv2);
	char* endpoint_list[] = { "everest", "montblanc", NULL};
	char* se_type_list[] = { "srm_v1", "srm_v2", NULL };
	int ret = gfal_select_best_protocol_and_endpointG(&opts, se_type_list, endpoint_list, endpoint, 2048, &srm_type, &err);
	assert_true_with_message(ret ==0 && err == NULL, " must be a succefull call to the best select");
	gfal_check_GError(&err);

	assert_true_with_message(strings_are_equal(endpoint,"montblanc"), " reponse not match correctly");
	// try with another version by default
	gfal_set_default_storageG(&opts, PROTO_SRM);
	ret = gfal_select_best_protocol_and_endpointG(&opts, se_type_list, endpoint_list, endpoint, 2048, &srm_type, &err);
	assert_true_with_message(ret ==0 && err == NULL, " must be a succefull call to the best select");
	gfal_check_GError(&err);
	assert_true_with_message(strings_are_equal(endpoint,"everest") , "must be a valid check");	
	gfal_handle_freeG(handle);
}
Beispiel #2
0
void gfal2_test_gfal_auto_get_srm_endpoint_full_endpoint_with_no_bdiiG()
{
#if USE_MOCK
	setup_mock_bdii();

#endif
	GError* err = NULL;
	char buff_endpoint[2048];
	enum gfal_srm_proto proto;
	gfal_handle handle = gfal_initG(&err);
	assert_true_with_message(handle != NULL, " handle is not properly allocated");
	if(handle==NULL)
		return;
	gfal_plugins_instance(handle, NULL);
	gfal_srmv2_opt opts;
	gfal_srm_opt_initG(&opts, handle);
	gfal_set_nobdiiG(handle, TRUE);
	int ret =-1;
	ret = gfal_srm_determine_endpoint(&opts, TEST_SRM_DPM_FULLENDPOINT_PREFIX, buff_endpoint, 2048, &proto, &err);
	assert_true_with_message( ret ==0 && err == NULL && strings_are_equal(buff_endpoint, TEST_SRM_DPM_FULLENDPOINT_URL), " must be a succesfull endpoint determination %d %ld %s", ret, err, buff_endpoint);
	gfal_check_GError(&err);	
	
	ret = gfal_srm_determine_endpoint(&opts, "srm://srm-pps:8443/srm/managerv2?SFN=/castor/cern.ch/grid/dteam/castordev/test-srm-pps_8443-srm2_d0t1-ed6b7013-5329-4f5b", buff_endpoint, 2048, &proto, &err);
	assert_true_with_message( ret ==0 && err == NULL && strings_are_equal(buff_endpoint, "httpg://srm-pps:8443/srm/managerv2"), " must be a succesfull endpoint determination 2 %d %ld %s", ret, err, buff_endpoint);
	gfal_check_GError(&err);
	memset(buff_endpoint,0, sizeof(char)*2048);
	ret = gfal_srm_determine_endpoint(&opts, TEST_SRM_VALID_SURL_EXAMPLE1, buff_endpoint, 2048, &proto, &err);
	assert_true_with_message( ret !=0 && err != NULL && err->code== EINVAL && *buff_endpoint=='\0', " must be a reported error, bdii is disable");
	g_clear_error(&err);
	gfal_handle_freeG(handle);	
}
Beispiel #3
0
void gfal2_test_gfal_srm_determine_endpoint_full_endpointG()
{
#if USE_MOCK
	setup_mock_bdii();

#endif
	GError* err = NULL;
	char buff_endpoint[2048];
	enum gfal_srm_proto proto;
	gfal_handle handle = gfal_initG(&err);
	assert_true_with_message(handle != NULL, " handle is not properly allocated");
	if(handle==NULL)
		return;
	gfal_srmv2_opt opts;
	gfal_srm_opt_initG(&opts, handle);
	int ret =-1;
	ret = gfal_srm_determine_endpoint(&opts, TEST_SRM_DPM_FULLENDPOINT_PREFIX, buff_endpoint, 2048, &proto, &err);
	assert_true_with_message( ret ==0 && err == NULL && strings_are_equal(buff_endpoint, TEST_SRM_DPM_FULLENDPOINT_URL), " must be a succesfull endpoint determination %d %ld %s", ret, err, buff_endpoint);
	gfal_check_GError(&err);	
	
	ret = gfal_srm_determine_endpoint(&opts, "srm://srm-pps:8443/srm/managerv2?SFN=/castor/cern.ch/grid/dteam/castordev/test-srm-pps_8443-srm2_d0t1-ed6b7013-5329-4f5b", buff_endpoint, 2048, &proto, &err);
	assert_true_with_message( ret ==0 && err == NULL && strings_are_equal(buff_endpoint, "httpg://srm-pps:8443/srm/managerv2"), " must be a succesfull endpoint determination 2 %d %ld %s", ret, err, buff_endpoint);
	gfal_check_GError(&err);
	gfal_handle_freeG(handle);	
}
Beispiel #4
0
static GVarType get_proc(const void *obj,
    const char *name, GVarData *prop, void *udata)
{
    Quark *q = (Quark *) obj;
    Grace *grace = grace_from_quark(q);
    DataColumn col;
    int column;
    
    if (!q) {
        return GVarNil;
    }
    
    if (strings_are_equal(name, "idstr")) {
        prop->str = copy_string(NULL, QIDSTR(q));
        return GVarStr;
    } else
    if (strings_are_equal(name, "active")) {
        prop->boolval = quark_is_active(q);
        return GVarBool;
    }
    
    switch (quark_fid_get(q)) {
    case QFlavorSSD:
        if (strings_are_equal(name, "nrows")) {
            prop->num = ssd_get_nrows(q);
            return GVarNum;
        } else
        if (strings_are_equal(name, "ncols")) {
            prop->num = ssd_get_ncols(q);
            return GVarNum;
        } else
        if ((column = ssd_get_column_by_name(q, name)) >= 0) {
            prop->arr = ssd_get_darray(q, column);
            return GVarArr;
        } else {
            return GVarNil;
        }
        break;
    case QFlavorSet:
        if (strings_are_equal(name, "length")) {
            prop->num = set_get_length(q);
            return GVarNum;
        } else
        if ((col = get_dataset_col_by_name(grace, name)) != DATA_BAD) {
            prop->arr = set_get_darray(q, col);
            return GVarArr;
        } else {
            return GVarNil;
        }
        break;
    default:
        return GVarNil;
        break;
    }
}
static void check_type_read_and_store_info(char *type, char *name, double coordinates_center_x, double coordinates_center_y)
{
	if (strings_are_equal(type, "input")) {
		create_input_list (type, name, coordinates_center_x, coordinates_center_y);
	}
	else if (strings_are_equal(type, "output")) {
		create_output_list (type, name, coordinates_center_x, coordinates_center_y);
	}
	else {	//it is a cell
		create_cell_list (type, name, coordinates_center_x, coordinates_center_y);
	}
}
Beispiel #6
0
void gfal2_test_gfal_srm_getTURLS_pipeline_success()
{
	setup_mock_srm();
	setup_mock_bdii();
	int i1;
#if USE_MOCK
	define_se_endpoints = calloc(sizeof(char*), 4); // set the response of the MDS layer for endpoint
	for(i1=0;i1 <3; ++i1)
		define_se_endpoints[i1]= strdup(TEST_SRM_DPM_FULLENDPOINT_URL);
	define_se_types= calloc(sizeof(char*), 4);
	char* types[] = { "srm_v1", "srm_v2", "srm_v1"};
	for(i1=0;i1 <3; ++i1)
		define_se_types[i1]= strdup(types[i1]);	


	will_respond(srm_mock_srm_context_init, 0, want_non_null(context), want_string(srm_endpoint, TEST_SRM_DPM_FULLENDPOINT_URL));
	defined_get_output = calloc(sizeof(struct srmv2_pinfilestatus),3);
	defined_get_output[0].turl= strdup(TEST_SRM_TURL_EXAMPLE1);
	defined_get_output[1].status= ENOENT;
	defined_get_output[1].explanation = strdup("err msg");
	defined_get_output[2].turl = strdup(TEST_SRM_TURL_EXAMPLE1);
	will_respond(srm_mock_srm_prepare_to_get, 3, want_non_null(context), want_non_null(input), want_non_null(output));
	always_return(srm_mock_srm_srmv2_filestatus_delete,0);
	always_return(srm_mock_srm_srmv2_pinfilestatus_delete,0);
#endif
	GError* tmp_err=NULL;
	gfal_handle handle  = gfal_initG(&tmp_err);
	assert_true_with_message(handle != NULL, " handle is not properly allocated");
	if(handle==NULL)
		return;
	gfal_srmv2_opt opts;
	gfal_srm_opt_initG(&opts, handle);
	gfal_plugins_instance(handle, NULL);
	gfal_srm_result* resu=NULL;
	char* surls[] = {TEST_SRM_VALID_SURL_EXAMPLE1, TEST_SRM_INVALID_SURL_EXAMPLE2, TEST_SRM_VALID_SURL_EXAMPLE1, NULL};
	int ret = gfal_srm_getTURLS(&opts, surls, &resu, &tmp_err);
	assert_true_with_message(ret ==g_strv_length(surls) && resu != NULL && tmp_err == NULL, " must be a successfull request");
	gfal_check_GError(&tmp_err);
	assert_true_with_message(resu[0].err_code == 0 && *(resu[0].err_str)== '\0' && strings_are_equal(resu[0].turl, TEST_SRM_TURL_EXAMPLE1), 
				" must be a valid turl, maybe the turl has changed %d %ld %s",resu[0].err_code, resu[0].err_str, resu[0].turl);	

	assert_true_with_message(resu[1].err_code == ENOENT && *(resu[1].err_str)!= '\0' && *(resu[1].turl) == '\0', 
				" must be a invalid turl 2 ");	
	assert_true_with_message(resu[2].err_code == 0 && *(resu[2].err_str)== '\0' && strings_are_equal(resu[2].turl, TEST_SRM_TURL_EXAMPLE1), 
				" must be a valid turl 3, maybe the turl has changed ");	
	free(resu);
	gfal_handle_freeG(handle);
}
    Client<HTTP>::Client(
        boost::asio::io_service& io_service,
        http_action ha,
        const std::string& server,
        const std::string& port,        // examples: "default", "8080", "2345", "http", "ftp", etc.
                                        // "default" will become "80" if b_use_ssl is false, or "443" if true
        const std::string& path,
        const std::string& header,
        const std::string& body,        // directly placed into request
        bool b_binary_result,
        const string& username,
        const string& password
    ) :

        // Call base class
        ClientBase<HTTP>::ClientBase(io_service, header, b_binary_result)

    {
        // Set up the type-specific socket.
        socket_=std::make_shared<HTTP>(io_service);

        // Configure the correct default port.
        string actual_port = port;
        if (strings_are_equal(actual_port,"default"))
        {
            actual_port = "80";
        }

        aresolve(ha, server, actual_port, path, header, body, username, password);
    }
Beispiel #8
0
void assert_string_equal_(const char *file, int line, const char *expression, const char *tried, const char *expected) {
    (*get_test_reporter()->assert_true)(
            get_test_reporter(),
            file,
            line,
            strings_are_equal(tried, expected),
            "[%s] should be [%s] but was [%s]\n", expression, show_null_as_the_string_null(expected), show_null_as_the_string_null(tried));
}
Beispiel #9
0
void assert_string_not_equal_(const char *file, int line, const char *tried, const char *expected) {
    (*get_test_reporter()->assert_true)(
            get_test_reporter(),
            file,
            line,
            ! strings_are_equal(tried, expected),
            "[%s] should not match [%s]", show_null_as_the_string_null(tried), show_null_as_the_string_null(expected));
}
Beispiel #10
0
datalog_element *datalog_definition::element_by_name(const char *name) {
  if(name == NULL) return NULL;
  datalog_element *x = element;
  while(x != NULL) {
    if(strings_are_equal(name,x->short_name) == true) return x;
    x = x->next;
  }
  //qDebug() << "Can't find element: " << name << "in definition" << get_msg_number();
  return NULL;
}
Beispiel #11
0
static int set_proc(void *obj,
    const char *name, GVarType type, GVarData prop, void *udata)
{
    Quark *q = (Quark *) obj;
    Grace *grace = grace_from_quark(q);
    DataColumn col;
    int column;
    
    if (!q) {
        return RETURN_FAILURE;
    }

    if (strings_are_equal(name, "idstr") && type == GVarStr) {
        return quark_idstr_set(q, prop.str);
    } else
    if (strings_are_equal(name, "active") && type == GVarBool) {
        return quark_set_active(q, prop.boolval);
    }

    switch (quark_fid_get(q)) {
    case QFlavorSSD:
        if ((column = ssd_get_column_by_name(q, name)) >= 0) {
            return ssd_set_darray(q, column, prop.arr);
        } else {
            return RETURN_FAILURE;
        }
        break;
    case QFlavorSet:
        if ((col = get_dataset_col_by_name(grace, name)) != DATA_BAD) {
            if (set_set_length(q, prop.arr->size) != RETURN_SUCCESS) {
                return RETURN_FAILURE;
            } else {
                return set_set_darray(q, col, prop.arr);
            }
        } else {
            return RETURN_FAILURE;
        }
        break;
    default:
        return RETURN_FAILURE;
        break;
    }
}
Beispiel #12
0
void gfal2_test__gfal_convert_full_surl()
{
	int res = -1;
	char buff[2048];
	GError* tmp_err=NULL;
	res=  gfal_get_fullendpointG(TEST_SRM_DPM_FULLENDPOINT_PREFIX, buff, 2048, &tmp_err);
	assert_true_with_message( res == 0 && strings_are_equal(buff, TEST_SRM_DPM_FULLENDPOINT_URL) && tmp_err==NULL, " must be a successfull endpoint convertion");
	g_clear_error(&tmp_err);
	res=  gfal_get_fullendpointG(TEST_SRM_DPM_FULLENDPOINT_PREFIX, buff, 2, &tmp_err);	
	assert_true_with_message( res != 0 && tmp_err!=NULL && tmp_err->code == ENOBUFS, " must be a buffer to small");	
	g_clear_error(&tmp_err);
}
Beispiel #13
0
    Client<HTTPS>::Client(
        boost::asio::io_service& io_service,
        http_action ha,
        const std::string& server,
        const std::string& port,
        const std::string& path,
        const std::string& header,
        const std::string& body,
        bool b_binary_result,
        const string& username,
        const string& password,
        bool verify_certificate,
        const std::string& cert_file,
        const std::string& private_key_file,
        const std::string& verify_file
    ) :

        // Call base class
        ClientBase<HTTPS>::ClientBase(io_service, header, b_binary_result),

        // Init vars
        // MDM Have the whole world really gone from ssl2 to tls1?
        // asio_context_(boost::asio::ssl::context::sslv23)
        asio_context_(boost::asio::ssl::context::tlsv1)

    {
        if(verify_certificate)
            asio_context_.set_verify_mode(boost::asio::ssl::verify_peer);
        else
            asio_context_.set_verify_mode(boost::asio::ssl::verify_none);

        if(cert_file.size()>0 && private_key_file.size()>0) {
            asio_context_.use_certificate_chain_file(cert_file);
            asio_context_.use_private_key_file(private_key_file, boost::asio::ssl::context::pem);
        }

        if(verify_file.size()>0)
            asio_context_.load_verify_file(verify_file);

        socket_=std::make_shared<HTTPS>(io_service, asio_context_);

        // Configure the correct default port.
        string actual_port = port;
        if (strings_are_equal(actual_port,"default"))
        {
            actual_port = "443";
        }

        aresolve(ha, server, actual_port, path, header, body, username, password);
    }
Beispiel #14
0
static obj_t find_symbol(obj_t name)
{
    obj_t p, sym;
    obj_t sym_name;

    CHECK(is_string(name), "must be string", name);
    for (p = all_symbols_list; !is_null(p); p = pair_cdr(p)) {
	assert(is_pair(p));
	sym = pair_car(p);
	assert(is_symbol(sym));
	sym_name = symbol_name(sym);
	assert(is_string(sym_name));
	if (strings_are_equal(sym_name, name))
	    return sym;
    }
    return EMPTY_LIST;
}
Beispiel #15
0
int save_project(GProject *gp, char *fn)
{
    GrFILE *grf;
    Quark *project = gproject_get_top(gp);
    GUI *gui = gui_from_quark(project);
    int noask_save;
    static int save_unsupported = FALSE;
    int retval;

    if (!project || !fn) {
        return RETURN_FAILURE;
    }
    
    if (fn && strstr(fn, ".agr")) {
        errmsg("Cowardly refusing to overwrite an agr file");
        return RETURN_FAILURE;
    }
    if (!save_unsupported &&
        !yesno("The current format may be unsupported by the final release. Continue?",
            "Yeah, I'm brave!", NULL, "doc/UsersGuide.html#unsupported_format")) {
        return RETURN_FAILURE;
    }
    save_unsupported = TRUE;

    noask_save = gui->noask;
    if (strings_are_equal(gproject_get_docname(gp), fn)) {
        /* If saving under the same name, don't warn about overwriting */
        gui->noask = TRUE;
    }
    
    grf = grfile_openw(fn);
    if (!grf) {
        return RETURN_FAILURE;
    }
    
    gui->noask = noask_save;

    retval = gproject_save(gp, grf);

    grfile_free(grf);
    
    return retval;
}
Beispiel #16
0
static void save_wisdom(void){
    char *final_wisdom;

    final_wisdom = fftw_export_wisdom_to_string();
    
    if (!initial_wisdom ||
        strings_are_equal(initial_wisdom, final_wisdom) != TRUE) {
        FILE *wf;
        wf = gapp_openw(gapp, wisdom_file);
        if (wf) {
            fftw_export_wisdom_to_file(wf);
            gapp_close(wf);
        }
    } 
    
    fftw_free(final_wisdom);
    if (initial_wisdom) {
        fftw_free(initial_wisdom);
    }
}
Beispiel #17
0
void gfal2_test_gfal_srm_determine_endpoint_not_fullG()
{
	
#if USE_MOCK
	int i1;
	setup_mock_bdii();
	char buff_tmp[2048];
	char* p = TEST_SRM_DPM_ENDPOINT_PREFIX+ strlen(GFAL_PREFIX_SRM);
	g_strlcpy(buff_tmp, p, strchr(p, '/')-p+1);
	define_se_endpoints = calloc(sizeof(char*), 4);
	for(i1=0;i1 <3; ++i1)
		define_se_endpoints[i1]= strdup(TEST_SRM_DPM_FULLENDPOINT_URL);
	define_se_types= calloc(sizeof(char*), 4);
	char* types[] = { "srm_v1", "srm_v2", "srm_v1"};
	for(i1=0;i1 <3; ++i1)
		define_se_types[i1]= strdup(types[i1]);	



#endif
	GError* err = NULL;
	char buff_endpoint[2048];
	enum gfal_srm_proto proto;
	gfal_handle handle = gfal_initG(&err);
	assert_true_with_message(handle != NULL, " handle is not properly allocated");
	if(handle==NULL)
		return;
	gfal_srmv2_opt opts;
	gfal_srm_opt_initG(&opts, handle);
	gfal_plugins_instance(handle, NULL);
	int ret =-1;
	ret = gfal_srm_determine_endpoint(&opts, TEST_SRM_DPM_ENDPOINT_PREFIX, buff_endpoint, 2048, &proto, &err);
	assert_true_with_message( ret ==0 && err == NULL && strings_are_equal(buff_endpoint, TEST_SRM_DPM_FULLENDPOINT_URL), " must be a succesfull endpoint determination %d %ld %s", ret, err, buff_endpoint);
	gfal_check_GError(&err);	
	
	ret = gfal_srm_determine_endpoint(&opts, "http://google.com", buff_endpoint, 2048, &proto, &err);
	assert_true_with_message( ret !=0 && err != NULL, "error must be reported %d %s", ret, ((err)?err->message:""));
	g_clear_error(&err);
	gfal_handle_freeG(handle);	
}
Beispiel #18
0
void gfal2_test_gfal_get_endpoint_and_setype_from_bdiiG(){
	GError* err= NULL;
	int i1;
	char buff_endpoint[2048];
	memset(buff_endpoint, '\0', sizeof(char)*2048);
	enum gfal_srm_proto proto;
	
#if USE_MOCK
	setup_mock_bdii();
	char buff_tmp[2048];
	char* p = TEST_SRM_DPM_ENDPOINT_PREFIX+ strlen(GFAL_PREFIX_SRM);
	g_strlcpy(buff_tmp, p, strchr(p, '/')-p+1);
	define_se_endpoints = calloc(sizeof(char*), 4);
	for(i1=0;i1 <3; ++i1)
		define_se_endpoints[i1]= strdup(TEST_SRM_DPM_FULLENDPOINT_URL);
	define_se_types= calloc(sizeof(char*), 4);
	char* types[] = { "srm_v1", "srm_v2", "srm_v1"};
	for(i1=0;i1 <3; ++i1)
		define_se_types[i1]= strdup(types[i1]);	




#endif
	gfal_handle handle = gfal_initG(&err);
	assert_true_with_message(handle != NULL, " handle is not properly allocated");	
	if(handle==NULL)
		return;
	gfal_srmv2_opt opts;
	gfal_srm_opt_initG(&opts, handle);
	char* surl = TEST_SRM_DPM_ENDPOINT_PREFIX;
	int ret = gfal_get_endpoint_and_setype_from_bdiiG(&opts, surl, buff_endpoint, 2048, &proto, &err);
	assert_true_with_message( ret ==0 && err== NULL && strings_are_equal(buff_endpoint, TEST_SRM_DPM_FULLENDPOINT_URL) && proto== PROTO_SRMv2, " must be a valid endpoint resolution");
	gfal_check_GError(&err);
	memset(buff_endpoint, '\0', sizeof(char)*2048);
	ret = gfal_get_endpoint_and_setype_from_bdiiG(&opts, "srm://lxb540dfshhhh9.cern.ch:8446/test/invalid", buff_endpoint, 2048, &proto, &err);
	assert_true_with_message(ret != 0 && err != NULL && err->code==ENXIO && *buff_endpoint== '\0', " must fail, invalid point");
	g_clear_error(&err);
	gfal_handle_freeG(handle);
}
void parse_size_file(char *type, double *width, double *height)
{
    FILE *sizes;
    char buffer[MAX_LINE_CHARS] = {0, };
    char *tmp;
    char delimeter[4] = " \t\n";
    sizes = fopen("NangateLibrarySizes.txt", "r");
    
    if (sizes == NULL) {
        printf("Didn't open Sizes file.\n");
    }
    
    while (fgets(buffer, MAX_LINE_CHARS, sizes) != NULL) {
            tmp = strtok(buffer, delimeter);
            if (tmp == NULL)
                continue;
            if(strings_are_equal(tmp, type)) {
                tmp = strtok(NULL, delimeter);
                *width = (double) atof(tmp);
                tmp = strtok(NULL, delimeter);
                *height = (double) atof(tmp);
            }
	}
}
Beispiel #20
0
	void request_parser::parse_content(request& req)
	{
		if (req.content.empty())
		{
			return;
		}

		std::string standard_type = "application/x-www-form-urlencoded";
		std::string multipart_type = "multipart/form-data";

		std::string content_type = req.header("Content-Type");
		if (content_type.empty() || strings_are_equal(content_type, standard_type, standard_type.size()))
		{
			std::string name, value;
			std::string::size_type pos;
			std::string::size_type old_pos = 0;

			while (true)
			{
				pos = req.content.find_first_of("&=", old_pos);
				if (pos == std::string::npos)
				{
					break;
				}

				if (req.content.at(pos) == '&')
				{
					const char* c_str_ = req.content.c_str() + old_pos;
					while (*c_str_ == '&')
					{
						++c_str_;
						++old_pos;
					}

					if (old_pos >= pos)
					{
						old_pos = ++pos;
						continue;
					}

					name = percent_decode(req.content.substr(old_pos, pos - old_pos));
					req.params.push_back(name_value(name, std::string()));
					old_pos = ++pos;
					continue;
				}

				name = percent_decode(req.content.substr(old_pos, pos - old_pos));
				old_pos = ++pos;

				pos = req.content.find_first_of(";&", old_pos);
				value = percent_decode(req.content.substr(old_pos, pos - old_pos));
				req.params.push_back(name_value(name, value));

				if (pos == std::string::npos)
				{
					break;
				}

				old_pos = ++pos;
			}
		}
		else if (strings_are_equal(multipart_type, content_type, multipart_type.size()))
		{
			std::string b_type = "boundary=";
			std::string::size_type pos = content_type.find(b_type);

			std::string sep1 = content_type.substr(pos + b_type.size());
			if (sep1.find(";") != std::string::npos)
			{
				sep1 = sep1.substr(0, sep1.find(";"));
			}
			sep1.append("\r\n");
			sep1.insert(0, "--");

			std::string sep2 = content_type.substr(pos + b_type.size());
			if (sep2.find(";") != std::string::npos)
			{
				sep2 = sep2.substr(0, sep2.find(";"));
			}
			sep2.append("--\r\n");
			sep2.insert(0, "--");

			std::string::size_type start = req.content.find(sep1);
			std::string::size_type sep_size = sep1.size();
			std::string::size_type old_pos = start + sep_size;

			while (true)
			{
				pos = req.content.find(sep1, old_pos);
				if (pos == std::string::npos)
				{
					break;
				}

				parse_multipart_content(req, req.content.substr(old_pos, pos - old_pos));
				old_pos = pos + sep_size;
			}

			pos = req.content.find(sep2, old_pos);
			if (pos != std::string::npos)
			{
				parse_multipart_content(req, req.content.substr(old_pos, pos - old_pos));
			}
		}
	}
Beispiel #21
0
void wall_clock_proc(void) {
    msg_buf* message = (msg_buf*)request_memory_block();
	  Node* msg_node = (Node*)request_memory_block();
    message->mtype = KCD_REG;
    copy_string("%W", message->mtext);

    //send register cmd to KCD
    msg_node->sender_id = PID_CLOCK;
    msg_node->receiving_id = PID_KCD;
    msg_node->data = message;
    send_message_node(msg_node);

    while (1){
				int neg_1 = -1;
        msg_buf* message = (msg_buf*) receive_message(&neg_1);
        if (message == NULL) {
            continue;
        }
        if (strings_are_equal(message->mtext,"D")) {
            // HH:MM:SS
            int seconds = (int) (g_clock / 1000) % 60 ;
            int minutes = (int) ((g_clock / (1000*60)) % 60);
            int hours   = (int) ((g_clock / (1000*60*60)) % 24);
            msg_buf* mtime;
            Node* msg_node;

            // Generate HH:MM:SS char array
            char output[11];
            output[0] = '0' + hours/10;
            output[1] = '0' + hours%10;
            output[2] = ':';
            output[3] = '0' + minutes/10;
            output[4] = '0' + minutes%10;
            output[5] = ':';
            output[6] = '0' + seconds/10;
            output[7] = '0' + seconds%10;
					  output[8] = '\n';
            output[9] = '\r';
						output[10] = '\0';

            // Send message to display the clock
            mtime = (msg_buf*)request_memory_block();
            mtime->mtype = CRT_DISPLAY;
            copy_string(output, mtime->mtext);

            msg_node = (Node*)request_memory_block();
            msg_node->sender_id = PID_CLOCK;
            msg_node->receiving_id = PID_CRT;
            msg_node->data = mtime;

            send_message_node(msg_node);
        } else if (message->mtext[2] == 'T') {
            // Terminate Displaying of Clock
            display_clock = false;
        } else if (message->mtext[2] == 'R') {
            // Reset Clock
            g_clock = 0;
            display_clock = true;
        } else if (message->mtext[2] == 'S') {
             // Input: %WS HH:MM:SS [12]
            int hour;
            int minute;
            int seconds;

						if (message->mtext[6] != ':' || message->mtext[9] != ':') {
							msg_buf* minv = (msg_buf*)request_memory_block();
							Node* msg_node = (Node*)request_memory_block();
							minv->mtype = CRT_DISPLAY;
							copy_string("Invalid Time for wallclock proc\n\r", minv->mtext);

							msg_node->sender_id = PID_CLOCK;
							msg_node->receiving_id = PID_CRT;
							msg_node->data = minv;

							send_message_node(msg_node);
						} else {
									 // Get Hours
							hour = message->mtext[4] - '0';
							hour *= 10;
							hour += message->mtext[5] - '0';

							// Get Minutes
							minute = message->mtext[7] - '0';
							minute *= 10;
							minute += message->mtext[8] - '0';

							// Get Seconds
							seconds = message->mtext[10] - '0';
							seconds *= 10;
							seconds += message->mtext[11] - '0';

							// Convert HH:MM:SS to ms for g_clock
							g_clock = hour*(1000*60*60) + minute*(1000*60) + seconds*(1000);

							// Enable Displaying of Clock
							display_clock = true;
						}



        }
						release_memory_block(message);
    }
}
Beispiel #22
0
static int compare_want_string(Constraint *constraint, intptr_t comparison) {
    return strings_are_equal((const char *)constraint->expected, (const char *)comparison);
}
Beispiel #23
0
static int leaveCB(TableEvent *event)
{
    SSDataUI *ui = (SSDataUI *) event->anydata;

    int nrows = ssd_get_nrows(ui->q);
    int ncols = ssd_get_ncols(ui->q);
    int format;
    double value;
    
    int changed = FALSE;
    
    GraceApp *gapp = gapp_from_quark(ui->q);
    
    if (event->row < 0 || event->col < 0 || event->col > ncols) {
        return TRUE;
    }
    
    if (event->row >= nrows && !string_is_empty(event->value)) {
        if (ssd_set_nrows(ui->q, event->row + 1) == RETURN_SUCCESS) {
            changed = TRUE;
        }
    }
    
    if (event->col == ncols && !string_is_empty(event->value)) {
        if (parse_date_or_number(get_parent_project(ui->q),
            event->value, FALSE, get_date_hint(gapp), &value) == RETURN_SUCCESS) {
            format = FFORMAT_NUMBER;
        } else {
            format = FFORMAT_STRING;
        }
        if (ssd_add_col(ui->q, format)) {
            ncols++;
            changed = TRUE;
        }
    }
    
    if (event->col < ncols) {
        char *old_value = get_cell_content(ui, event->row, event->col, &format);
        if (!strings_are_equal(old_value, event->value)) {
            switch (format) {
            case FFORMAT_STRING:
                if (ssd_set_string(ui->q, event->row, event->col, event->value) ==
                    RETURN_SUCCESS) {
                    quark_dirtystate_set(ui->q, TRUE);
                    changed = TRUE;
                }
                break;    
            default:
                if (graal_eval_expr(grace_get_graal(gapp->grace),
                    event->value, &value, gproject_get_top(gapp->gp)) == RETURN_SUCCESS) {

                    unsigned int prec;
                    char buf[32];
                    double val;

                    prec = project_get_prec(get_parent_project(ui->q));
                    sprintf(buf, "%.*g", prec, value);

                    if (parse_date_or_number(get_parent_project(ui->q),
                        buf, FALSE, get_date_hint(gapp), &val) == RETURN_SUCCESS) {

                        if (ssd_set_value(ui->q, event->row, event->col, val) == RETURN_SUCCESS) {
                            quark_dirtystate_set(ui->q, TRUE);
                            changed = TRUE;
                        }
                    }
                } else {
                    errmsg("Can't parse input value");
                    return FALSE;
                }
                break;
            }
        }
    }
    
    if (changed) {
        snapshot_and_update(gapp->gp, FALSE);
    }

    return TRUE;
}
static bool actual_value_not_necessary_for(Constraint *constraint, const char *actual_string, const char *actual_value_string) {
    (void)constraint; // UNUSED!
    return strings_are_equal(actual_string, actual_value_string) ||
            strings_are_equal(actual_string, "true") ||
            strings_are_equal(actual_string, "false");
}
Beispiel #25
0
static bool compare_want_string(Constraint *constraint, intptr_t actual) {
    return strings_are_equal((const char *)constraint->expected_value, (const char *)actual);
}