xref: /illumos-gate/usr/src/lib/libslp/javalib/com/sun/slp/SSrvReg.java (revision 4f364e7c95ee7fd9d5bbeddc1940e92405bb0e72)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 1999, 2001 by Sun Microsystems, Inc.
23  * All rights reserved.
24  *
25  */
26 
27 //  SSrvReg.java:      Message class for SLP service registration request.
28 //  Author:           James Kempf
29 //  Created On:       Thu Oct  9 14:47:48 1997
30 //  Last Modified By: Jason Goldschmidt
31 //  Last Modified On: Thu Apr  5 14:46:29 2001
32 //  Update Count:     107
33 //
34 
35 package com.sun.slp;
36 
37 import java.util.*;
38 import java.io.*;
39 
40 
41 /**
42  * The SSrvReg class models the server side SLP service registration. The
43  * default class does SLPv2 regs, but subclasses can do other versions
44  * by redefining the initialize() and makeReply() messages.
45  *
46  * @author James Kempf
47  */
48 
49 class SSrvReg extends SrvLocMsgImpl {
50 
51     ServiceURL URL = null;	         // the service URL.
52     String serviceType = "";	         // service type.
53     Vector attrList = new Vector();        // ServiceLocationAttribute objects.
54     Hashtable URLSignature = null;  // signature for URL.
55     Hashtable attrSignature = null; // the signatures for the attributes.
56 
57     // Construct a SSrvReg from the input stream.
58 
59     SSrvReg(SrvLocHeader hdr, DataInputStream dis)
60 	throws ServiceLocationException, IOException {
61 
62 	super(hdr, SrvLocHeader.SrvReg);
63 
64 	this.initialize(dis);
65 
66     }
67 
68     // Initialize the object from the input stream.
69 
70     void initialize(DataInputStream dis)
71 	throws ServiceLocationException, IOException {
72 
73 	SLPServerHeaderV2 hdr = (SLPServerHeaderV2)getHeader();
74 	StringBuffer buf = new StringBuffer();
75 
76 	// Parse in the service URL
77 
78 	Hashtable table = new Hashtable();
79 
80 	URL =
81 	    hdr.parseServiceURLIn(dis,
82 				  table,
83 				ServiceLocationException.INVALID_REGISTRATION);
84 
85 	URLSignature = (Hashtable)table.get(URL);
86 
87 	// Parse in service type name.
88 
89 	hdr.getString(buf, dis);
90 
91 	// Validate and set URL type.
92 
93 	ServiceType t = new ServiceType(buf.toString());
94 
95 	if (!(URL.getServiceType()).isServiceURL() &&
96 	    !t.equals(URL.getServiceType())) {
97 	    URL.setServiceType(t);
98 
99 	}
100 
101 	// Parse in the scope list.
102 
103 	hdr.parseScopesIn(dis);
104 
105 	// Parse in the attribute list.
106 
107 	attrSignature =
108 	    hdr.parseAuthenticatedAttributeVectorIn(attrList, dis, false);
109 
110 	hdr.constructDescription("SrvReg",
111 				 "       URL=``" +
112 				 URL + "''\n" +
113 				 "       service type=``" +
114 				 serviceType + "''\n" +
115 				 "       attribute list=``" +
116 				 attrList + "''\n" +
117 				 "       URL signature=" +
118 				 AuthBlock.desc(URLSignature) + "\n" +
119 				 "       attribute signature=" +
120 				 AuthBlock.desc(attrSignature) + "\n");
121     }
122 
123     // Return a SrvAck. We ignore the existing flag, since in V2, fresh comes
124     //  in. In this case, all we need to do is clone the header.
125 
126     SrvLocMsg makeReply(boolean existing) {
127 
128 	SLPServerHeaderV2 hdr =
129 	    ((SLPServerHeaderV2)getHeader()).makeReplyHeader();
130 
131 	// Construct description.
132 
133 	hdr.constructDescription("SrvAck", "");
134 
135 	return hdr;
136 
137     }
138 }
139