[jcifs] RPC Stub Format Changes

Michael B Allen mba2000 at ioplex.com
Tue Aug 17 21:25:30 GMT 2004


Michael B Allen said:
> I think recursively nesting class definitions in stubs was clearly wrong.
> Instead of having a separate classfile for each operations there I'm going
> to change the compiler to generate a file for each interface with a single
> nested class def for each struct/union.

If you're curious, below is srvsvc.java (only the NetShareEnumAll
operation w/ 2 info levels). I think this is a good format. Note how
unions are represented as abstract super classes that each arm extends for
type safety.

Idlc now also runs the preprocessor on each file and fully supports
'import' statements.

Now I just have to make it write a file instead of dumping the output to
stdout :)

I suppose I should make sure it runs on Windows ok too. A little ironic
that most jCIFS users are Windows users :->

Mike

import ndr.*;

public class srvsvc {

    public static class NetShareInfo0 {
        public String netname;

        public void encode(NetworkDataRepresentation ndr, NdrBuffer dst)
throws NdrException {
            if (netname == null) {
                dst.enc_ndr_long(0);
            } else {
                dst.enc_ndr_long(System.identityHashCode(netname));
                dst.deferred.enc_ndr_string(netname);
            }
        }
        public void decode(NetworkDataRepresentation ndr, NdrBuffer src)
throws NdrException {
            ndr.ptr = src.dec_ndr_long();
            if (ndr.ptr != 0) {
                netname = src.deferred.dec_ndr_string();
            }
        }
    }

    public static class NetShareInfoCtr0 {
        public int count;
        public NetShareInfo0[] array;

        public void encode(NetworkDataRepresentation ndr, NdrBuffer dst)
throws NdrException {
            dst.enc_ndr_long(count);
            if (array == null) {
                dst.enc_ndr_long(0);
            } else {
                dst.enc_ndr_long(System.identityHashCode(array));
                NdrBuffer deferred = dst.getDeferred(4 + 4 * count);
                deferred.enc_ndr_long(count);
                for (int i = 0; i < count; i++) {
                    array[i].encode(ndr, deferred);
                }
            }
        }
        public void decode(NetworkDataRepresentation ndr, NdrBuffer src)
throws NdrException {
            count = src.dec_ndr_long();
            ndr.ptr = src.dec_ndr_long();
            if (ndr.ptr != 0) {
                NdrBuffer deferred = src.getDeferred(4 + 4 * count);
                count = deferred.dec_ndr_long();
                if (array == null) {
                    array = new NetShareInfo0[count];
                }
                for (int i = 0; i < count; i++) {
                    array[i] = new NetShareInfo0();
                    array[i].decode(ndr, deferred);
                }
            }
        }
    }

    public static class NetShareInfo1 {
        public String netname;
        public int type;
        public String remark;

        public void encode(NetworkDataRepresentation ndr, NdrBuffer dst)
throws NdrException {
            if (netname == null) {
                dst.enc_ndr_long(0);
            } else {
                dst.enc_ndr_long(System.identityHashCode(netname));
                dst.deferred.enc_ndr_string(netname);
            }
            dst.enc_ndr_long(type);
            if (remark == null) {
                dst.enc_ndr_long(0);
            } else {
                dst.enc_ndr_long(System.identityHashCode(remark));
                dst.deferred.enc_ndr_string(remark);
            }
        }
        public void decode(NetworkDataRepresentation ndr, NdrBuffer src)
throws NdrException {
            ndr.ptr = src.dec_ndr_long();
            if (ndr.ptr != 0) {
                netname = src.deferred.dec_ndr_string();
            }
            type = src.dec_ndr_long();
            ndr.ptr = src.dec_ndr_long();
            if (ndr.ptr != 0) {
                remark = src.deferred.dec_ndr_string();
            }
        }
    }

    public static class NetShareInfoCtr1 {
        public int count;
        public NetShareInfo1[] array;

        public void encode(NetworkDataRepresentation ndr, NdrBuffer dst)
throws NdrException {
            dst.enc_ndr_long(count);
            if (array == null) {
                dst.enc_ndr_long(0);
            } else {
                dst.enc_ndr_long(System.identityHashCode(array));
                NdrBuffer deferred = dst.getDeferred(4 + 12 * count);
                deferred.enc_ndr_long(count);
                for (int i = 0; i < count; i++) {
                    array[i].encode(ndr, deferred);
                }
            }
        }
        public void decode(NetworkDataRepresentation ndr, NdrBuffer src)
throws NdrException {
            count = src.dec_ndr_long();
            ndr.ptr = src.dec_ndr_long();
            if (ndr.ptr != 0) {
                NdrBuffer deferred = src.getDeferred(4 + 12 * count);
                count = deferred.dec_ndr_long();
                if (array == null) {
                    array = new NetShareInfo1[count];
                }
                for (int i = 0; i < count; i++) {
                    array[i] = new NetShareInfo1();
                    array[i].decode(ndr, deferred);
                }
            }
        }
    }

