1 /*----------------------------------------------------------------------------
2 Name: HelloWorld.c
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 Comment: HelloWorld connects with raw socket to xmlBlaster
6 Author: "Marcel Ruff" <xmlBlaster@marcelruff.info>
7 Compile:
8 Linux C:
9 gcc -Wall -g -Wno-long-long -D_REENTRANT -I. -o HelloWorld HelloWorld.c util/helper.c util/msgUtil.c util/Timestampc.c \
10 util/Properties.c socket/xmlBlasterSocket.c socket/xmlBlasterZlib.c socket/XmlBlasterConnectionUnparsed.c
11
12 With zlib compression:
13 gcc -Wall -pedantic -Wno-long-long -D_REENTRANT -g -DXMLBLASTER_ZLIB=1 -I. -o HelloWorld HelloWorld.c util/helper.c \
14 util/msgUtil.c util/Timestampc.c util/Properties.c socket/xmlBlasterSocket.c socket/xmlBlasterZlib.c socket/XmlBlasterConnectionUnparsed.c \
15 -I/opt/zlib/include -L/opt/zlib/lib -lz
16
17 Start with: "HelloWorld -plugin/socket/compress/type zlib:stream"
18
19 Linux C++: g++ -Wall -g -D_REENTRANT -I. -o HelloWorld HelloWorld.c util/helper.c util/msgUtil.c util/Timestampc.c \
20 util/Properties.c socket/xmlBlasterSocket.c socket/xmlBlasterZlib.c socket/XmlBlasterConnectionUnparsed.c \
21 -DXMLBLASTER_C_COMPILE_AS_CPP
22
23 Linux Intel compiler:
24 icc -g -D_REENTRANT -I. -o HelloWorld HelloWorld.c util/helper.c util/msgUtil.c util/Timestampc.c \
25 util/Properties.c socket/xmlBlasterSocket.c socket/xmlBlasterZlib.c socket/XmlBlasterConnectionUnparsed.c
26
27 Win: cl /MT /W3 /Wp64 -D_WINDOWS -DDLL_IGNORE -DXB_NO_PTHREADS -I. HelloWorld.c util\helper.c util\msgUtil.c util\Timestampc.c \
28 util\Properties.c socket\xmlBlasterSocket.c socket\xmlBlasterZlib.c socket\XmlBlasterConnectionUnparsed.c ws2_32.lib
29
30 WinCE: -DWINCE ...
31
32 Sun: cc -g -D_REENTRANT -I. -o HelloWorld HelloWorld.c util/helper.c util/msgUtil.c util/Timestampc.c
33 util/Properties.c socket/xmlBlasterSocket.c socket/xmlBlasterZlib.c
34 socket/XmlBlasterConnectionUnparsed.c -lsocket -lnsl
35
36 Linux with shared lib:
37 gcc -o HelloWorld HelloWorld.c -L../../lib -lxmlBlasterClientC -I.
38 -Wl,-rpath=../../lib -lpthread
39
40 HP-UX 11 with gcc. 2.8.1:
41 gcc -g -I. -UXB_USE_PTHREADS -o HelloWorld HelloWorld.c util/helper.c util/msgUtil.c util/Timestampc.c util/Properties.c
42 socket/xmlBlasterSocket.c socket/XmlBlasterConnectionUnparsed.c socket/xmlBlasterZlib.c
43 Date: 05/2003
44 -----------------------------------------------------------------------------*/
45 #if !defined(__IPhoneOS__)
46 #include <stdio.h>
47 #include <stdlib.h>
48 #include <string.h>
49 #include <XmlBlasterConnectionUnparsed.h>
50
51 #if defined(WINCE)
52 #include "HelloWorldCE/stdafx.h"
53 #endif
54
55 /**
56 * Access the free memory in the server.
57 */
58 #if defined(WINCE)
59 int _tmain(int argc, _TCHAR** argv_wcs) { /* wchar_t==_TCHAR */
60 char **argv = convertWcsArgv(argv_wcs, argc);
61 #else
62 int main(int argc, const char* const* argv) {
63 #endif
64 MsgUnitArr *msgUnitArr;
65 XmlBlasterException exception;
66 const char *connectQos;
67 char *response;
68
69 XmlBlasterConnectionUnparsed *xb = getXmlBlasterConnectionUnparsed(argc, argv);
70
71 connectQos = "<qos>"
72 " <securityService type='htpasswd' version='1.0'>"
73 " <user>fritz</user>"
74 " <passwd>secret</passwd>"
75 " </securityService>"
76 "</qos>";
77 response = xb->connect(xb, connectQos, &exception);
78 free(response);
79 if (*exception.errorCode != '\0') {
80 printf("[client] Caught exception during connect, errorCode=%s, message=%s\n",
81 exception.errorCode, exception.message);
82 freeXmlBlasterConnectionUnparsed(&xb);
83 exit(1);
84 }
85
86 printf("[HelloWorld] Connected to xmlBlaster, invoking now get() ...\n");
87
88 msgUnitArr = xb->get(xb, "<key oid='__cmd:?freeMem'/>", 0, &exception);
89 if (*exception.errorCode != '\0') {
90 printf("[HelloWorld] Caught exception in get errorCode=%s, message=%s\n",
91 exception.errorCode, exception.message);
92 freeXmlBlasterConnectionUnparsed(&xb);
93 exit(1);
94 }
95 if (msgUnitArr != (MsgUnitArr *)0 && msgUnitArr->len > 0) {
96 char *contentStr = strFromBlobAlloc(msgUnitArr->msgUnitArr[0].content,
97 msgUnitArr->msgUnitArr[0].contentLen);
98 printf("[HelloWorld] xmlBlaster has %s bytes of free memory\n", contentStr);
99 free(contentStr);
100 }
101 freeMsgUnitArr(msgUnitArr);
102
103 (void)xb->disconnect(xb, 0, &exception);
104
105 freeXmlBlasterConnectionUnparsed(&xb);
106 printf("[HelloWorld] Good bye.\n");
107 # if defined(WINCE)
108 freeArgv(argv, argc);
109 # endif
110 return 0;
111 }
112 #endif /* IPhoneOS */
syntax highlighted by Code2HTML, v. 0.9.1