KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jcifs > dcerpc > DcerpcBinding


1 /* jcifs msrpc client library in Java
2  * Copyright (C) 2006 "Michael B. Allen" <jcifs at samba dot org>
3  * "Eric Glass" <jcifs at samba dot org>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package jcifs.dcerpc;
21
22 import java.util.HashMap JavaDoc;
23 import java.util.Iterator JavaDoc;
24
25 import jcifs.dcerpc.msrpc.*;
26
27 class DcerpcBinding {
28
29     private static HashMap JavaDoc INTERFACES;
30
31     static {
32         INTERFACES = new HashMap JavaDoc();
33         INTERFACES.put("srvsvc", srvsvc.getSyntax());
34         INTERFACES.put("lsarpc", lsarpc.getSyntax());
35         INTERFACES.put("samr", samr.getSyntax());
36     }
37
38     String JavaDoc proto;
39     String JavaDoc server;
40     String JavaDoc endpoint = null;
41     HashMap JavaDoc options = null;
42     UUID uuid = null;
43     int major;
44     int minor;
45
46     DcerpcBinding(String JavaDoc proto, String JavaDoc server) {
47         this.proto = proto;
48         this.server = server;
49     }
50
51     void setOption(String JavaDoc key, Object JavaDoc val) throws DcerpcException {
52         if (key.equals("endpoint")) {
53             endpoint = val.toString().toLowerCase();
54             if (endpoint.startsWith("\\pipe\\")) {
55                 String JavaDoc iface = (String JavaDoc)INTERFACES.get(endpoint.substring(6));
56                 if (iface != null) {
57                     int c, p;
58                     c = iface.indexOf(':');
59                     p = iface.indexOf('.', c + 1);
60                     uuid = new UUID(iface.substring(0, c));
61                     major = Integer.parseInt(iface.substring(c + 1, p));
62                     minor = Integer.parseInt(iface.substring(p + 1));
63                     return;
64                 }
65             }
66             throw new DcerpcException("Bad endpoint: " + endpoint);
67         }
68         if (options == null)
69             options = new HashMap JavaDoc();
70         options.put(key, val);
71     }
72     Object JavaDoc getOption(String JavaDoc key) {
73         if (key.equals("endpoint"))
74             return endpoint;
75         return options.get(key);
76     }
77
78     public String JavaDoc toString() {
79         String JavaDoc ret = proto + ":" + server + "[" + endpoint;
80         if (options != null) {
81             Iterator JavaDoc iter = options.keySet().iterator();
82             while (iter.hasNext()) {
83                 Object JavaDoc key = iter.next();
84                 Object JavaDoc val = options.get(key);
85                 ret += "," + key + "=" + val;
86             }
87         }
88         ret += "]";
89         return ret;
90     }
91 }
92
Popular Tags