    public static abstract class NetShareCtr extends NdrObject { }

    public static class NetShareInfoCtr0 extends NetShareCtr {
        public int count;
        public NetShareInfo0[] array;

        public void encode(NetworkDataRepresentation ndr, NdrBuffer dst)
throws NdrException {
            dst.enc_ndr_long(count);
            if (array == null) {
                dst.enc_ndr_long(0);
            } else {
                dst.enc_ndr_long(System.identityHashCode(array));
                NdrBuffer deferred = dst.getDeferred(4 + 4 * count);
                deferred.enc_ndr_long(count);
                for (int i = 0; i < count; i++) {
                    array[i].encode(ndr, deferred);
                }
            }
        }
        public void decode(NetworkDataRepresentation ndr, NdrBuffer src)
throws NdrException {
            count = src.dec_ndr_long();
            ndr.ptr = src.dec_ndr_long();
            if (ndr.ptr != 0) {
                NdrBuffer deferred = src.getDeferred(4 + 4 * count);
                count = deferred.dec_ndr_long();
                if (array == null) {
                    array = new NetShareInfo0[count];
                }
                for (int i = 0; i < count; i++) {
                    array[i] = new NetShareInfo0();
                    array[i].decode(ndr, deferred);
                }
            }
        }
    }

    public static class NetShareInfoCtr1 extends NetShareCtr {
        public int count;
        public NetShareInfo1[] array;

        public void encode(NetworkDataRepresentation ndr, NdrBuffer dst)
throws NdrException {
            dst.enc_ndr_long(count);
            if (array == null) {
                dst.enc_ndr_long(0);
            } else {
                dst.enc_ndr_long(System.identityHashCode(array));
                NdrBuffer deferred = dst.getDeferred(4 + 12 * count);
                deferred.enc_ndr_long(count);
                for (int i = 0; i < count; i++) {
                    array[i].encode(ndr, deferred);
                }
            }
        }
        public void decode(NetworkDataRepresentation ndr, NdrBuffer src)
throws NdrException {
            count = src.dec_ndr_long();
            ndr.ptr = src.dec_ndr_long();
            if (ndr.ptr != 0) {
                NdrBuffer deferred = src.getDeferred(4 + 12 * count);
                count = deferred.dec_ndr_long();
                if (array == null) {
                    array = new NetShareInfo1[count];
                }
                for (int i = 0; i < count; i++) {
                    array[i] = new NetShareInfo1();
                    array[i].decode(ndr, deferred);
                }
            }
        }
    }

    public class NetShareEnumAll {
        public int retval;
        public String servername;
        public int level;
        public NetShareCtr info;
        public int prefmaxlen;
        public int totalentries;
        public int resume_handle;

        public NetShareEnumAll(String servername,
                    int level,
                    NetShareCtr info,
                    int prefmaxlen,
                    int totalentries,
                    int resume_handle) {
            this.servername = servername;
            this.level = level;
            this.info = info;
            this.prefmaxlen = prefmaxlen;
            this.totalentries = totalentries;
            this.resume_handle = resume_handle;
        }

        public void encode(NetworkDataRepresentation ndr, NdrBuffer dst)
throws NdrException {
            if (servername == null) {
                dst.enc_ndr_long(0);
            } else {
                dst.enc_ndr_long(System.identityHashCode(servername));
                dst.deferred.enc_ndr_string(servername);
            }
            dst.enc_ndr_long(level);
            dst.enc_ndr_long(level);
            if (info == null) {
                dst.enc_ndr_long(0);
            } else {
                dst.enc_ndr_long(System.identityHashCode(info));
                info.encode(ndr, dst.getDeferred(8));
            }
            dst.enc_ndr_long(prefmaxlen);
            dst.enc_ndr_long(resume_handle);
        }
        public void decode(NetworkDataRepresentation ndr, NdrBuffer src)
throws NdrException {
            level = src.dec_ndr_long();
            level = src.dec_ndr_long();
            ndr.ptr = src.dec_ndr_long();
            if (ndr.ptr != 0) {
                info.decode(ndr, src.getDeferred(8));
            }
            totalentries = src.dec_ndr_long();
            resume_handle = src.dec_ndr_long();
            retval = src.dec_ndr_long();
        }
    }

}



More information about the jcifs mailing list