示例#1
0
        private string doDeleteContainer(string line)
        {
            string givenContainerName = line;

            if (line.Equals(this.loggedInUsername))
            {
                return(MESSAGES.ERR);
            }
            Services.IResourceManage r = new Services.Resource();
            //int uid = srv.getAzureLink().findUserId(this.loggedInUserid);
            int rid = r.getContainerID(loggedInUserid, givenContainerName);

            if (rid == -1)
            {
                return(MESSAGES.E_NOFOLDER);
            }
            if (!r.isOwner(loggedInUserid, rid))
            {
                return(MESSAGES.E_NOACCESS);
            }
            try
            {
                r.deleteSharedContainer(rid);
            }
            catch (ArgumentException e)
            {
                if (e.Message.Equals("container not empty"))
                {
                    return(MESSAGES.E_NOTEMPTY);
                }
                else
                {
                    throw;
                }
            }
            return(MESSAGES.OK);
        }
示例#2
0
        private string doCreate(string line)
        {
            const String sep = " SHAREWITH ";

            if (!isLoggedIn())
            {
                return(MESSAGES.ERR);
            }
            //int uid = srv.getAzureLink().findUserId(this.loggedInUserid);
            int idx = line.LastIndexOf(sep);

            if (idx == -1)
            {
                return(MESSAGES.ERR);
            }
            String sharedFolderName = line.Substring(0, idx);

            /* This should be done via a regex check... */
            if (sharedFolderName.IndexOf('@') != -1 ||
                sharedFolderName.IndexOf('/') != -1 ||
                sharedFolderName.IndexOf('\\') != -1)
            {
                return(MESSAGES.E_BADFOLDERNAME);
            }

            try
            {
                new System.IO.FileInfo(sharedFolderName);
            }
            catch (Exception)
            {
                return("ERR_INVALID_FOLDERNAME");
            }
            String sharedUsersStr = line.Substring(idx + sep.Length);

            String[] sharedUsers = sharedUsersStr.Split(',');
            if (sharedUsers.Length == 0)
            {
                return(MESSAGES.ERR);
            }
            int[]             userids = new int[sharedUsers.Length];
            Boolean[]         write   = new Boolean[sharedUsers.Length];
            Services.Resource m       = new Services.Resource();

            for (int i = 0; i < sharedUsers.Length; i++)
            {
                String shareInfo = sharedUsers[i];
                int    sep_idx   = shareInfo.IndexOf(' ');
                if (sep_idx == -1 || sep_idx != shareInfo.LastIndexOf(' '))
                {
                    return(MESSAGES.ERR);
                }
                String sharedUser = shareInfo.Substring(0, sep_idx);
                int    userid     = srv.getAzureLink().findUserId(sharedUser);
                if (userid == -1)
                {
                    return(MESSAGES.E_NOUSER + " " + sharedUser);
                }
                if (userid == this.loggedInUserid)
                {
                    return(MESSAGES.ERR);
                }
                // this is not perfectly MT-safe, alas...
                if (m.getContainerID(userid, sharedFolderName) != -1)
                {
                    return(MESSAGES.E_EXISTS);
                }
                userids[i] = userid;

                String acl_str = shareInfo.Substring(sep_idx + 1);
                if (acl_str.Equals("R"))
                {
                    write[i] = false;
                }
                else if (acl_str.Equals("RW"))
                {
                    write[i] = true;
                }
                else
                {
                    return(MESSAGES.ERR);
                }
            }


            try
            {
                int sharedContainerId = m.createSharedContainer(loggedInUserid, sharedFolderName);
                if (sharedContainerId == -1)
                {
                    return(MESSAGES.E_EXISTS);
                }
                for (int i = 0; i < userids.Length; i++)
                {
                    m.grantRights(userids[i], sharedContainerId, write[i]);
                }
                return(MESSAGES.OK);
            }
            catch (DBLikeExceptions.CloudContainerAlreadyExistException)
            {
                return(MESSAGES.E_EXISTS);
            }
        }
示例#3
0
        private string doList(string line)
        {
            if (!isLoggedIn())
            {
                return(MESSAGES.ERR);
            }

            var cloudInfo = srv.getAzureLink().getUserCloudFileSystem(this.loggedInUsername);

            StringBuilder replyStr = new StringBuilder();

            replyStr.Append("<?xml version='1.0' encoding='UTF-8'?>\r\n");
            replyStr.Append("<cloudinfo>\r\n");
            Services.IResourceManage mg = new Services.Resource();
            /* this is INCREDIBLY FUGLY CODE */


            //int uid = srv.getAzureLink().findUserId(this.loggedInUserid);
            foreach (String containerName in cloudInfo.Keys)
            {
                replyStr.Append("\t<container name='");
                replyStr.Append(containerName);
                replyStr.Append("' access='");
                int containerID = mg.getContainerID(loggedInUserid, containerName);

                if (mg.isOwner(loggedInUserid, containerID))
                {
                    replyStr.Append("owner");
                }
                else if (mg.canWrite(loggedInUserid, containerID))
                {
                    replyStr.Append("readwrite");
                }
                else
                {
                    replyStr.Append("readonly");
                }
                replyStr.Append("'>\r\n");

                var containerFiles = cloudInfo[containerName];
                foreach (String fileName in containerFiles.Keys)
                {
                    var file = containerFiles[fileName];
                    replyStr.Append("\t\t<file name='" + fileName + "' ");
                    replyStr.Append(" size='" + file.getSize() + "' ");
                    replyStr.Append(" timestamp='" + file.getLastmodifiedTime() + "' ");
                    replyStr.Append(" md5='" + file.getMD5HashValue() + "'");
                    replyStr.Append(" deleted='" + file.isDeleted() + "'");
                    replyStr.Append(" />\r\n");
                    //replyStr.Append("\t\t</file>\r\n");
                }
                if (mg.isOwner(loggedInUserid, containerID))
                {
                    string sharedUsersXML = makeSharedUsersXML(containerID);
                    replyStr.Append(sharedUsersXML);
                }
                replyStr.Append("\t</container>\r\n");
            }
            replyStr.Append("</cloudinfo>");
            replyStr.Replace('\'', '\"');
            return(replyStr.ToString());
        }