Skip to content
This repository was archived by the owner on Feb 19, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 18 additions & 24 deletions csharp/autogen/src/HTTP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,37 +358,31 @@ public static Uri BuildUri(string hostname, string path, params object[] args)
flatargs.Add(arg);
}

UriBuilder uri = new UriBuilder();
uri.Scheme = "https";
uri.Port = DEFAULT_HTTPS_PORT;
uri.Host = hostname;
uri.Path = path;

StringBuilder query = new StringBuilder();
var query = new StringBuilder();
for (int i = 0; i < flatargs.Count - 1; i += 2)
{
string kv;

// If the argument is null, don't include it in the URL
if (flatargs[i + 1] == null)
if (flatargs[i + 1] == null)//skip null arguments
continue;

// bools are special because some xapi calls use presence/absence and some
// use "b=true" (not "True") and "b=false". But all accept "b=true" or absent.
if (flatargs[i + 1] is bool)
{
if (!((bool)flatargs[i + 1]))
continue;
kv = flatargs[i] + "=true";
}
else
kv = flatargs[i] + "=" + Uri.EscapeDataString(flatargs[i + 1].ToString());

if (query.Length != 0)
query.Append('&');
query.Append(kv);

query.Append(flatargs[i]).Append("=");

if (flatargs[i + 1] is bool)
query.Append((bool)flatargs[i + 1] ? "true" : "false");
else
query.Append(Uri.EscapeDataString(flatargs[i + 1].ToString()));
}
uri.Query = query.ToString();

UriBuilder uri = new UriBuilder
{
Scheme = "https",
Port = DEFAULT_HTTPS_PORT,
Host = hostname,
Path = path,
Query = query.ToString()
};

return uri.Uri;
}
Expand Down
109 changes: 36 additions & 73 deletions csharp/gen_csharp_binding.ml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ let rec main() =
classes |> List.filter (fun x-> x.name <> "session") |> List.iter gen_class_file;
TypeSet.iter gen_enum !enums;
gen_maps();
gen_http_actions();
render_file ("HTTP_actions.mustache", "HTTP_actions.cs") (gen_http_actions()) templdir destdir;
gen_relations();
let sorted_members = List.sort String.compare !api_members in
let json = `O ["api_members", `A (List.map (fun x -> `O ["api_member", `String x];) sorted_members); ] in
Expand Down Expand Up @@ -174,89 +174,52 @@ and gen_relation out_chan (manyField, oneClass, oneField) =
(* ------------------- category: http_actions *)

and gen_http_actions() =
let out_chan = open_out (Filename.concat destdir "HTTP_actions.cs") in
let print format = fprintf out_chan format in

let print_header() = print
"%s

using System;
using System.Text;
using System.Net;

