summaryrefslogtreecommitdiffstats
path: root/bindings/csharp/test_xcap/Program.cs
blob: 3c88733c1009fa8cbff29374af4e2095f5595fc6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace test_xcap
{
    class Program
    {
        const String REALM = "micromethod.com";
        const String USER = "mamadou";
        const String PASSWORD = "mamadou";
        const String HOST = "192.168.0.10";
        const int PORT = 8080;
        
        static void Main(string[] args)
        {
            xcapStack = new MyXcapStack(new MyXcapCallback(), String.Format("sip:{0}@{1}", USER, REALM), PASSWORD, String.Format("http://{0}:{1}/services", HOST, PORT));
            xcapSelector = new XcapSelector(xcapStack);

            if (!xcapStack.start())
            {
                Console.WriteLine("Failed to start the XCAP stack");
            }

            xcapStack.addHeader("Connection", "Keep-Alive");
		    xcapStack.addHeader("User-Agent", "XDM-client/OMA1.1");
            xcapStack.addHeader("X-3GPP-Intended-Identity", String.Format("sip:{0}@{1}", USER, REALM));

            //xcapSelector.setAUID("resource-lists").
            //    setAttribute("list", "name", "rcs").
            //    setAttribute("entry", "uri", String.Format("sip:{0}@{1}", USER, REALM)).
            //    setName("display-name");

            //xcapSelector.setAUID("xcap-caps");
           // xcapStack.getDocument(xcapSelector.getString());
           // xcapSelector.reset();
           // Console.ReadLine();

            xcapSelector.setAUID("resource-lists");
            xcapStack.getDocument(xcapSelector.getString());
            xcapSelector.reset();
            Console.ReadLine();

            xcapStack.stop();

            Console.ReadLine();
            
            xcapStack.start();

            xcapSelector.setAUID("xcap-caps");
            xcapStack.getDocument(xcapSelector.getString());
            xcapSelector.reset();
            Console.ReadLine();

            Console.ReadLine();
        }

        static XcapSelector xcapSelector;
        static MyXcapStack xcapStack;


        class MyXcapStack : XcapStack
        {
            public MyXcapStack(MyXcapCallback callback, string xui, string password, string xcap_root)
                : base(callback, xui, password, xcap_root)
            {
            }
        }

        class MyXcapCallback : XcapCallback
        {
            public MyXcapCallback()
                :base()
            {
            }

            public override int onEvent(XcapEvent e)
            {
                XcapMessage message = e.getXcapMessage();
                String content_type;

                if(message == null){
                    Console.WriteLine("Invalid Xcap message");
                    return -1;
                }

                Console.WriteLine("code={0} and Phrase={1}", message.getCode(), message.getPhrase());
                
                if((content_type = message.getXcapHeaderValue("Content-Type")) != null){
                    Console.WriteLine("Content-Type={0}", content_type);
                    uint clen = message.getXcapContentLength();
                    if (clen > 0)
                    {
                        byte[] content = new byte[clen];
                        uint read = message.getXcapContent(content, (uint)content.Length);
                        Console.WriteLine("Content-Value ==> {0}", Encoding.UTF8.GetString(content));
                    }
                }

                

                return base.onEvent(e);
            }
        }
    }
}
OpenPOWER on IntegriCloud