Exemple #1
0
static void execute_method(xmlrpc_value **result, char *method, xmlrpc_value *params) {
    xmlrpc_server_info *serverInfo;

    serverInfo = xmlrpc_server_info_new(&env, server);
    *result = xmlrpc_client_call_server_params(&env, serverInfo, method, params);
    check_fault();
}
Exemple #2
0
// call PS FeedIndex for a given destination
int MyFeedIndex(struct soap *soap, glite_jpis_context_t ctx, long int uniqueid, const char *dest)
{
	struct _jpelem__FeedIndex		in;
	struct _jpelem__FeedIndexResponse 	out;
//	struct jptype__primaryQuery     	query;
//	struct jptype__stringOrBlob		value;
//	struct xsd__base64Binary		blob;
	int 					i, dest_index, status;
	glite_jp_is_conf *conf = ctx->conf;

	lprintf("(%ld) for %s called\n", uniqueid, dest);

	if (refresh_gsoap(ctx, soap) != 0)
		return glite_jpis_stack_error(ctx->jpctx, EINVAL, "can't refresh credentials");

	memset(&in, 0, sizeof(in));

	for (i=0; conf->attrs[i]; i++) ;
	in.__sizeattributes = i;
	in.attributes = conf->attrs;

	if ((dest_index = find_dest_index(conf, uniqueid)) < 0)
		return glite_jpis_stack_error(ctx->jpctx, EINVAL, "internal error (feed index %ld not found)", uniqueid);

	soap_begin(soap);
	for (i=0; conf->feeds[dest_index]->query[i].attr; i++);
	GLITE_SECURITY_GSOAP_LIST_CREATE(soap, &in, conditions, struct jptype__primaryQuery, i);

	for (i=0; conf->feeds[dest_index]->query[i].attr; i++) {
		if (glite_jpis_QueryCondToSoap(soap, &conf->feeds[dest_index]->query[i], 
				GLITE_SECURITY_GSOAP_LIST_GET(in.conditions, i)) != SOAP_OK) {
			soap_end(soap);
			return glite_jpis_stack_error(ctx->jpctx, EINVAL, "error during conds conversion");
		}
	}

	in.history = conf->feeds[dest_index]->history;
	in.continuous = conf->feeds[dest_index]->continuous;
	in.destination = ctx->hname;
	lprintf("(%ld) destination IS: '%s'\n", uniqueid, ctx->hname);

	if (check_fault(soap,soap_call___jpsrv__FeedIndex(soap,dest,"", &in, &out)) != 0) {
		fprintf(stderr, "\n");
		glite_jpis_unlockFeed(ctx, uniqueid);
		glite_jpis_stack_error(ctx->jpctx, EIO, "soap_call___jpsrv__FeedIndex() returned error %d", soap->error);
		soap_end(soap);
		return EIO;
	}
	else {
		status = (conf->feeds[dest_index]->history ? GLITE_JP_IS_STATE_HIST : 0) | (conf->feeds[dest_index]->continuous ? GLITE_JP_IS_STATE_CONT : 0);
		lprintf("(%ld) FeedId: %s\n", uniqueid, out.feedId);
		lprintf("(%ld) Expires: %s", uniqueid, ctime(&out.feedExpires));
		glite_jpis_initFeed(ctx, uniqueid, out.feedId, time(NULL) + (out.feedExpires - time(NULL)) / 2, status);
		glite_jpis_unlockFeed(ctx, uniqueid);
	}

	soap_end(soap);

	return 0;
}
Exemple #3
0
int MyFeedRefresh(struct soap *soap, glite_jpis_context_t ctx, long int uniqueid, const char *dest, int status, const char *feedid)
{
	struct _jpelem__FeedIndexRefresh		in;
	struct _jpelem__FeedIndexRefreshResponse 	out;

	lprintf("(%ld) for %s called, status = %d\n", uniqueid, feedid, status);

	if (refresh_gsoap(ctx, soap) != 0)
		return glite_jpis_stack_error(ctx->jpctx, EINVAL, "can't refresh credentials");

	soap_begin(soap);
	memset(&in, 0, sizeof(in));
	in.feedId = soap_strdup(soap, feedid);
	if (check_fault(soap,soap_call___jpsrv__FeedIndexRefresh(soap,dest,"", &in, &out)) != 0) {
		fprintf(stderr, "\n");
		glite_jpis_unlockFeed(ctx, uniqueid);
		glite_jpis_stack_error(ctx->jpctx, EIO, "soap_call___jpsrv__FeedRefresh() returned error %d", soap->error);
		soap_end(soap);
		return EIO;
	}
	else {
		status &= (~GLITE_JP_IS_STATE_ERROR);
		lprintf("(%ld) FeedId: %s\n", uniqueid, feedid);
		lprintf("(%ld) Expires: %s", uniqueid, ctime(&out.feedExpires));
		glite_jpis_initFeed(ctx, uniqueid, feedid, time(NULL) + (out.feedExpires - time(NULL)) / 2, status);
		glite_jpis_unlockFeed(ctx, uniqueid);
	}

	soap_end(soap);
	return 0;
}
Exemple #4
0
static void get_int64(xmlrpc_value *value, int64_t *num) {
    xmlrpc_int64 tmp;
    assert(xmlrpc_value_type(value) == XMLRPC_TYPE_I8);
    xmlrpc_read_i8(&env, value, &tmp);
    check_fault();

    *num = (int64_t) tmp;
}
Exemple #5
0
int main(int argc, char * const argv[]) {
	struct soap soap, soap_comm;
	struct _jpelem__QueryJobs qj;
	char *server, *example_file, *query_file, *test_file;
	const char *prog_name;
	int retval, opt, example_fd, query_fd, test_fd;
	format_t format = FORMAT_XML;

	prog_name = server = NULL;
	example_file = query_file = test_file = NULL;
	query_fd = example_fd = test_fd = -1;
	retval = 1;

	soap_init(&soap);
	soap_set_namespaces(&soap, jp__namespaces);

	/* 
	 * Soap with registered plugin can't be used for reading XML.
	 * For communications with JP IS glite_gsplugin needs to be registered yet.
	 */
	soap_init(&soap_comm);
	soap_set_namespaces(&soap_comm, jp__namespaces);
	soap_register_plugin(&soap_comm, glite_gsplugin);

	/* program name */
	prog_name = strrchr(argv[0], '/');
	if (prog_name) prog_name++;
	else prog_name = argv[0];

	if (argc <= 1) {
		usage(prog_name);
		goto cleanup;
	}

	/* handle arguments */
	while ((opt = getopt_long(argc, argv, get_opt_string, opts, NULL)) != EOF) switch (opt) {
		case 'i': 
			free(server);
			server = strdup(optarg);
			break;
		case 'e':
			free(example_file);
			example_file = strdup(optarg);
			break;
		case 'q':
			free(query_file);
			query_file = strdup(optarg);
			break;
		case 't':
			free(test_file);
			test_file = strdup(optarg);
			break;
		case 'f':
			if (strcasecmp(optarg, "xml") == 0) format = FORMAT_XML;
			else if (strcasecmp(optarg, "strippedxml") == 0) format = FORMAT_STRIPPEDXML;
			else format = FORMAT_HR;
			break;
		default:
			usage(prog_name);
			goto cleanup;
	}
	if (optind < argc) {
		usage(prog_name);
		goto cleanup;
	}
	if (!server) server = strdup(DEFAULT_JPIS);
#ifdef SOAP_XML_INDENT
	if (format != FORMAT_STRIPPEDXML) soap_omode(&soap, SOAP_XML_INDENT);
#endif


	/* prepare steps according to the arguments */
	if (query_file) {
		if (strcmp(query_file, "-") == 0) query_fd = STDIN_FILENO;
		else if ((query_fd = open(query_file, 0)) < 0) {
			fprintf(stderr, "error opening %s: %s\n", query_file, strerror(errno));
			goto cleanup;
		}
		free(query_file);
		query_file = NULL;
	}
	if (example_file) {
		if (strcmp(example_file, "-") == 0) example_fd = STDOUT_FILENO;
		else if ((example_fd = creat(example_file, S_IREAD | S_IWRITE | S_IRGRP)) < 0) {
			fprintf(stderr, "error creating %s: %s\n", example_file, strerror(errno));
			goto cleanup;
		}
		free(example_file);
		example_file = NULL;
	}
	if (test_file) {
		if (strcmp(test_file, "-") == 0) test_fd = STDIN_FILENO;
		else if ((test_fd = open(test_file, 0)) < 0) {
			fprintf(stderr, "error opening %s: %s\n", test_file, strerror(errno));
			goto cleanup;
		}
		free(test_file);
		test_file = NULL;
	}

	/* the dump action */
	if (example_fd >= 0) {
		if (query_example_dump(&soap, example_fd) != 0) {
			fprintf(stderr, "Error dumping example query XML.\n");
		}
	}

	/* the test XML file action */
	if (test_fd >= 0) {
		soap_begin(&soap);
		if (query_recv(&soap, test_fd, &qj) != 0) {
			fprintf(stderr, "test: Error getting query XML\n");
		} else {
			query_format(&soap, format, stdout, &qj);
		}
		soap_end(&soap);
	}

	/* query action */
	if (query_fd >= 0) {
		struct _jpelem__QueryJobs in;
		struct _jpelem__QueryJobsResponse out;
		int ret;

		soap_begin(&soap);
		memset(&in, 0, sizeof(in));
		memset(&out, 0, sizeof(out));
		/* 
		 * Right way would be copy data from client query structure to IS query
		 * structure. Just ugly retype to client here.
		 */
		if (query_recv(&soap, query_fd, (struct _jpelem__QueryJobs *)&in) != 0) {
			fprintf(stderr, "query: Error getting query XML\n");
		} else {
			fprintf(stderr, "query: using JPIS %s\n\n", server);
			query_print(stderr, &in);
			fprintf(stderr, "\n");
			soap_begin(&soap_comm);
			ret = check_fault(&soap_comm, soap_call___jpsrv__QueryJobs(&soap_comm, server, "", &in, &out));
			if (ret == 0) {
				queryresult_format(&soap, format, stdout, (struct _jpelem__QueryJobsResponse *)&out);
			} else {
				soap_end(&soap_comm);
				soap_end(&soap);
				goto cleanup;
			}
			soap_end(&soap_comm);
		}
		soap_end(&soap);
	}

	retval = 0;

cleanup:
	soap_done(&soap);
	soap_done(&soap_comm);
	if (example_fd > STDERR_FILENO) close(example_fd);
	if (query_fd > STDERR_FILENO) close(query_fd);
	if (test_fd > STDERR_FILENO) close(test_fd);
	free(server);
	free(example_file);
	free(query_file);
	free(test_file);

	return retval;
}
Exemple #6
0
static void get_torrent_list(torrent_array **result) {
    size_t size;
    xmlrpc_value *xml_array, *params;

    params = xmlrpc_array_new(&env);
    xmlrpc_array_append_item(&env, params, xmlrpc_string_new(&env, "main"));
    xmlrpc_array_append_item(&env, params, xmlrpc_string_new(&env, "d.hash="));
    xmlrpc_array_append_item(&env, params, xmlrpc_string_new(&env, "d.name="));
    xmlrpc_array_append_item(&env, params, xmlrpc_string_new(&env, "d.is_active="));
    xmlrpc_array_append_item(&env, params, xmlrpc_string_new(&env, "d.state="));
    xmlrpc_array_append_item(&env, params, xmlrpc_string_new(&env, "d.bytes_done="));
    xmlrpc_array_append_item(&env, params, xmlrpc_string_new(&env, "d.size_bytes="));
    xmlrpc_array_append_item(&env, params, xmlrpc_string_new(&env, "d.up.rate="));
    xmlrpc_array_append_item(&env, params, xmlrpc_string_new(&env, "d.down.rate="));
    xmlrpc_array_append_item(&env, params, xmlrpc_string_new(&env, "d.down.total="));
    xmlrpc_array_append_item(&env, params, xmlrpc_string_new(&env, "d.ratio="));
    check_fault();

    execute_proxy_method(&xml_array, "d.multicall", params);
    check_fault(&env);
    assert(xmlrpc_value_type(xml_array) == XMLRPC_TYPE_ARRAY);

    XMLRPC_ASSERT_ARRAY_OK(xml_array);
    size = xmlrpc_array_size(&env, xml_array);
    check_fault(&env);

    if (size <= 0)
        goto finish;
        
    *result = torrent_array_new(size);
    for (size_t i = 0; i < size; ++i) {
        size_t tarray_size;
        xmlrpc_value *tarray = NULL;

        xmlrpc_array_read_item(&env, xml_array, i, &tarray);
        check_fault(&env);
        assert(xmlrpc_value_type(tarray) == XMLRPC_TYPE_ARRAY);

        XMLRPC_ASSERT_ARRAY_OK(tarray);
        tarray_size = xmlrpc_array_size(&env, tarray);

        for (size_t j = 0; j < tarray_size; ++j) {
            xmlrpc_value *item = NULL;

            xmlrpc_array_read_item(&env, tarray, j, &item);
            check_fault(&env);

            switch (j) {
                case 0:
                    get_string(item, &(*result)->torrents[i]->hash);
                    break;
                case 1:
                    get_string(item, &(*result)->torrents[i]->name);
                    break;
                case 2:
                    get_bool_from_int64(item, &(*result)->torrents[i]->active);
                    break;
                case 3:
                    get_bool_from_int64(item, &(*result)->torrents[i]->started);
                    break;
                case 4:
                    get_int64(item, &(*result)->torrents[i]->done_bytes);
                    break;
                case 5:
                    get_int64(item, &(*result)->torrents[i]->size_bytes);
                    break;
                case 6:
                    get_int64(item, &(*result)->torrents[i]->up_rate);
                    break;
                case 7:
                    get_int64(item, &(*result)->torrents[i]->down_rate);
                    break;
                case 8:
                    get_int64(item, &(*result)->torrents[i]->down_total);
                    break;
                case 9:
                    get_int64(item, &(*result)->torrents[i]->ratio);
                    break;
                default:
                    ;
            }
            xmlrpc_DECREF(item);
        }
        xmlrpc_DECREF(tarray);
    }

finish:
    xmlrpc_DECREF(xml_array);
}
Exemple #7
0
static void get_string(xmlrpc_value *value, const char **string) {
    assert(xmlrpc_value_type(value) == XMLRPC_TYPE_STRING);
    xmlrpc_read_string(&env, value, string);
    check_fault();
}
Exemple #8
0
static void execute_proxy_method(xmlrpc_value **result, char *method, xmlrpc_value *params) {
    *result = xmlrpc_call_scgi_server_params(&env, server, port, method, params);
    check_fault();
}
Exemple #9
0
static void init() {
    xmlrpc_env_init(&env);

    xmlrpc_client_init2(&env, XMLRPC_CLIENT_NO_FLAGS, NAME, VERSION, NULL, 0);
    check_fault(&env);
}