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
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
1.2.0 (4 Mar 2014)
------------------

* Java SDK: generate automatically overloads for methods with changed signature
for compatibility with older servers. Other smaller enhancements.
* C# SDK: added xml documentation. Overloads for methods with changed signature
are now generated automatically.
* Fixes for build system changes.
* Corrections to the versioning of the SDK.
* Bugs fixed: CA-111642, CA-112409, CA-121354, CA-121355, CA-124147, CA-125856,
CA-126990, CA-127849.

1.1.0 (23 Jul 2013)
-------------------

Expand Down
10 changes: 5 additions & 5 deletions OMakefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ ZipUp(dir, dest) =
cd $(dir)/.. && zip -q -r9 $(d) $(basename $(dir)) && mv $(d) $(dest)

CSharpReadme(dir, specific) =
sed -e 's/@PRODUCT_VERSION@/$(PRODUCT_VERSION)/g' csharp/README-common.txt.dist >$(dir)/README.txt
sed -e 's/@SDK_VERSION@/$(SDK_VERSION)/g' csharp/README-common.txt.dist >$(dir)/README.txt
cat csharp/README-$(specific).txt.dist >>$(dir)/README.txt
$(INSTALL) $(XMLRPCLICENSE) $(dir)/LICENSE.CookComputing.XmlRpcV2
$(INSTALL) LICENSE $(dir)/LICENSE.txt

InstallAndBrand(sourcefile, targetfile) =
$(INSTALL) $(sourcefile) $(targetfile)
sed -i -e 's/@PRODUCT_VERSION@/$(PRODUCT_VERSION)/g' $(targetfile)
sed -i -e 's/@SDK_VERSION@/$(SDK_VERSION)/g' $(targetfile)

csharp_src: gen_gui_csharp_bindings
mkdir -p $(CSHARP_SRC_TMP)/Properties
Expand All @@ -79,7 +79,7 @@ csharp_src: gen_gui_csharp_bindings
$(INSTALL) $(CSHARP_GEN)/FriendlyErrorNames.resx $(CSHARP_SRC_TMP)
$(INSTALL) $(SUPPORT_CS) $(CSHARP_SRC_TMP)
mv $(CSHARP_SRC_TMP)/AssemblyInfo.cs $(CSHARP_SRC_TMP)/Properties/AssemblyInfo.cs
sed -i -e 's/1\.0\.0\.0/$(PRODUCT_VERSION).0/g' $(CSHARP_SRC_TMP)/Properties/AssemblyInfo.cs
sed -i -e 's/1\.0\.0\.0/$(SDK_VERSION).0/g' $(CSHARP_SRC_TMP)/Properties/AssemblyInfo.cs
mv $(CSHARP_GEN)/XenObjectDownloader.tmp $(CSHARP_GEN)/XenObjectDownloader.cs
CSharpReadme($(CSHARP_SRC_TMP), src)
Flip($(CSHARP_SRC_TMP))
Expand Down Expand Up @@ -110,8 +110,8 @@ $(BINDINGS_TMP)/XenCenterBindings.zip: gen_gui_csharp_bindings
powershell_src: csharp_src gen_powershell_bindings
mkdir -p $(POWERSHELL_TMP)
$(INSTALL) powershell/src/*.cs $(POWERSHELL_TMP)
sed -i -e 's/1\.0\.0\.0/$(PRODUCT_VERSION)/g' $(POWERSHELL_TMP)/AssemblyInfo.cs
sed -i -e 's/1000/$(PRODUCT_VERSION).0/g' $(POWERSHELL_TMP)/AssemblyInfo.cs
sed -i -e 's/1\.0\.0\.0/$(SDK_VERSION)/g' $(POWERSHELL_TMP)/AssemblyInfo.cs
sed -i -e 's/1000/$(SDK_VERSION).0/g' $(POWERSHELL_TMP)/AssemblyInfo.cs
$(INSTALL) $(POWERSHELL_GEN)/* $(POWERSHELL_TMP)
InstallAndBrand(powershell/README.txt.dist, $(POWERSHELL_TMP)/README.txt)
InstallAndBrand(powershell/about_XenServer.help.txt, $(POWERSHELL_TMP)/about_XenServer.help.txt)
Expand Down
2 changes: 1 addition & 1 deletion c/Makefile.dist
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ LIBXENAPI_OBJS = $(patsubst %.c, %.o, $(wildcard src/*.c))

TEST_PROGRAMS = test/test_vm_ops test/test_event_handling \
test/test_failures test/test_vm_async_migrate \
test/test_enumerate
test/test_enumerate test/test_get_records

TARBALL_DEST = lib@LIB_NAME@-$(MAJOR).$(MINOR)

Expand Down
2 changes: 1 addition & 1 deletion c/OMakefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ c_source: gen_c_binding
cp $(C_GEN_FOLDER)/*.c $(C_SRC_TMP_FOLDER)/src
sed -e s/@LIB_MAJOR@/$(API_MAJOR)/g -e s/@LIB_MINOR@/$(API_MINOR)/g -e s/@LIB_NAME@/xenserver/g Makefile.dist > $(C_SRC_TMP_FOLDER)/Makefile
cp ../LICENSE $(C_SRC_TMP_FOLDER)/COPYING
sed -e 's/@PRODUCT_VERSION@/$(PRODUCT_VERSION)/g' README.dist >$(C_SRC_TMP_FOLDER)/README
sed -e 's/@SDK_VERSION@/$(SDK_VERSION)/g' README.dist >$(C_SRC_TMP_FOLDER)/README
cp xen_internal.h $(C_SRC_TMP_FOLDER)/include
cp xen_common.h xen_string_set.h $(C_SRC_TMP_FOLDER)/include/xen/api
cp xen_common.c xen_string_set.c $(C_SRC_TMP_FOLDER)/src
Expand Down
6 changes: 3 additions & 3 deletions c/README.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
libxenserver
============

Version @PRODUCT_VERSION@
Version @SDK_VERSION@

libxenserver is a complete SDK for Citrix XenServer, exposing the XenServer
API to C programmers.
Expand Down Expand Up @@ -47,13 +47,13 @@ On Debian, these are packaged as libxml2-dev and libcurl3-dev.
Downloads
---------

libxenserver is available in the XenServer-@PRODUCT_VERSION@-SDK.zip in two separate
libxenserver is available in the XenServer-SDK-@SDK_VERSION@.zip in two separate
folders, one for the compiled binaries, and one for the source code.
The binaries are compiled for the XenServer SDK virtual machine, and we
recommend compiling from source if you wish to use the library in a
different environment.

The XenServer-@PRODUCT_VERSION@-SDK.zip is available from
The XenServer-SDK-@SDK_VERSION@.zip is available from
http://www.citrix.com/downloads/xenserver/.


Expand Down
46 changes: 17 additions & 29 deletions c/gen_c_binding.ml
Original file line number Diff line number Diff line change
Expand Up @@ -865,8 +865,8 @@ extern %s *
and write_map_impl name l r out_chan =
let print format = fprintf out_chan format in
let tn = typename name in
let l_free_impl = free_impl "map->contents[i].key" l in
let r_free_impl = free_impl "map->contents[i].val" r in
let l_free_impl = free_impl "map->contents[i].key" false l in
let r_free_impl = free_impl "map->contents[i].val" true r in
let needed = ref StringSet.empty in
find_needed'' needed l;
find_needed'' needed r;
Expand Down Expand Up @@ -1242,42 +1242,30 @@ and find_needed'' needed = function
()

and record_free_impl prefix = function
Field fr ->
free_impl (prefix ^ (fieldname fr.field_name)) fr.ty
| Field fr -> free_impl (prefix ^ (fieldname fr.field_name)) true fr.ty
| Namespace (p, c) -> joined "\n " (record_free_impl (prefix ^ (fieldname p) ^ "_")) c

| Namespace (p, c) ->
joined "\n "
(record_free_impl (prefix ^ (fieldname p) ^ "_")) c


and free_impl val_name = function
| String -> sprintf "free(%s);" val_name
and free_impl val_name record = function
| String -> sprintf "free(%s);" val_name
| Int
| Float
| Bool
| DateTime
| Enum (_, _) ->
""
| Ref n ->
sprintf "%s_free(%s);" (record_opt_typename n) val_name
| Set(Ref n) ->
sprintf "%s_opt_set_free(%s);" (record_typename n) val_name
| Set(Enum (e, _)) ->
sprintf "%s_set_free(%s);" (typename e) val_name
| Set(String) ->
sprintf "xen_string_set_free(%s);" val_name
| Map(l, r) ->
let n = mapname l r in
sprintf "%s_free(%s);" (typename n) val_name
| Record x -> sprintf "%s_free(%s);" (record_typename x) val_name
| _ -> "DONT_KNOW"
| Enum (_, _) -> ""
| Ref n -> sprintf "%s_free(%s);" (if record then record_opt_typename n else typename n) val_name
| Set(Ref n) -> sprintf "%s_opt_set_free(%s);" (record_typename n) val_name
| Set(Enum (e, _)) -> sprintf "%s_set_free(%s);" (typename e) val_name
| Set(String) -> sprintf "xen_string_set_free(%s);" val_name
| Map(l, r) -> let n = mapname l r in
sprintf "%s_free(%s);" (typename n) val_name
| Record x -> sprintf "%s_free(%s);" (record_typename x) val_name
| _ -> "DONT_KNOW"


and add_enum_internal needed = function
Enum(x, _) ->
StringSet.add (x ^ "_internal") needed
| _ ->
needed
| Enum(x, _) -> StringSet.add (x ^ "_internal") needed
| _ -> needed


and add_enum_map_internal needed l r =
Expand Down
223 changes: 223 additions & 0 deletions c/test/test_get_records.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
/*
* 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.
*/

#define _GNU_SOURCE
#include <assert.h>
#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <libxml/parser.h>
#include <curl/curl.h>
#include <xen/api/xen_all.h>


static void usage()
{
fprintf(stderr,
"Usage:\n"
"\n"
" test_get_records <url> <username> <password>\n"
"\n"
"where\n"
" <url> is the server's URL, e.g. https://server.example.com\n"
" <username> is the username to use at the server; and\n"
" <password> is the password.\n");

exit(EXIT_FAILURE);
}


static char *url;


typedef struct
{
xen_result_func func;
void *handle;
} xen_comms;


static size_t
write_func(void *ptr, size_t size, size_t nmemb, xen_comms *comms)
{
size_t n = size * nmemb;
#ifdef PRINT_XML
printf("\n\n---Result from server -----------------------\n");
printf("%s\n",((char*) ptr));
fflush(stdout);
#endif
return comms->func(ptr, n, comms->handle) ? n : 0;
}


static int
call_func(const void *data, size_t len, void *user_handle,
void *result_handle, xen_result_func result_func)
{
(void)user_handle;

#ifdef PRINT_XML
printf("\n\n---Data to server: -----------------------\n");
printf("%s\n",((char*) data));
fflush(stdout);
#endif

CURL *curl = curl_easy_init();
if (!curl) {
return -1;
}

xen_comms comms = {
.func = result_func,
.handle = result_handle
};

curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
#ifdef CURLOPT_MUTE
curl_easy_setopt(curl, CURLOPT_MUTE, 1);
#endif
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &write_func);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &comms);
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, len);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);

CURLcode result = curl_easy_perform(curl);

curl_easy_cleanup(curl);

return result;
}


static void print_error(xen_session *session)
{
fprintf(stderr, "Error: %d", session->error_description_count);
for (int i = 0; i < session->error_description_count; i++)
{
fprintf(stderr, "%s ", session->error_description[i]);
}
fprintf(stderr, "\n");
}


int main(int argc, char **argv)
{
if (argc != 4)
usage();

url = argv[1];
char *username = argv[2];
char *password = argv[3];

xmlInitParser();
xen_init();
curl_global_init(CURL_GLOBAL_ALL);

#define CLEANUP \
do { \
xen_session_logout(session); \
curl_global_cleanup(); \
xen_fini(); \
xmlCleanupParser(); \
} while(0) \


xen_session *session = xen_session_login_with_password(call_func, NULL,
username, password, xen_api_latest_version);


/* Print some info for hosts */

xen_host_xen_host_record_map *hostRecords;
if (!xen_host_get_all_records(session, &hostRecords))
{
print_error(session);
CLEANUP;
return 1;
}

for (size_t i = 0; i < hostRecords->size; i++)
{
xen_host_record *rec = hostRecords->contents[i].val;
printf("Host: %s, edition: %s\n", rec->name_label, rec->edition);
}

xen_host_xen_host_record_map_free(hostRecords);

/* Print some info for templates */

xen_vm_xen_vm_record_map *vmRecords;
if (!xen_vm_get_all_records(session, &vmRecords))
{
print_error(session);
CLEANUP;
return 1;
}

for (size_t i = 0; i < vmRecords->size; i++)
{
xen_vm_record *rec = vmRecords->contents[i].val;
if (!rec->is_a_template)
continue;

printf("VM: %s, vCPUs max: %" PRId64 "\n", rec->name_label, rec->vcpus_max);
}

xen_vm_xen_vm_record_map_free(vmRecords);

/* Print some info for storage repositories */

xen_sr_xen_sr_record_map *srRecords;
if (!xen_sr_get_all_records(session, &srRecords))
{
print_error(session);
CLEANUP;
return 1;
}

for (size_t i = 0; i < srRecords->size; i++)
{
xen_sr_record *rec = srRecords->contents[i].val;
printf("SR: %s -> Free space: %" PRId64 "\n",
rec->name_label,
rec->physical_size - rec->physical_utilisation);
}

xen_sr_xen_sr_record_map_free(srRecords);

CLEANUP;
return 0;
}
Loading