namespace XenAPI
{
public partial class HTTP_actions
{
private static void Get(HTTP.DataCopiedDelegate dataCopiedDelegate, HTTP.FuncBool cancellingDelegate, int timeout_ms,
string hostname, string remotePath, IWebProxy proxy, string localPath, params object[] args)
{
HTTP.Get(dataCopiedDelegate, cancellingDelegate, HTTP.BuildUri(hostname, remotePath, args), proxy, localPath, timeout_ms);
}

private static void Put(HTTP.UpdateProgressDelegate progressDelegate, HTTP.FuncBool cancellingDelegate, int timeout_ms,
string hostname, string remotePath, IWebProxy proxy, string localPath, params object[] args)
{
HTTP.Put(progressDelegate, cancellingDelegate, HTTP.BuildUri(hostname, remotePath, args), proxy, localPath, timeout_ms);
}"
Licence.bsd_two_clause
in

let print_footer() = print "\n }\n}\n" in

(* Each action has:
(unique public name, (HTTP method, URI, whether to expose in SDK, [args to expose in SDK], [allowed_roles], [(sub-action,allowed_roles)]))
*)
let decl_of_sdkarg = function
String_query_arg s -> "string " ^ (escaped s)
| Int64_query_arg s -> "long " ^ (escaped s)
| Bool_query_arg s -> "bool " ^ (escaped s)
| Varargs_query_arg -> "params string[] args /* alternate names & values */"
| String_query_arg s -> sprintf "string %s = null" (escaped s)
| Int64_query_arg s -> sprintf "long? %s = null" (escaped s)
| Bool_query_arg s -> sprintf "bool? %s = null" (escaped s)
| Varargs_query_arg -> "params string[] args /* alternate names and values */"
in

let use_of_sdkarg = function
String_query_arg s
| String_query_arg s
| Int64_query_arg s
| Bool_query_arg s -> "\"" ^ s ^ "\", " ^ (escaped s) (* "s", s *)
| Bool_query_arg s -> sprintf {|"%s", %s|} s (escaped s)
| Varargs_query_arg -> "args"
in

let string1 = function
Get -> "HTTP.DataCopiedDelegate dataCopiedDelegate"
| Put -> "HTTP.UpdateProgressDelegate progressDelegate"
let delegate_type = function
| Get -> "DataCopiedDelegate"
| Put -> "UpdateProgressDelegate"
| _ -> failwith "Unimplemented HTTP method"
in

let string2 = function
Get -> "Get(dataCopiedDelegate"
| Put -> "Put(progressDelegate"
let delegate_name = function
| Get -> "dataCopiedDelegate"
| Put -> "progressDelegate"
| _ -> failwith "Unimplemented HTTP method"
in

let print_one_action_core name meth uri sdkargs =
let enhanced_args = [String_query_arg "task_id"; String_query_arg "session_id"] @ sdkargs in
print "

public static void %s(%s, HTTP.FuncBool cancellingDelegate, int timeout_ms,
string hostname, IWebProxy proxy, string path, %s)
{
%s, cancellingDelegate, timeout_ms, hostname, \"%s\", proxy, path,
%s);
}"
name
(string1 meth)
(String.concat ", " (List.map decl_of_sdkarg enhanced_args))
(string2 meth)
uri
(String.concat ", " (List.map use_of_sdkarg enhanced_args))
in

let print_one_action(name, (meth, uri, sdk, sdkargs, _, _)) =
match sdk with
| false -> ()
| true -> print_one_action_core name meth uri sdkargs
let http_method = function
| Get -> "Get"
| Put -> "Put"
| _ -> failwith "Unimplemented HTTP method"
in

print_header();
List.iter print_one_action http_actions;
print_footer();
let action_json (name, (meth, uri, _, sdkargs, _, _)) =
let enhanced_args = [String_query_arg "task_id"; String_query_arg "session_id"] @ sdkargs in
`O [
"name", `String name;
"delegate_type", `String (delegate_type meth);
"delegate_name", `String (delegate_name meth);
"http_method", `String (http_method meth);
"uri", `String uri;
"sdkargs_decl", `String (enhanced_args |> List.map decl_of_sdkarg |> String.concat ", ");
"sdkargs", `String (enhanced_args |> List.map use_of_sdkarg |> String.concat ", ");
] in
let filtered_actions = http_actions |> List.filter (fun (_, (_, _, sdk, _, _, _)) -> sdk) in
`O [
"licence", `String Licence.bsd_two_clause;
"http_actions", `A (List.map action_json filtered_actions);
]

(* ------------------- category: classes *)

Expand Down
47 changes: 47 additions & 0 deletions csharp/templates/HTTP_actions.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{{{licence}}}

using System;
using System.Text;
using System.Net;

namespace XenAPI
{
public partial class HTTP_actions
{
private static void Get(HTTP.DataCopiedDelegate dataCopiedDelegate, HTTP.FuncBool cancellingDelegate, int timeout_ms,
string hostname, string remotePath, IWebProxy proxy, string localPath, params object[] args)
{
HTTP.Get(dataCopiedDelegate, cancellingDelegate, HTTP.BuildUri(hostname, remotePath, args), proxy, localPath, timeout_ms);
}

private static void Put(HTTP.UpdateProgressDelegate progressDelegate, HTTP.FuncBool cancellingDelegate, int timeout_ms,
string hostname, string remotePath, IWebProxy proxy, string localPath, params object[] args)
{
HTTP.Put(progressDelegate, cancellingDelegate, HTTP.BuildUri(hostname, remotePath, args), proxy, localPath, timeout_ms);
}

{{#http_actions}}
public static void {{name}}(HTTP.{{delegate_type}} {{delegate_name}}, HTTP.FuncBool cancellingDelegate, int timeout_ms,
string hostname, IWebProxy proxy, string path, {{{sdkargs_decl}}})
{
{{http_method}}({{delegate_name}}, cancellingDelegate, timeout_ms, hostname, "{{uri}}", proxy, path,
{{{sdkargs}}});
}

{{/http_actions}}

public static void get_pool_patch_download(HTTP.DataCopiedDelegate dataCopiedDelegate, HTTP.FuncBool cancellingDelegate, int timeout_ms,
string hostname, IWebProxy proxy, string path, string task_id, string session_id, string uuid)
{
Get(dataCopiedDelegate, cancellingDelegate, timeout_ms, hostname, "/pool_patch_download", proxy, path,
"task_id", task_id, "session_id", session_id, "uuid", uuid);
}

public static void put_oem_patch_stream(HTTP.UpdateProgressDelegate progressDelegate, HTTP.FuncBool cancellingDelegate, int timeout_ms,
string hostname, IWebProxy proxy, string path, string task_id, string session_id)
{
Put(progressDelegate, cancellingDelegate, timeout_ms, hostname, "/oem_patch_stream", proxy, path,
"task_id", task_id, "session_id", session_id);
}
}
}
69 changes: 69 additions & 0 deletions powershell/autogen/src/Receive-XenPoolPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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.
*/


using System;
using System.Collections;
using System.Collections.Generic;
using System.Management.Automation;
using System.Text;

using XenAPI;

namespace Citrix.XenServer.Commands
{
[Cmdlet(VerbsCommunications.Receive, "XenPoolPatch", SupportsShouldProcess = false)]
[OutputType(typeof(void))]
public class ReceiveXenPoolPatchCommand : XenServerHttpCmdlet
{
#region Cmdlet Parameters

[Parameter]
public HTTP.DataCopiedDelegate DataCopiedDelegate { get; set; }

[Parameter(ValueFromPipelineByPropertyName = true)]
public string Uuid { get; set; }

#endregion

#region Cmdlet Methods

protected override void ProcessRecord()
{
GetSession();

RunApiCall(() => XenAPI.HTTP_actions.get_pool_patch_download(DataCopiedDelegate,
CancellingDelegate, TimeoutMs, XenHost, Proxy, Path, TaskRef,
session.opaque_ref, Uuid));
}

#endregion
}
}
69 changes: 69 additions & 0 deletions powershell/autogen/src/Send-XenOemPatchStream.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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.
*/


using System;
using System.Collections;
using System.Collections.Generic;
using System.Management.Automation;
using System.Text;

using XenAPI;

namespace Citrix.XenServer.Commands
{
[Cmdlet(VerbsCommunications.Send, "XenOemPatchStream", SupportsShouldProcess = true)]
[OutputType(typeof(void))]
public class SendXenOemPatchStreamCommand : XenServerHttpCmdlet
{
#region Cmdlet Parameters

[Parameter]
public HTTP.UpdateProgressDelegate ProgressDelegate { get; set; }

#endregion

#region Cmdlet Methods

protected override void ProcessRecord()
{
GetSession();

if (!ShouldProcess("/oem_patch_stream"))
return;

RunApiCall(() => XenAPI.HTTP_actions.put_oem_patch_stream(ProgressDelegate,
CancellingDelegate, TimeoutMs, XenHost, Proxy, Path, TaskRef,
session.opaque_ref));
}

#endregion
}
}
6 changes: 3 additions & 3 deletions powershell/gen_powershell_binding.ml
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,15 @@ and gen_arg_param = function
(pascal_case_ x)
| Int64_query_arg x -> sprintf "
[Parameter]
public long %s { get; set; }\n" (pascal_case_ x)
public long? %s { get; set; }\n" (pascal_case_ x)
| Bool_query_arg x ->
let y = if x = "host" then "is_host" else x in
sprintf "
[Parameter]
public bool %s { get; set; }\n" (pascal_case_ y)
public bool? %s { get; set; }\n" (pascal_case_ y)
| Varargs_query_arg -> sprintf "
///<summary>
/// Alternate names & values
/// Alternate names and values
///</summary>
[Parameter]
public string[] Args { get; set; }\n"
Expand Down
Loading