diff --git a/c/autogen/include/xen/api/xen_common.h b/c/autogen/include/xen/api/xen_common.h index 0817c88..43882a5 100644 --- a/c/autogen/include/xen/api/xen_common.h +++ b/c/autogen/include/xen/api/xen_common.h @@ -1,19 +1,19 @@ /* * Copyright (c) Citrix Systems, Inc. * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * + * * 1) Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. - * + * * 2) Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS @@ -45,6 +45,14 @@ #endif #endif +#ifndef XEN_API_TYPE +#ifdef __cplusplus +#define XEN_API_TYPE type_name +#else +#define XEN_API_TYPE typename +#endif +#endif + #include "xen_api_version.h" #include "xen/api/xen_host_decl.h" #include "xen/api/xen_task_decl.h" diff --git a/c/autogen/src/xen_common.c b/c/autogen/src/xen_common.c index d5c78d0..ad3c3d6 100644 --- a/c/autogen/src/xen_common.c +++ b/c/autogen/src/xen_common.c @@ -1,19 +1,19 @@ /* * Copyright (c) Citrix Systems, Inc. * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * + * * 1) Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. - * + * * 2) Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS @@ -259,7 +259,7 @@ xen_session_slave_local_login_with_password(xen_call_func call_func, void *handl call_raw(session, "session.slave_local_login_with_password", params, 2, &abstract_type_string, &session->session_id); - + if (session->ok) { //assume the latest api version @@ -340,9 +340,9 @@ bool abstract_value params[] = { }; - + abstract_type result_type = abstract_type_string_set; - + *result = NULL; xen_call_(session, "session.get_all_subject_identifiers", params, 0, &result_type, result); return session->ok; @@ -355,9 +355,9 @@ xen_session_get_all_subject_identifiers_async(xen_session *session, xen_task *re abstract_value params[] = { }; - + abstract_type result_type = abstract_type_string; - + *result = NULL; xen_call_(session, "Async.session.get_all_subject_identifiers", params, 0, &result_type, result); return session->ok; @@ -373,7 +373,7 @@ xen_session_logout_subject_identifier(xen_session *session, const char *subject_ .u.string_val = subject_identifier } }; - xen_call_(session, "session.logout_subject_identifier", params, 1, NULL, NULL); + xen_call_(session, "session.logout_subject_identifier", params, 1, NULL, NULL); return session->ok; } @@ -386,11 +386,11 @@ xen_session_logout_subject_identifier_async(xen_session *session, xen_task *resu { .type = &abstract_type_string, .u.string_val = subject_identifier } }; - + abstract_type result_type = abstract_type_string; *result = NULL; - XEN_CALL_("Async.session.logout_subject_identifier"); + XEN_CALL_("Async.session.logout_subject_identifier"); return session->ok; } @@ -494,7 +494,7 @@ static const struct_member xen_session_record_struct_members[] = const abstract_type xen_session_record_abstract_type_ = { - .typename = STRUCT, + .XEN_API_TYPE = STRUCT, .struct_size = sizeof(xen_session_record), .member_count = sizeof(xen_session_record_struct_members) / sizeof(struct_member), @@ -531,7 +531,7 @@ xen_uuid_string_to_bytes(char *uuid, char **bytes) unsigned int buf[16]; *bytes = NULL; - + if (strlen(uuid) != 36) return false; @@ -774,7 +774,7 @@ static int count_children(xmlNode *n, const char *name) static void destring(xen_session *s, xmlChar *name, const abstract_type *type, void *value) { - switch (type->typename) + switch (type->XEN_API_TYPE) { case STRING: { @@ -840,7 +840,7 @@ static void parse_into(xen_session *s, xmlNode *value_node, return; } - switch (result_type->typename) + switch (result_type->XEN_API_TYPE) { case STRING: { @@ -1214,7 +1214,7 @@ static void parse_into(xen_session *s, xmlNode *value_node, static size_t size_of_member(const abstract_type *type) { - switch (type->typename) + switch (type->XEN_API_TYPE) { case STRING: return sizeof(char *); @@ -1322,7 +1322,7 @@ static void parse_fault(xen_session *session, xmlXPathContextPtr xpathCtx) static void parse_failure(xen_session *session, xmlNode *node) { abstract_type error_description_type = - { .typename = SET, + { .XEN_API_TYPE = SET, .child = &abstract_type_string }; arbitrary_set *error_descriptions; @@ -1379,7 +1379,7 @@ static void parse_result(xen_session *session, const char *result, { parse_fault(session, xpathCtx); - xmlXPathFreeContext(xpathCtx); + xmlXPathFreeContext(xpathCtx); xmlFreeDoc(doc); return; } @@ -1390,7 +1390,7 @@ static void parse_result(xen_session *session, const char *result, parse_fault(session, xpathCtx); xmlXPathFreeObject(xpathObj); - xmlXPathFreeContext(xpathCtx); + xmlXPathFreeContext(xpathCtx); xmlFreeDoc(doc); return; } @@ -1402,7 +1402,7 @@ static void parse_result(xen_session *session, const char *result, if (status_code == NULL) { xmlXPathFreeObject(xpathObj); - xmlXPathFreeContext(xpathCtx); + xmlXPathFreeContext(xpathCtx); xmlFreeDoc(doc); server_error(session, "Server response does not have a Status"); return; @@ -1414,8 +1414,8 @@ static void parse_result(xen_session *session, const char *result, xmlFree(status_code); xmlXPathFreeObject(xpathObj); - xmlXPathFreeContext(xpathCtx); - xmlFreeDoc(doc); + xmlXPathFreeContext(xpathCtx); + xmlFreeDoc(doc); return; } @@ -1429,12 +1429,12 @@ static void parse_result(xen_session *session, const char *result, static void -make_body_add_type(enum abstract_typename typename, abstract_value *v, +make_body_add_type(enum abstract_typename XEN_API_TYPE, abstract_value *v, xmlNode *params_node) { char buf[20]; char *encoded = NULL; - switch (typename) + switch (XEN_API_TYPE) { case STRING: encoded = (char *)xmlEncodeEntitiesReentrant(NULL, (xmlChar*)v->u.string_val); @@ -1455,7 +1455,7 @@ make_body_add_type(enum abstract_typename typename, abstract_value *v, case BOOL: add_param(params_node, "boolean", v->u.bool_val ? "1" : "0"); break; - + case VOID: add_param(params_node, "string", ""); break; @@ -1507,8 +1507,8 @@ make_body_add_type(enum abstract_typename typename, abstract_value *v, arbitrary_map *map_val = v->u.struct_val; xmlNode *param_node = add_param_struct(params_node); for (size_t i = 0; i < map_val->size; i++) { - enum abstract_typename typename_key = member[0].type->typename; - enum abstract_typename typename_val = member[1].type->typename; + enum abstract_typename typename_key = member[0].type->XEN_API_TYPE; + enum abstract_typename typename_val = member[1].type->XEN_API_TYPE; int offset_key = member[0].offset; int offset_val = member[1].offset; int struct_size = v->type->struct_size; @@ -1565,7 +1565,7 @@ make_body(const char *method_name, abstract_value params[], int param_count) for (int p = 0; p < param_count; p++) { abstract_value *v = params + p; - make_body_add_type(v->type->typename, v, params_node); + make_body_add_type(v->type->XEN_API_TYPE, v, params_node); } xmlBufferPtr buffer = xmlBufferCreate(); @@ -1591,7 +1591,7 @@ add_struct_value(const struct abstract_type *type, void *value, const char *type, const char *val), const char *key, xmlNode *node) { - switch (type->typename) + switch (type->XEN_API_TYPE) { case REF: case STRING: @@ -1683,7 +1683,7 @@ add_struct_value(const struct abstract_type *type, void *value, break; case DATETIME: - { + { char buf[255]; struct tm *tm = gmtime((time_t*)value); strftime(buf, sizeof(buf), "%Y%m%dT%H:%M:%S", tm); @@ -1700,13 +1700,13 @@ add_struct_value(const struct abstract_type *type, void *value, static const char * get_val_as_string(const struct abstract_type *type, void *value) { - switch (type->typename) + switch (type->XEN_API_TYPE) { case REF: { char *buf = NULL; arbitrary_record_opt *val = *(arbitrary_record_opt **)value; - + if (val != NULL) { if (val->is_record) @@ -1875,28 +1875,28 @@ xen_strdup_(const char *in) } -const abstract_type abstract_type_string = { .typename = STRING }; -const abstract_type abstract_type_int = { .typename = INT }; -const abstract_type abstract_type_float = { .typename = FLOAT }; -const abstract_type abstract_type_bool = { .typename = BOOL }; -const abstract_type abstract_type_datetime = { .typename = DATETIME }; -const abstract_type abstract_type_ref = { .typename = REF }; +const abstract_type abstract_type_string = { .XEN_API_TYPE = STRING }; +const abstract_type abstract_type_int = { .XEN_API_TYPE = INT }; +const abstract_type abstract_type_float = { .XEN_API_TYPE = FLOAT }; +const abstract_type abstract_type_bool = { .XEN_API_TYPE = BOOL }; +const abstract_type abstract_type_datetime = { .XEN_API_TYPE = DATETIME }; +const abstract_type abstract_type_ref = { .XEN_API_TYPE = REF }; const abstract_type abstract_type_string_set = { - .typename = SET, + .XEN_API_TYPE = SET, .child = &abstract_type_string }; const abstract_type abstract_type_int_set = { - .typename = SET, + .XEN_API_TYPE = SET, .child = &abstract_type_int }; const abstract_type abstract_type_ref_set = { - .typename = SET, + .XEN_API_TYPE = SET, .child = &abstract_type_ref }; @@ -1919,7 +1919,7 @@ static const struct struct_member string_ref_members[] = }; const abstract_type abstract_type_string_ref_map = { - .typename = MAP, + .XEN_API_TYPE = MAP, .struct_size = sizeof(xen_string_ref_map_contents), .members = string_ref_members }; @@ -1937,7 +1937,7 @@ static const struct struct_member string_int_members[] = }; const abstract_type abstract_type_string_int_map = { - .typename = MAP, + .XEN_API_TYPE = MAP, .struct_size = sizeof(xen_string_int_map_contents), .members = string_int_members }; @@ -1955,7 +1955,7 @@ static const struct struct_member string_string_members[] = }; const abstract_type abstract_type_string_string_map = { - .typename = MAP, + .XEN_API_TYPE = MAP, .struct_size = sizeof(xen_string_string_map_contents), .members = string_string_members }; @@ -1973,7 +1973,7 @@ static struct struct_member int_float_members[] = }; const abstract_type abstract_type_int_float_map = { - .typename = MAP, + .XEN_API_TYPE = MAP, .struct_size = sizeof(xen_int_float_map_contents), .members = int_float_members }; @@ -1991,7 +1991,7 @@ static struct struct_member int_int_members[] = }; const abstract_type abstract_type_int_int_map = { - .typename = MAP, + .XEN_API_TYPE = MAP, .struct_size = sizeof(xen_int_int_map_contents), .members = int_int_members }; @@ -2009,7 +2009,7 @@ static struct struct_member int_string_set_members[] = }; const abstract_type abstract_type_int_string_set_map = { - .typename = MAP, + .XEN_API_TYPE = MAP, .struct_size = sizeof(xen_int_string_set_map_contents), .members = int_string_set_members }; @@ -2025,9 +2025,9 @@ static struct struct_member string_string_set_members[] = .offset = offsetof(xen_string_string_set_map_contents, val) } }; -const abstract_type abstract_type_string_string_set_map = +const abstract_type abstract_type_string_string_set_map = { - .typename = MAP, + .XEN_API_TYPE = MAP, .struct_size = sizeof(xen_string_string_set_map_contents), .members = string_string_set_members }; @@ -2043,9 +2043,9 @@ static struct struct_member string_string_string_map_members[] = .offset = offsetof(xen_string_string_string_map_map_contents, val) } }; -const abstract_type abstract_type_string_string_string_map_map = +const abstract_type abstract_type_string_string_string_map_map = { - .typename = MAP, + .XEN_API_TYPE = MAP, .struct_size = sizeof(xen_string_string_string_map_map_contents), .members = string_string_string_map_members }; diff --git a/c/autogen/src/xen_event_batch.c b/c/autogen/src/xen_event_batch.c index add2eb3..51afa39 100644 --- a/c/autogen/src/xen_event_batch.c +++ b/c/autogen/src/xen_event_batch.c @@ -46,7 +46,7 @@ static const struct_member xen_event_batch_struct_members [] = { }; const abstract_type xen_event_batch_abstract_type_ = { - .typename = STRUCT, + .XEN_API_TYPE = STRUCT, .struct_size = sizeof (xen_event_batch), .member_count = sizeof (xen_event_batch_struct_members) / sizeof (struct_member), diff --git a/c/gen_c_binding.ml b/c/gen_c_binding.ml index cce18c8..1b59d84 100644 --- a/c/gen_c_binding.ml +++ b/c/gen_c_binding.ml @@ -733,7 +733,7 @@ extern enum %s const abstract_type %s_abstract_type_ = { - .typename = ENUM, + .XEN_API_TYPE = ENUM, .enum_marshaller = (const char *(*)(int))&%s_to_string, .enum_demarshaller = @@ -755,7 +755,7 @@ const abstract_type %s_abstract_type_ = print "const abstract_type %s_set_abstract_type_ = { - .typename = SET, + .XEN_API_TYPE = SET, .child = &%s_abstract_type_ }; @@ -937,7 +937,7 @@ static const struct_member %s_struct_members[] = const abstract_type %s_abstract_type_ = { - .typename = MAP, + .XEN_API_TYPE = MAP, .struct_size = sizeof(%s_struct_members), .member_count = sizeof(%s_struct_members) / sizeof(struct_member), @@ -1141,7 +1141,7 @@ and write_impl {name=classname; contents; messages; _} out_chan = const abstract_type %s_abstract_type_ = { - .typename = STRUCT, + .XEN_API_TYPE = STRUCT, .struct_size = sizeof(%s), .member_count = sizeof(%s_struct_members) / sizeof(struct_member), @@ -1154,7 +1154,7 @@ const abstract_type %s_abstract_type_ = print "const abstract_type %s_set_abstract_type_ = { - .typename = SET, + .XEN_API_TYPE = SET, .child = &%s_abstract_type_ };\n\n\n" record_tn record_tn; @@ -1174,7 +1174,7 @@ const abstract_type %s_abstract_type_ = const abstract_type abstract_type_string_%s_map = { - .typename = MAP, + .XEN_API_TYPE = MAP, .struct_size = sizeof(%s_map_contents), .members = %s_members };\n\n\n" mappingName mappingName record_tn mappingName record_tn mappingName mappingName; diff --git a/c/templates/Makefile.mustache b/c/templates/Makefile.mustache index e92d14f..6e55a7a 100644 --- a/c/templates/Makefile.mustache +++ b/c/templates/Makefile.mustache @@ -64,8 +64,8 @@ LIBXENAPI_OBJS = $(patsubst %.c, %.o, $(wildcard src/*.c)) TEST_PROGRAMS = $(patsubst %.c, %, $(wildcard test/*.c)) -.PHONY: all -all: $(TEST_PROGRAMS) +%.o: %.c %.h + $(CC) -o $@ $< libxenserver.so: libxenserver.so.{{API_VERSION_MAJOR}} ln -sf $< $@ @@ -79,12 +79,14 @@ libxenserver.so.{{API_VERSION_MAJOR}}.{{API_VERSION_MINOR}}: $(LIBXENAPI_OBJS) libxenserver.a: $(LIBXENAPI_OBJS) $(AR) rcs libxenserver.a $^ -$(TEST_PROGRAMS): test/%: test/%.o libxenserver.so +test/%: test/%.o libxenserver.so $(CC) -o $@ $< $(TEST_LDFLAGS) $(LDFLAGS) +build: libxenserver.so libxenserver.a -.PHONY: install -install: all libxenserver.a +tests: $(TEST_PROGRAMS) + +install: libxenserver.so libxenserver.a $(INSTALL_DIR) $(DESTDIR)/include/xen/api $(INSTALL_DIR) $(DESTDIR)/lib $(INSTALL_DATA) libxenserver.so.{{API_VERSION_MAJOR}}.{{API_VERSION_MINOR}} $(DESTDIR)/lib @@ -98,13 +100,13 @@ install: all libxenserver.a $(INSTALL_DATA) $$i $(DESTDIR)/include/xen/api; \ done - -.PHONY: clean clean: cleantests rm -f `find -name *.o` rm -f libxenserver.so* rm -f libxenserver.a -.PHONY: cleantests cleantests: rm -f $(TEST_PROGRAMS) + +.PHONY: clean cleantests build tests install +.DEFAULT_GOAL := tests diff --git a/c/templates/xen_internal.mustache b/c/templates/xen_internal.mustache index d747022..6a7dfbb 100644 --- a/c/templates/xen_internal.mustache +++ b/c/templates/xen_internal.mustache @@ -68,7 +68,7 @@ typedef struct struct_member struct_member; typedef struct abstract_type { - enum abstract_typename typename; + enum abstract_typename XEN_API_TYPE; const struct abstract_type *child; const char * (*enum_marshaller)(int); int (*enum_demarshaller)(xen_session *, const char *); diff --git a/common/CommonFunctions.ml b/common/CommonFunctions.ml index 97f0d69..82d7105 100644 --- a/common/CommonFunctions.ml +++ b/common/CommonFunctions.ml @@ -56,6 +56,13 @@ let with_output filename f = finally (fun () -> f io) ~always:(fun () -> close_out io) +let joined sep f l = l |> List.map f |> List.filter (fun x -> x <> "") |> String.concat sep + +let escape_xml s = s |> + Astring.String.cuts ~sep:"<" ~empty:true |> + String.concat "<" |> + Astring.String.cuts ~sep:">" ~empty:true |> + String.concat ">" let rec list_distinct list = match list with diff --git a/csharp/autogen/src/Event.cs b/csharp/autogen/src/Event.cs index 455be96..78c2fe2 100644 --- a/csharp/autogen/src/Event.cs +++ b/csharp/autogen/src/Event.cs @@ -89,7 +89,7 @@ public static Event get_record(Session session, string _event) if (session.JsonRpcClient != null) return session.JsonRpcClient.event_get_record(session.opaque_ref, _event); else - return new Event(session.proxy.event_get_record(session.opaque_ref, _event ?? "").parse()); + return new Event(session.XmlRpcProxy.event_get_record(session.opaque_ref, _event ?? "").parse()); } public static string get_by_uuid(Session session, string _uuid) @@ -97,7 +97,7 @@ public static string get_by_uuid(Session session, string _uuid) if (session.JsonRpcClient != null) return session.JsonRpcClient.event_get_by_uuid(session.opaque_ref, _uuid); else - return session.proxy.event_get_by_uuid(session.opaque_ref, _uuid ?? "").parse(); + return session.XmlRpcProxy.event_get_by_uuid(session.opaque_ref, _uuid ?? "").parse(); } public static long get_id(Session session, string _event) @@ -105,7 +105,7 @@ public static long get_id(Session session, string _event) if (session.JsonRpcClient != null) return session.JsonRpcClient.event_get_id(session.opaque_ref, _event); else - return long.Parse(session.proxy.event_get_id(session.opaque_ref, _event ?? "").parse()); + return long.Parse(session.XmlRpcProxy.event_get_id(session.opaque_ref, _event ?? "").parse()); } public static void set_id(Session session, string _event, long _id) @@ -113,7 +113,7 @@ public static void set_id(Session session, string _event, long _id) if (session.JsonRpcClient != null) session.JsonRpcClient.event_set_id(session.opaque_ref, _event, _id); else - session.proxy.event_set_id(session.opaque_ref, _event ?? "", _id.ToString()).parse(); + session.XmlRpcProxy.event_set_id(session.opaque_ref, _event ?? "", _id.ToString()).parse(); } public static void register(Session session, string[] _classes) @@ -121,7 +121,7 @@ public static void register(Session session, string[] _classes) if (session.JsonRpcClient != null) session.JsonRpcClient.event_register(session.opaque_ref, _classes); else - session.proxy.event_register(session.opaque_ref, _classes).parse(); + session.XmlRpcProxy.event_register(session.opaque_ref, _classes).parse(); } public static void unregister(Session session, string[] _classes) @@ -129,7 +129,7 @@ public static void unregister(Session session, string[] _classes) if (session.JsonRpcClient != null) session.JsonRpcClient.event_unregister(session.opaque_ref, _classes); else - session.proxy.event_unregister(session.opaque_ref, _classes).parse(); + session.XmlRpcProxy.event_unregister(session.opaque_ref, _classes).parse(); } public static Proxy_Event[] next(Session session) @@ -137,7 +137,7 @@ public static Proxy_Event[] next(Session session) if (session.JsonRpcClient != null) throw new NotImplementedException(); else - return session.proxy.event_next(session.opaque_ref).parse(); + return session.XmlRpcProxy.event_next(session.opaque_ref).parse(); } public static IEventCollection from(Session session, string[] _classes, string _token, double _timeout) @@ -145,14 +145,21 @@ public static IEventCollection from(Session session, string[] _classes, string _ if (session.JsonRpcClient != null) return session.JsonRpcClient.event_from(session.opaque_ref, _classes, _token, _timeout); else - return session.proxy.event_from(session.opaque_ref, _classes, _token, _timeout).parse(); + return session.XmlRpcProxy.event_from(session.opaque_ref, _classes, _token, _timeout).parse(); } private long _id; public long id { get { return _id; } - set { if (value != _id) { _id = value; Changed = true; NotifyPropertyChanged("id"); } } + set + { + if (value != _id) + { + _id = value; + NotifyPropertyChanged("id"); + } + } } public string timestamp; diff --git a/csharp/autogen/src/HTTP.cs b/csharp/autogen/src/HTTP.cs index 1264879..e4c585b 100644 --- a/csharp/autogen/src/HTTP.cs +++ b/csharp/autogen/src/HTTP.cs @@ -44,6 +44,8 @@ namespace XenAPI { public partial class HTTP { + #region Exceptions + [Serializable] public class TooManyRedirectsException : Exception { @@ -119,6 +121,8 @@ public ProxyServerAuthenticationException(string message, Exception exception) : protected ProxyServerAuthenticationException(SerializationInfo info, StreamingContext context) : base(info, context) { } } + #endregion + public delegate bool FuncBool(); public delegate void UpdateProgressDelegate(int percent); public delegate void DataCopiedDelegate(long bytes); @@ -397,7 +401,7 @@ private static string GetPartOrNull(string str, int partIndex) #endregion - private static NetworkStream ConnectSocket(Uri uri, bool nodelay, int timeout_ms) + private static NetworkStream ConnectSocket(Uri uri, bool nodelay, int timeoutMs) { AddressFamily addressFamily = uri.HostNameType == UriHostNameType.IPv6 ? AddressFamily.InterNetworkV6 @@ -406,8 +410,8 @@ private static NetworkStream ConnectSocket(Uri uri, bool nodelay, int timeout_ms new Socket(addressFamily, SocketType.Stream, ProtocolType.Tcp); socket.NoDelay = nodelay; //socket.ReceiveBufferSize = 64 * 1024; - socket.ReceiveTimeout = timeout_ms; - socket.SendTimeout = timeout_ms; + socket.ReceiveTimeout = timeoutMs; + socket.SendTimeout = timeoutMs; socket.Connect(uri.Host, uri.Port); return new NetworkStream(socket, true); @@ -420,10 +424,10 @@ private static NetworkStream ConnectSocket(Uri uri, bool nodelay, int timeout_ms /// /// /// - /// Timeout, in ms. 0 for no timeout. - public static Stream ConnectStream(Uri uri, IWebProxy proxy, bool nodelay, int timeout_ms) + /// Timeout, in ms. 0 for no timeout. + public static Stream ConnectStream(Uri uri, IWebProxy proxy, bool nodelay, int timeoutMs) { - IMockWebProxy mockProxy = proxy != null ? proxy as IMockWebProxy : null; + IMockWebProxy mockProxy = proxy as IMockWebProxy; if (mockProxy != null) return mockProxy.GetStream(uri); @@ -433,25 +437,25 @@ public static Stream ConnectStream(Uri uri, IWebProxy proxy, bool nodelay, int t if (useProxy) { Uri proxyURI = proxy.GetProxy(uri); - stream = ConnectSocket(proxyURI, nodelay, timeout_ms); + stream = ConnectSocket(proxyURI, nodelay, timeoutMs); } else { - stream = ConnectSocket(uri, nodelay, timeout_ms); + stream = ConnectSocket(uri, nodelay, timeoutMs); } try { if (useProxy) { - string line = String.Format("CONNECT {0}:{1} HTTP/1.0", uri.Host, uri.Port); + string line = string.Format("CONNECT {0}:{1} HTTP/1.0", uri.Host, uri.Port); WriteLine(line, stream); WriteLine(stream); List initialResponse = new List(); - ReadHttpHeaders(ref stream, proxy, nodelay, timeout_ms, initialResponse); + ReadHttpHeaders(ref stream, proxy, nodelay, timeoutMs, initialResponse); - AuthenticateProxy(ref stream, uri, proxy, nodelay, timeout_ms, initialResponse, line); + AuthenticateProxy(ref stream, uri, proxy, nodelay, timeoutMs, initialResponse, line); } if (UseSSL(uri)) @@ -472,7 +476,7 @@ public static Stream ConnectStream(Uri uri, IWebProxy proxy, bool nodelay, int t } } - private static void AuthenticateProxy(ref Stream stream, Uri uri, IWebProxy proxy, bool nodelay, int timeout_ms, List initialResponse, string header) + private static void AuthenticateProxy(ref Stream stream, Uri uri, IWebProxy proxy, bool nodelay, int timeoutMs, List initialResponse, string header) { // perform authentication only if proxy requires it List fields = initialResponse.FindAll(str => str.StartsWith("Proxy-Authenticate:")); @@ -484,7 +488,7 @@ private static void AuthenticateProxy(ref Stream stream, Uri uri, IWebProxy prox { stream.Close(); Uri proxyURI = proxy.GetProxy(uri); - stream = ConnectSocket(proxyURI, nodelay, timeout_ms); + stream = ConnectSocket(proxyURI, nodelay, timeoutMs); } if (proxy.Credentials == null) @@ -613,7 +617,7 @@ private static void AuthenticateProxy(ref Stream stream, Uri uri, IWebProxy prox // handle authentication attempt response List authenticatedResponse = new List(); - ReadHttpHeaders(ref stream, proxy, nodelay, timeout_ms, authenticatedResponse); + ReadHttpHeaders(ref stream, proxy, nodelay, timeoutMs, authenticatedResponse); if (authenticatedResponse.Count == 0) throw new BadServerResponseException("No response from the proxy server after authentication attempt."); switch (getResultCode(authenticatedResponse[0])) @@ -629,7 +633,8 @@ private static void AuthenticateProxy(ref Stream stream, Uri uri, IWebProxy prox } } - private static Stream DO_HTTP(Uri uri, IWebProxy proxy, bool nodelay, int timeout_ms, params string[] headers) + + private static Stream DoHttp(Uri uri, IWebProxy proxy, bool nodelay, int timeout_ms, params string[] headers) { Stream stream = ConnectStream(uri, proxy, nodelay, timeout_ms); @@ -653,34 +658,39 @@ private static Stream DO_HTTP(Uri uri, IWebProxy proxy, bool nodelay, int timeou return stream; } - // - // The following functions do all the HTTP headers related stuff - // returning the stream ready for use - // - - public static Stream CONNECT(Uri uri, IWebProxy proxy, String session, int timeout_ms) + /// + /// Adds HTTP CONNECT headers returning the stream ready for use + /// + public static Stream HttpConnectStream(Uri uri, IWebProxy proxy, String session, int timeoutMs) { - return DO_HTTP(uri, proxy, true, timeout_ms, + return DoHttp(uri, proxy, true, timeoutMs, string.Format("CONNECT {0} HTTP/1.0", uri.PathAndQuery), string.Format("Host: {0}", uri.Host), string.Format("Cookie: session_id={0}", session)); } - public static Stream PUT(Uri uri, IWebProxy proxy, long ContentLength, int timeout_ms) + /// + /// Adds HTTP PUT headers returning the stream ready for use + /// + public static Stream HttpPutStream(Uri uri, IWebProxy proxy, long contentLength, int timeoutMs) { - return DO_HTTP(uri, proxy, false, timeout_ms, + return DoHttp(uri, proxy, false, timeoutMs, string.Format("PUT {0} HTTP/1.0", uri.PathAndQuery), string.Format("Host: {0}", uri.Host), - string.Format("Content-Length: {0}", ContentLength)); + string.Format("Content-Length: {0}", contentLength)); } - public static Stream GET(Uri uri, IWebProxy proxy, int timeout_ms) + /// + /// Adds HTTP GET headers returning the stream ready for use + /// + public static Stream HttpGetStream(Uri uri, IWebProxy proxy, int timeoutMs) { - return DO_HTTP(uri, proxy, false, timeout_ms, + return DoHttp(uri, proxy, false, timeoutMs, string.Format("GET {0} HTTP/1.0", uri.PathAndQuery), string.Format("Host: {0}", uri.Host)); } + /// /// A general HTTP PUT method, with delegates for progress and cancelling. May throw various exceptions. /// @@ -689,12 +699,12 @@ public static Stream GET(Uri uri, IWebProxy proxy, int timeout_ms) /// URI to PUT to /// A proxy to handle the HTTP connection /// Path to file to put - /// Timeout for the connection in ms. 0 for no timeout. + /// Timeout for the connection in ms. 0 for no timeout. public static void Put(UpdateProgressDelegate progressDelegate, FuncBool cancellingDelegate, - Uri uri, IWebProxy proxy, string path, int timeout_ms) + Uri uri, IWebProxy proxy, string path, int timeoutMs) { using (Stream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read), - requestStream = PUT(uri, proxy, fileStream.Length, timeout_ms)) + requestStream = HttpPutStream(uri, proxy, fileStream.Length, timeoutMs)) { long len = fileStream.Length; DataCopiedDelegate dataCopiedDelegate = delegate(long bytes) @@ -715,15 +725,15 @@ public static void Put(UpdateProgressDelegate progressDelegate, FuncBool cancell /// URI to GET from /// A proxy to handle the HTTP connection /// Path to file to receive the data - /// Timeout for the connection in ms. 0 for no timeout. + /// Timeout for the connection in ms. 0 for no timeout. public static void Get(DataCopiedDelegate dataCopiedDelegate, FuncBool cancellingDelegate, - Uri uri, IWebProxy proxy, string path, int timeout_ms) + Uri uri, IWebProxy proxy, string path, int timeoutMs) { string tmpFile = Path.GetTempFileName(); try { using (Stream fileStream = new FileStream(tmpFile, FileMode.Create, FileAccess.Write, FileShare.None), - downloadStream = GET(uri, proxy, timeout_ms)) + downloadStream = HttpGetStream(uri, proxy, timeoutMs)) { CopyStream(downloadStream, fileStream, dataCopiedDelegate, cancellingDelegate); fileStream.Flush(); @@ -738,6 +748,28 @@ public static void Get(DataCopiedDelegate dataCopiedDelegate, FuncBool cancellin } } + + [Obsolete("Use HttpConnectStream(Uri, IWebProxy, String, int) instead.")] + public static Stream CONNECT(Uri uri, IWebProxy proxy, string session, int timeoutMs) + { + return HttpConnectStream(uri,proxy,session, timeoutMs); + } + +#pragma warning disable 3005 + [Obsolete("Use HttpPutStream(Uri, IWebProxy, long, int) instead.")] + public static Stream PUT(Uri uri, IWebProxy proxy, long contentLength, int timeoutMs) + { + return HttpPutStream(uri, proxy, contentLength, timeoutMs); + } + + [Obsolete("Use HttpGetStream(Uri, IWebProxy, int) instead.")] + public static Stream GET(Uri uri, IWebProxy proxy, int timeoutMs) + { + return HttpGetStream(uri, proxy, timeoutMs); + } +#pragma warning restore 3005 + + private const int FILE_MOVE_MAX_RETRIES = 5; private const int FILE_MOVE_SLEEP_BETWEEN_RETRIES = 100; diff --git a/csharp/autogen/src/Session.cs b/csharp/autogen/src/Session.cs index c3aec0a..82e38af 100644 --- a/csharp/autogen/src/Session.cs +++ b/csharp/autogen/src/Session.cs @@ -31,8 +31,6 @@ using System; using System.Collections.Generic; using System.Net; -using System.Net.Security; -using System.Security.Cryptography.X509Certificates; using CookComputing.XmlRpc; using Newtonsoft.Json; @@ -54,15 +52,10 @@ public partial class Session : XenObject /// public static IWebProxy Proxy = null; - public API_Version APIVersion = API_Version.API_1_1; + public API_Version APIVersion = API_Version.UNKNOWN; public object Tag; - // Filled in after successful session_login_with_password for version 1.6 or newer connections - private bool _isLocalSuperuser = true; - private XenRef _subject = null; - private string _userSid = null; - private string[] permissions = null; private List roles = new List(); /// @@ -130,16 +123,16 @@ public Session(Session session, int timeout) Cookies = session.JsonRpcClient.Cookies }; } - else if (session.proxy != null) + else if (session.XmlRpcProxy != null) { - proxy = XmlRpcProxyGen.Create(); - proxy.Url = session.Url; - proxy.Timeout = timeout; - proxy.NonStandard = session.proxy.NonStandard; - proxy.UseIndentation = session.proxy.UseIndentation; - proxy.UserAgent = session.proxy.UserAgent; - proxy.KeepAlive = session.proxy.KeepAlive; - proxy.Proxy = session.proxy.Proxy; + XmlRpcProxy = XmlRpcProxyGen.Create(); + XmlRpcProxy.Url = session.Url; + XmlRpcProxy.Timeout = timeout; + XmlRpcProxy.NonStandard = session.XmlRpcProxy.NonStandard; + XmlRpcProxy.UseIndentation = session.XmlRpcProxy.UseIndentation; + XmlRpcProxy.UserAgent = session.XmlRpcProxy.UserAgent; + XmlRpcProxy.KeepAlive = session.XmlRpcProxy.KeepAlive; + XmlRpcProxy.Proxy = session.XmlRpcProxy.Proxy; } CopyADFromSession(session); @@ -159,14 +152,14 @@ public static Session get_record(Session session, string _session) private void InitializeXmlRpcProxy(string url, int timeout) { - proxy = XmlRpcProxyGen.Create(); - proxy.Url = url; - proxy.NonStandard = XmlRpcNonStandard.All; - proxy.Timeout = timeout; - proxy.UseIndentation = false; - proxy.UserAgent = UserAgent; - proxy.KeepAlive = true; - proxy.Proxy = Proxy; + XmlRpcProxy = XmlRpcProxyGen.Create(); + XmlRpcProxy.Url = url; + XmlRpcProxy.NonStandard = XmlRpcNonStandard.All; + XmlRpcProxy.Timeout = timeout; + XmlRpcProxy.UseIndentation = false; + XmlRpcProxy.UserAgent = UserAgent; + XmlRpcProxy.KeepAlive = true; + XmlRpcProxy.Proxy = Proxy; } private void SetupSessionDetails() @@ -180,11 +173,11 @@ private void SetupSessionDetails() private void CopyADFromSession(Session session) { - _isLocalSuperuser = session.IsLocalSuperuser; - _subject = session.Subject; - _userSid = session.UserSid; + IsLocalSuperuser = session.IsLocalSuperuser; + SessionSubject = session.SessionSubject; + UserSid = session.UserSid; roles = session.Roles; - permissions = session.Permissions; + Permissions = session.Permissions; } /// @@ -193,18 +186,21 @@ private void CopyADFromSession(Session session) private void SetADDetails() { if (APIVersion < API_Version.API_1_6) + { + IsLocalSuperuser = true; return; + } - _isLocalSuperuser = get_is_local_superuser(); + IsLocalSuperuser = get_is_local_superuser(); if (IsLocalSuperuser) return; - _subject = get_subject(); - _userSid = get_auth_user_sid(); + SessionSubject = get_subject(this, opaque_ref); + UserSid = get_auth_user_sid(); // Cache the details of this user to avoid making server calls later // For example, some users get access to the pool through a group subject and will not be in the main cache - UserDetails.UpdateDetails(_userSid, this); + UserDetails.UpdateDetails(UserSid, this); } /// @@ -217,11 +213,11 @@ private void SetRbacPermissions() return; // allRoles will contain every role on the server, permissions contains the subset of those that are available to this session. - permissions = Session.get_rbac_permissions(this, opaque_ref); + Permissions = Session.get_rbac_permissions(this, opaque_ref); Dictionary, Role> allRoles = Role.get_all_records(this); // every Role object is either a single api call (a permission) or has subroles and contains permissions through its descendants. // We take out the parent Roles (VM-Admin etc.) into the Session.Roles field - foreach (string s in permissions) + foreach (string s in Permissions) { foreach (XenRef xr in allRoles.Keys) { @@ -243,7 +239,7 @@ public virtual UserDetails CurrentUserDetails { get { - return _userSid == null ? null : UserDetails.Sid_To_UserDetails[_userSid]; + return UserSid == null ? null : UserDetails.Sid_To_UserDetails[UserSid]; } } @@ -257,7 +253,16 @@ public override string SaveChanges(Session session, string _serverOpaqueRef, Ses throw new Exception("The method or operation is not implemented."); } - public Proxy proxy { get; private set; } +#pragma warning disable 3005 + [Obsolete("Use XmlRpcProxy instead.")] + public Proxy proxy + { + get { return XmlRpcProxy; } + private set { XmlRpcProxy = value; } + } +#pragma warning restore 3005 + + public Proxy XmlRpcProxy { get; private set; } public JsonRpcClient JsonRpcClient { get; private set; } @@ -274,7 +279,7 @@ public string Url if (JsonRpcClient != null) return JsonRpcClient.Url; else - return proxy.Url; + return XmlRpcProxy.Url; } } @@ -285,14 +290,14 @@ public string ConnectionGroupName if (JsonRpcClient != null) return JsonRpcClient.ConnectionGroupName; else - return proxy.ConnectionGroupName; + return XmlRpcProxy.ConnectionGroupName; } set { if (JsonRpcClient != null) JsonRpcClient.ConnectionGroupName = value; else - proxy.ConnectionGroupName = value; + XmlRpcProxy.ConnectionGroupName = value; } } @@ -303,8 +308,8 @@ public ICredentials Credentials if (JsonRpcClient != null) return JsonRpcClient.WebProxy == null ? null : JsonRpcClient.WebProxy.Credentials; - if (proxy != null) - return proxy.Proxy == null ? null : proxy.Proxy.Credentials; + if (XmlRpcProxy != null) + return XmlRpcProxy.Proxy == null ? null : XmlRpcProxy.Proxy.Credentials; return null; } @@ -312,40 +317,39 @@ public ICredentials Credentials /// /// Always true before API version 1.6. + /// Filled in after successful session_login_with_password for 1.6 or newer connections /// - public virtual bool IsLocalSuperuser + public virtual bool IsLocalSuperuser { get; private set; } + +#pragma warning disable 3005 + [Obsolete("Use SessionSubject instead.")] + [JsonConverter(typeof(XenRefConverter))] + public XenRef Subject { - get { return _isLocalSuperuser; } + get { return SessionSubject; } + private set { SessionSubject = value; } } +#pragma warning restore 3005 /// /// The OpaqueRef for the Subject under whose authority the current user is logged in; /// may correspond to either a group or a user. /// Null if IsLocalSuperuser is true. /// - [JsonConverter(typeof(XenRefConverter))] - public XenRef Subject - { - get { return _subject; } - } + [JsonConverter(typeof(XenRefConverter))] + public XenRef SessionSubject { get; private set; } /// /// The Active Directory SID of the currently logged-in user. /// Null if IsLocalSuperuser is true. /// - public string UserSid - { - get { return _userSid; } - } + public string UserSid { get; private set; } /// /// All permissions associated with the session at the time of log in. This is the list xapi uses until the session is logged out; /// even if the permitted roles change on the server side, they don't apply until the next session. /// - public string[] Permissions - { - get { return permissions; } - } + public string[] Permissions { get; private set; } /// /// All roles associated with the session at the time of log in. Do not rely on roles for determining what a user can do, @@ -362,7 +366,7 @@ public void login_with_password(string username, string password) if (JsonRpcClient != null) opaque_ref = JsonRpcClient.session_login_with_password(username, password); else - opaque_ref = proxy.session_login_with_password(username, password).parse(); + opaque_ref = XmlRpcProxy.session_login_with_password(username, password).parse(); SetupSessionDetails(); } @@ -374,7 +378,7 @@ public void login_with_password(string username, string password, string version if (JsonRpcClient != null) opaque_ref = JsonRpcClient.session_login_with_password(username, password, version); else - opaque_ref = proxy.session_login_with_password(username, password, version).parse(); + opaque_ref = XmlRpcProxy.session_login_with_password(username, password, version).parse(); SetupSessionDetails(); } @@ -399,7 +403,7 @@ public void login_with_password(string username, string password, string version if (JsonRpcClient != null) opaque_ref = JsonRpcClient.session_login_with_password(username, password, version, originator); else - opaque_ref = proxy.session_login_with_password(username, password, version, originator).parse(); + opaque_ref = XmlRpcProxy.session_login_with_password(username, password, version, originator).parse(); SetupSessionDetails(); } @@ -444,24 +448,24 @@ private static void SwitchToJsonRpcBackend(Session session) if (isELy || isInvernessOrAbove) { - session.JsonRpcClient = new JsonRpcClient(session.proxy.Url) + session.JsonRpcClient = new JsonRpcClient(session.XmlRpcProxy.Url) { - ConnectionGroupName = session.proxy.ConnectionGroupName, - Timeout = session.proxy.Timeout, - KeepAlive = session.proxy.KeepAlive, - UserAgent = session.proxy.UserAgent, - WebProxy = session.proxy.Proxy, - ProtocolVersion = session.proxy.ProtocolVersion, - Expect100Continue = session.proxy.Expect100Continue, - AllowAutoRedirect = session.proxy.AllowAutoRedirect, - PreAuthenticate = session.proxy.PreAuthenticate, - Cookies = session.proxy.CookieContainer + ConnectionGroupName = session.XmlRpcProxy.ConnectionGroupName, + Timeout = session.XmlRpcProxy.Timeout, + KeepAlive = session.XmlRpcProxy.KeepAlive, + UserAgent = session.XmlRpcProxy.UserAgent, + WebProxy = session.XmlRpcProxy.Proxy, + ProtocolVersion = session.XmlRpcProxy.ProtocolVersion, + Expect100Continue = session.XmlRpcProxy.Expect100Continue, + AllowAutoRedirect = session.XmlRpcProxy.AllowAutoRedirect, + PreAuthenticate = session.XmlRpcProxy.PreAuthenticate, + Cookies = session.XmlRpcProxy.CookieContainer }; if (isInvernessOrAbove) session.JsonRpcClient.JsonRpcVersion = JsonRpcVersion.v2; - session.proxy = null; + session.XmlRpcProxy = null; } } @@ -470,7 +474,7 @@ public void slave_local_login_with_password(string username, string password) if (JsonRpcClient != null) opaque_ref = JsonRpcClient.session_slave_local_login_with_password(username, password); else - opaque_ref = proxy.session_slave_local_login_with_password(username, password).parse(); + opaque_ref = XmlRpcProxy.session_slave_local_login_with_password(username, password).parse(); //assume the latest API APIVersion = API_Version.LATEST; } @@ -502,7 +506,7 @@ public void logout(string _self) if (JsonRpcClient != null) JsonRpcClient.session_logout(_self); else - proxy.session_logout(_self).parse(); + XmlRpcProxy.session_logout(_self).parse(); } public void local_logout() @@ -524,7 +528,7 @@ public void local_logout(string opaqueRef) if (JsonRpcClient != null) JsonRpcClient.session_local_logout(opaqueRef); else - proxy.session_local_logout(opaqueRef).parse(); + XmlRpcProxy.session_local_logout(opaqueRef).parse(); } public void change_password(string oldPassword, string newPassword) @@ -543,7 +547,7 @@ public void change_password(Session session2, string oldPassword, string newPass if (JsonRpcClient != null) JsonRpcClient.session_change_password(session2.opaque_ref, oldPassword, newPassword); else - proxy.session_change_password(session2.opaque_ref, oldPassword, newPassword).parse(); + XmlRpcProxy.session_change_password(session2.opaque_ref, oldPassword, newPassword).parse(); } public string get_this_host() @@ -556,7 +560,7 @@ public static string get_this_host(Session session, string _self) if (session.JsonRpcClient != null) return session.JsonRpcClient.session_get_this_host(session.opaque_ref, _self ?? ""); else - return session.proxy.session_get_this_host(session.opaque_ref, _self ?? "").parse(); + return session.XmlRpcProxy.session_get_this_host(session.opaque_ref, _self ?? "").parse(); } public string get_this_user() @@ -569,7 +573,7 @@ public static string get_this_user(Session session, string _self) if (session.JsonRpcClient != null) return session.JsonRpcClient.session_get_this_user(session.opaque_ref, _self ?? ""); else - return session.proxy.session_get_this_user(session.opaque_ref, _self ?? "").parse(); + return session.XmlRpcProxy.session_get_this_user(session.opaque_ref, _self ?? "").parse(); } public bool get_is_local_superuser() @@ -582,7 +586,7 @@ public static bool get_is_local_superuser(Session session, string _self) if (session.JsonRpcClient != null) return session.JsonRpcClient.session_get_is_local_superuser(session.opaque_ref, _self ?? ""); else - return session.proxy.session_get_is_local_superuser(session.opaque_ref, _self ?? "").parse(); + return session.XmlRpcProxy.session_get_is_local_superuser(session.opaque_ref, _self ?? "").parse(); } public static string[] get_rbac_permissions(Session session, string _self) @@ -590,7 +594,7 @@ public static string[] get_rbac_permissions(Session session, string _self) if (session.JsonRpcClient != null) return session.JsonRpcClient.session_get_rbac_permissions(session.opaque_ref, _self ?? ""); else - return session.proxy.session_get_rbac_permissions(session.opaque_ref, _self ?? "").parse(); + return session.XmlRpcProxy.session_get_rbac_permissions(session.opaque_ref, _self ?? "").parse(); } public DateTime get_last_active() @@ -603,7 +607,7 @@ public static DateTime get_last_active(Session session, string _self) if (session.JsonRpcClient != null) return session.JsonRpcClient.session_get_last_active(session.opaque_ref, _self ?? ""); else - return session.proxy.session_get_last_active(session.opaque_ref, _self ?? "").parse(); + return session.XmlRpcProxy.session_get_last_active(session.opaque_ref, _self ?? "").parse(); } public bool get_pool() @@ -616,7 +620,7 @@ public static bool get_pool(Session session, string _self) if (session.JsonRpcClient != null) return session.JsonRpcClient.session_get_pool(session.opaque_ref, _self ?? ""); else - return session.proxy.session_get_pool(session.opaque_ref, _self ?? "").parse(); + return session.XmlRpcProxy.session_get_pool(session.opaque_ref, _self ?? "").parse(); } public XenRef get_subject() @@ -629,7 +633,7 @@ public static XenRef get_subject(Session session, string _self) if (session.JsonRpcClient != null) return session.JsonRpcClient.session_get_subject(session.opaque_ref, _self ?? ""); else - return new XenRef(session.proxy.session_get_subject(session.opaque_ref, _self ?? "").parse()); + return new XenRef(session.XmlRpcProxy.session_get_subject(session.opaque_ref, _self ?? "").parse()); } public string get_auth_user_sid() @@ -642,7 +646,7 @@ public static string get_auth_user_sid(Session session, string _self) if (session.JsonRpcClient != null) return session.JsonRpcClient.session_get_auth_user_sid(session.opaque_ref, _self ?? ""); else - return session.proxy.session_get_auth_user_sid(session.opaque_ref, _self ?? "").parse(); + return session.XmlRpcProxy.session_get_auth_user_sid(session.opaque_ref, _self ?? "").parse(); } #region AD SID enumeration and bootout @@ -657,7 +661,7 @@ public static string[] get_all_subject_identifiers(Session session) if (session.JsonRpcClient != null) return session.JsonRpcClient.session_get_all_subject_identifiers(session.opaque_ref); else - return session.proxy.session_get_all_subject_identifiers(session.opaque_ref).parse(); + return session.XmlRpcProxy.session_get_all_subject_identifiers(session.opaque_ref).parse(); } public XenRef async_get_all_subject_identifiers() @@ -670,7 +674,7 @@ public static XenRef async_get_all_subject_identifiers(Session session) if (session.JsonRpcClient != null) return session.JsonRpcClient.async_session_get_all_subject_identifiers(session.opaque_ref); else - return XenRef.Create(session.proxy.async_session_get_all_subject_identifiers(session.opaque_ref).parse()); + return XenRef.Create(session.XmlRpcProxy.async_session_get_all_subject_identifiers(session.opaque_ref).parse()); } public string logout_subject_identifier(string subject_identifier) @@ -686,7 +690,7 @@ public static string logout_subject_identifier(Session session, string subject_i return string.Empty; } else - return session.proxy.session_logout_subject_identifier(session.opaque_ref, subject_identifier).parse(); + return session.XmlRpcProxy.session_logout_subject_identifier(session.opaque_ref, subject_identifier).parse(); } public XenRef async_logout_subject_identifier(string subject_identifier) @@ -699,7 +703,7 @@ public static XenRef async_logout_subject_identifier(Session session, stri if (session.JsonRpcClient != null) return session.JsonRpcClient.async_session_logout_subject_identifier(session.opaque_ref, subject_identifier); else - return XenRef.Create(session.proxy.async_session_logout_subject_identifier(session.opaque_ref, subject_identifier).parse()); + return XenRef.Create(session.XmlRpcProxy.async_session_logout_subject_identifier(session.opaque_ref, subject_identifier).parse()); } #endregion @@ -716,7 +720,7 @@ public static Dictionary get_other_config(Session session, strin if (session.JsonRpcClient != null) return session.JsonRpcClient.session_get_other_config(session.opaque_ref, _self ?? ""); else - return Maps.convert_from_proxy_string_string(session.proxy.session_get_other_config(session.opaque_ref, _self ?? "").parse()); + return Maps.convert_from_proxy_string_string(session.XmlRpcProxy.session_get_other_config(session.opaque_ref, _self ?? "").parse()); } public void set_other_config(Dictionary _other_config) @@ -729,7 +733,7 @@ public static void set_other_config(Session session, string _self, Dictionary : IXenObject where S : XenObject public string opaque_ref { get; set; } [JsonIgnore] - public bool Changed { get; set; } + [Obsolete("This property can no longer be used to deduce that a XenObject has changed: " + + "now it always returns true and new values assigned to it are ignored. " + + "To be notified when the XenObject has changed (i.e. its properties have new values)," + + "handle the event PropertyChanged instead.")] + public bool Changed + { + get { return true; } + set { } + } public event PropertyChangedEventHandler PropertyChanged; diff --git a/csharp/gen_csharp_binding.ml b/csharp/gen_csharp_binding.ml index d32f3a1..1909d0d 100644 --- a/csharp/gen_csharp_binding.ml +++ b/csharp/gen_csharp_binding.ml @@ -79,14 +79,6 @@ let classes = List.filter (fun x-> not (List.mem x.name ["debug"; "event"])) (ob let enums = ref TypeSet.empty let maps = ref TypeSet.empty -let joined sep f l = l |> List.map f |> List.filter (fun x -> x <> "") |> String.concat sep - -let escape_xml s = s |> - Astring.String.cuts ~sep:"<" ~empty:true |> - String.concat "<" |> - Astring.String.cuts ~sep:">" ~empty:true |> - String.concat ">" - let enum_of_wire = Astring.String.map (fun x -> match x with '-' -> '_' | _ -> x) @@ -95,6 +87,10 @@ let api_members = ref [] let rec main() = render_file ("Proxy.mustache", "Proxy.cs") (gen_proxy CommonFunctions.XmlRpc) templdir destdir; render_file ("JsonRpcClient.mustache", "JsonRpcClient.cs") (gen_proxy CommonFunctions.JsonRpc) templdir destdir; + + let msgJson = `O ["message_types", `A (List.map (fun x -> `O ["message_type", `String (fst x)];) !Api_messages.msgList); ] in + render_file ("Message2.mustache", "Message2.cs") msgJson templdir destdir; + classes |> List.filter (fun x-> x.name <> "session") |> List.iter gen_class_file; TypeSet.iter gen_enum !enums; gen_maps(); @@ -304,34 +300,6 @@ namespace XenAPI (escape_xml cls.description) (if publishedInfo = "" then "" else "\n /// "^publishedInfo) exposed_class_name exposed_class_name; - (* Generate bits for Message type *) - if cls.name = "message" then - begin - print " - public enum MessageType { %s }; - - public MessageType Type - { - get - { - switch (this.name) - {" - (String.concat ", " ((List.map fst !Api_messages.msgList) @ ["unknown"])); - - List.iter (fun x -> print " - case \"%s\": - return MessageType.%s;" x x) (List.map fst !Api_messages.msgList); - - print - " - default: - return MessageType.unknown; - } - } - } -" - end; - print " #region Constructors @@ -666,7 +634,7 @@ and gen_exposed_method cls msg curParams = exposed_ret_type msg.msg_name paramSignature (json_return_opt (sprintf "session.JsonRpcClient.%s(%s)" proxyMsgName jsonCallParams) msg.msg_result) - (convert_from_proxy_opt (sprintf "session.proxy.%s(%s).parse()" proxyMsgName callParams) msg.msg_result) + (convert_from_proxy_opt (sprintf "session.XmlRpcProxy.%s(%s).parse()" proxyMsgName callParams) msg.msg_result) in let async = if msg.msg_async then sprintf " @@ -678,7 +646,7 @@ and gen_exposed_method cls msg curParams = if (session.JsonRpcClient != null) return session.JsonRpcClient.async_%s(%s); else - return XenRef.Create(session.proxy.async_%s(%s).parse()); + return XenRef.Create(session.XmlRpcProxy.async_%s(%s).parse()); }\n" msg.msg_doc (if publishInfo = "" then "" else "\n /// "^publishInfo) deprecatedInfoString @@ -808,7 +776,6 @@ and gen_exposed_field out_chan cls content = if (%s) { _%s = value; - Changed = true; NotifyPropertyChanged(\"%s\"); } } @@ -907,7 +874,7 @@ and gen_proxy_method protocol classname message params = return_word (json_deserialise_opt message.msg_result) classname message.msg_name paramsJsonNoTypes in - let async = + let async = if message.msg_async then sprintf " public XenRef async_%s(%s) diff --git a/csharp/templates/Message2.mustache b/csharp/templates/Message2.mustache new file mode 100644 index 0000000..d670e0f --- /dev/null +++ b/csharp/templates/Message2.mustache @@ -0,0 +1,60 @@ +/* + * Copyright (c) Citrix Systems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1) Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2) Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +namespace XenAPI +{ + public partial class Message : XenObject + { + public enum MessageType + { +{{#message_types}} + {{{message_type}}}, +{{/message_types}} + unknown + } + + public MessageType Type + { + get + { + switch (this.name) + { +{{#message_types}} + case "{{{message_type}}}": + return MessageType.{{{message_type}}}; +{{/message_types}} + default: + return MessageType.unknown; + } + } + } + } +} diff --git a/csharp/templates/XenServer.csproj.mustache b/csharp/templates/XenServer.csproj.mustache index f862970..fa0ed70 100644 --- a/csharp/templates/XenServer.csproj.mustache +++ b/csharp/templates/XenServer.csproj.mustache @@ -18,6 +18,7 @@ DEBUG;TRACE prompt 4 + true false @@ -59,6 +60,7 @@ + diff --git a/java/main.ml b/java/main.ml index 460cb11..35a8594 100644 --- a/java/main.ml +++ b/java/main.ml @@ -228,9 +228,9 @@ let gen_method_return_cast message = match message.msg_result with let gen_method_return file cls message = if (String.lowercase_ascii cls.name) = "event" && (String.lowercase_ascii message.msg_name) = "from" then - fprintf file " return Types.toEventBatch(result);\n" + fprintf file " return Types.toEventBatch(result);\n" else - fprintf file " return%s;\n" (gen_method_return_cast message) + fprintf file " return%s;\n" (gen_method_return_cast message) let rec range = function | 0 -> [] @@ -245,41 +245,49 @@ let gen_method file cls message params async_version = let method_static = if is_method_static message then "static " else "" in let method_name = camel_case message.msg_name in let paramString = get_method_params_for_signature params in - let default_errors = ["BadServerResponse"; - "XenAPIException"; - "XmlRpcException"] in - let err_string = String.concat ",\n " (default_errors @ (List.map - (fun err -> "Types." ^ (exception_class_case err.err_name)) message.msg_errors)) in + let default_errors = [ + ("BadServerResponse", "Thrown if the response from the server contains an invalid status."); + ("XenAPIException", "Thrown if the call failed."); + ("XmlRpcException", "Thrown if the result of an asynchronous call could not be parsed.") + ] in let publishInfo = get_published_info_message message cls in fprintf file " /**\n"; - fprintf file " * %s\n" message.msg_doc; + fprintf file " * %s\n" (escape_xml message.msg_doc); if not (publishInfo = "") then fprintf file " * %s\n" publishInfo; if (get_method_deprecated message) then fprintf file " * @deprecated\n"; fprintf file " *\n"; + fprintf file " * @param c The connection the call is made on\n"; List.iter (fun x -> let paramPublishInfo = get_published_info_param message x in fprintf file " * @param %s %s%s\n" (camel_case x.param_name) - x.param_doc + (if x.param_doc = "" then "No description" else (escape_xml x.param_doc)) (if paramPublishInfo = "" then "" else " "^paramPublishInfo)) params; if async_version then fprintf file " * @return Task\n" - else - (match message.msg_result with - | None -> () - | Some (_, desc) -> fprintf file " * @return %s\n" desc); + else begin + match message.msg_result with + | None -> () + | Some (_, "") -> fprintf file " * @return %s\n" (get_java_type_or_void message.msg_result) + | Some (_, desc) -> fprintf file " * @return %s\n" desc + end; + + List.iter (fun x -> fprintf file " * @throws %s %s\n" (fst x) (snd x)) default_errors; + List.iter (fun x -> fprintf file " * @throws Types.%s %s\n" (exception_class_case x.err_name) x.err_doc) message.msg_errors; fprintf file " */\n"; if async_version then fprintf file " %s public %sTask %sAsync(%s) throws\n" deprecated_string method_static method_name paramString else - fprintf file " %s public %s%s %s(%s) throws\n" deprecated_string method_static return_type method_name paramString; + fprintf file " %s public %s%s %s(%s) throws\n" deprecated_string method_static return_type method_name paramString; - fprintf file " %s {\n" err_string; + let all_errors = (List.map fst default_errors) @ + (List.map (fun x -> "Types." ^ (exception_class_case x.err_name)) message.msg_errors) in + fprintf file " %s {\n" (String.concat ",\n " all_errors); if async_version then fprintf file " String method_call = \"Async.%s.%s\";\n" message.msg_obj_name message.msg_name @@ -316,7 +324,7 @@ let gen_method file cls message params async_version = fprintf file " return Types.toTask(result);\n" ) else ( match message.msg_result with - | None -> fprintf file " return;\n" + | None -> fprintf file "" | Some _ -> fprintf file " Object result = response.get(\"Value\");\n"; gen_method_return file cls message ); @@ -348,7 +356,7 @@ let gen_record_field file prefix field cls = let name = camel_case (String.concat "_" (List.rev (field.field_name :: prefix))) in let publishInfo = get_published_info_field field cls in fprintf file " /**\n"; - fprintf file " * %s\n" field.field_description; + fprintf file " * %s\n" (escape_xml field.field_description); if not (publishInfo = "") then fprintf file " * %s\n" publishInfo; fprintf file " */\n"; fprintf file " public %s %s;\n" ty name @@ -698,7 +706,7 @@ let gen_enum file name ls = fprintf file " /* This can never be reached */\n"; fprintf file " return \"illegal enum\";\n"; fprintf file " }\n"; - fprintf file "\n };\n\n" + fprintf file "\n }\n\n" ;; let gen_enums file = @@ -720,7 +728,7 @@ let gen_error file name params = (fun field -> "String " ^ field) fields) in fprintf file " /**\n"; - fprintf file " * %s\n" params.err_doc; + fprintf file " * %s\n" (escape_xml params.err_doc); fprintf file " */\n"; fprintf file " public static class %s extends XenAPIException {\n" name; @@ -728,18 +736,9 @@ let gen_error file name params = fprintf file "\n /**\n"; fprintf file " * Create a new %s\n" name; - - if List.length fields > 0 - then - begin - fprintf file " *\n"; - List.iter - (fun s -> fprintf file " * @param %s\n" s) fields - end; - fprintf file " */\n"; fprintf file " public %s(%s) {\n" name constructor_params; - fprintf file " super(\"%s\");\n" params.err_doc; + fprintf file " super(\"%s\");\n" (escape_xml params.err_doc); List.iter (fun s -> fprintf file " this.%s = %s;\n" s s) fields; diff --git a/powershell/autogen/XenServer.types.ps1xml b/powershell/autogen/XenServer.types.ps1xml index 3426499..065f02a 100644 --- a/powershell/autogen/XenServer.types.ps1xml +++ b/powershell/autogen/XenServer.types.ps1xml @@ -29,15 +29,13 @@ OF THE POSSIBILITY OF SUCH DAMAGE. --> - - XenAPI.Session - - - APIVersionString - - ([string]$this.APIVersion).Replace("API_", "").Replace("_", ".") - - - - + + XenAPI.Session + + + APIVersionString + [XenAPI.Helper]::APIVersionString($this.APIVersion) + + + diff --git a/powershell/templates/XenServerPowerShell.csproj.mustache b/powershell/templates/XenServerPowerShell.csproj.mustache index afaabd9..2acba0b 100644 --- a/powershell/templates/XenServerPowerShell.csproj.mustache +++ b/powershell/templates/XenServerPowerShell.csproj.mustache @@ -18,6 +18,7 @@ DEBUG;TRACE prompt 4 + true false Program C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe