]> xenbits.xensource.com Git - xcp/xen-api-libs.git/commitdiff
[refactoring] Move RSS from xen-api.hg to xen-api-libs.hg
authorDavid Scott <dave.scott@eu.citrix.com>
Mon, 26 Oct 2009 16:32:15 +0000 (16:32 +0000)
committerDavid Scott <dave.scott@eu.citrix.com>
Mon, 26 Oct 2009 16:32:15 +0000 (16:32 +0000)
rss/META.in [new file with mode: 0644]
rss/Makefile [new file with mode: 0644]
rss/rss.ml [new file with mode: 0644]
rss/rss.mli [new file with mode: 0644]

diff --git a/rss/META.in b/rss/META.in
new file mode 100644 (file)
index 0000000..d4283ad
--- /dev/null
@@ -0,0 +1,5 @@
+version = "@VERSION@"
+description = "RSS library"
+requires = "xml-light2"
+archive(byte) = "rss.cma"
+archive(native) = "rss.cmxa"
diff --git a/rss/Makefile b/rss/Makefile
new file mode 100644 (file)
index 0000000..7458e07
--- /dev/null
@@ -0,0 +1,56 @@
+CC = gcc
+CFLAGS = -Wall -fPIC -O2 -I/opt/xensource/lib/ocaml
+OCAMLC = ocamlc -g
+OCAMLOPT = ocamlopt
+
+LDFLAGS = -cclib -L./
+
+DESTDIR ?= /
+VERSION := $(shell hg parents --template "{rev}" 2>/dev/null || echo 0.0)
+OCAMLOPTFLAGS = -g -dtypes
+
+OCAMLABI := $(shell ocamlc -version)
+OCAMLLIBDIR := $(shell ocamlc -where)
+OCAMLDESTDIR ?= $(OCAMLLIBDIR)
+
+OBJS = rss
+INTF = $(foreach obj, $(OBJS),$(obj).cmi)
+LIBS = rss.cma rss.cmxa
+
+all: $(INTF) $(LIBS) $(PROGRAMS)
+
+bins: $(PROGRAMS)
+
+libs: $(LIBS)
+
+rss.cmxa: $(foreach obj,$(OBJS),$(obj).cmx)
+       $(OCAMLOPT) $(OCAMLOPTFLAGS) -a -o $@ $(foreach obj,$(OBJS),$(obj).cmx)
+
+rss.cma: $(foreach obj,$(OBJS),$(obj).cmo)
+       $(OCAMLC) -a -o $@ $(foreach obj,$(OBJS),$(obj).cmo)
+
+%.cmo: %.ml
+       $(OCAMLC) -c -I ../xml-light2 -o $@ $<
+
+%.cmi: %.mli
+       $(OCAMLC) -c -I ../xml-light2 -o $@ $<
+
+%.cmx: %.ml
+       $(OCAMLOPT) $(OCAMLOPTFLAGS) -c -I ../xml-light2 -o $@ $<
+
+%.o: %.c
+       $(CC) $(CFLAGS) -c -o $@ $<
+
+META: META.in
+       sed 's/@VERSION@/$(VERSION)/g' < $< > $@
+
+.PHONY: install
+install: $(LIBS) META
+       ocamlfind install -destdir $(DESTDIR)$(shell ocamlfind printconf destdir) -ldconf ignore rss META $(INTF) $(LIBS) *.a *.cmx
+
+.PHONY: uninstall
+uninstall:
+       ocamlfind remove rss
+
+clean:
+       rm -f *.o *.so *.a *.cmo *.cmi *.cma *.cmx *.cmxa *.annot $(LIBS) $(PROGRAMS)
\ No newline at end of file
diff --git a/rss/rss.ml b/rss/rss.ml
new file mode 100644 (file)
index 0000000..1a0caad
--- /dev/null
@@ -0,0 +1,67 @@
+(*
+ * Copyright (C) 2006-2009 Citrix Systems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *)
+type item_info = {
+       item_title: string;
+       item_link: string option;
+       item_description: string;
+       item_pubdate: string;
+}
+
+type channel_info = {
+       chan_title: string;
+       chan_description: string;
+       chan_language: string;
+       chan_pubdate: string;
+       chan_items: item_info list;
+}
+
+let to_xml chans =
+       let simple_node nodename pcdata =
+               Xml.Element (nodename, [], [ Xml.PCData pcdata ])
+               in
+       let simple_optional_node nodename pcdata =
+               match pcdata with
+               | None -> []
+               | Some pcdata -> [ simple_node nodename pcdata ]
+               in
+       let item_to_xml item =
+               let itemchildren =
+                       [ simple_node "title" item.item_title ] @
+                       (simple_optional_node "link" item.item_link) @
+                       [ simple_node "description" item.item_description ] @
+                       [ simple_node "pubDate" item.item_pubdate ] @
+                       []
+                       in
+               Xml.Element ("item", [], itemchildren)
+               in
+       let channel_to_xml chan =
+               let infos_xml =
+                       [ simple_node "title" chan.chan_title ] @
+                       [ simple_node "description" chan.chan_description ] @
+                       [ simple_node "language" chan.chan_language ] @
+                       [ simple_node "pubDate" chan.chan_pubdate ] @
+                       [ simple_node "generator" "Xapi alerts generator" ] @
+                       []
+                       in
+               let items_xml = List.map item_to_xml chan.chan_items in
+               Xml.Element ("channel", [], infos_xml @ items_xml)
+               in
+       Xml.Element ("rss", [ ("version", "2.0") ],
+                    List.map channel_to_xml chans)
+
+let to_stream rsschans outchan =
+       output_string outchan "<?xml version=\"1.0\"?>\n";
+       output_string outchan (Xml.to_string (to_xml rsschans));
+       flush outchan;
+       ()
diff --git a/rss/rss.mli b/rss/rss.mli
new file mode 100644 (file)
index 0000000..fd994c5
--- /dev/null
@@ -0,0 +1,29 @@
+(*
+ * Copyright (C) 2006-2009 Citrix Systems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *)
+
+type item_info = {
+  item_title : string;
+  item_link : string option;
+  item_description : string;
+  item_pubdate : string;
+}
+type channel_info = {
+  chan_title : string;
+  chan_description : string;
+  chan_language : string;
+  chan_pubdate : string;
+  chan_items : item_info list;
+}
+val to_xml : channel_info list -> Xml.xml
+val to_stream : channel_info list -> out_channel -> unit