private KwsAnpEventStatus HandleKwsCreatedEvent(AnpMsg msg) { KwsCredentials creds = m_kws.CoreData.Credentials; // Add the creator to the user list. KwsUser user = new KwsUser(); user.UserID = msg.Elements[2].UInt32; user.InvitationDate = msg.Elements[1].UInt64; user.AdminName = msg.Elements[3].String; user.EmailAddress = msg.Elements[4].String; user.OrgName = msg.Elements[msg.Minor <= 2 ? 7 : 5].String; user.AdminFlag = true; user.ManagerFlag = true; user.RegisterFlag = true; m_kws.CoreData.UserInfo.UserTree[user.UserID] = user; // Update the workspace data. if (msg.Minor <= 2) { creds.SecureFlag = true; } if (msg.Minor >= 3) { creds.KwsName = msg.Elements[6].String; creds.Flags = msg.Elements[7].UInt32; creds.KwmoAddress = msg.Elements[8].String; } m_kws.StateChangeUpdate(false); return KwsAnpEventStatus.Processed; }
public override void AddToMsg(AnpMsg M) { M.AddUInt32(4); M.AddUInt32(IsFile ? KAnpType.KANP_KFS_OP_DELETE_FILE : KAnpType.KANP_KFS_OP_DELETE_DIR); M.AddUInt64(Inode); M.AddUInt64(CommitID); }
private KwsAnpEventStatus HandleKwsCreatedEvent(AnpMsg msg) { // FIXME store the workspace creation date. KwsUser user = new KwsUser(); user.UserID = msg.Elements[2].UInt32; user.InvitationDate = msg.Elements[1].UInt64; user.AdminName = msg.Elements[3].String; user.EmailAddress = msg.Elements[4].String; user.Power = 1; user.OrgName = msg.Elements[msg.Minor <= 2 ? 7 : 5].String; // Add the creator to the user list. m_kws.CoreData.UserInfo.UserTree[user.UserID] = user; m_kws.CoreData.UserInfo.Creator = user; // FIXME do something better when we look into the user powers. // If we are the creator of this workspace, set our Admin flag. if (m_kws.CoreData.Credentials.UserID == user.UserID) m_kws.CoreData.Credentials.AdminFlag = true; m_kws.StateChangeUpdate(false); return KwsAnpEventStatus.Processed; }
public override KwsAnpEventStatus HandleAnpEvent(AnpMsg msg) { if (msg.Type == KAnpType.KANP_EVT_PB_TRIGGER_CHAT) return HandleTriggerChatEvent(msg); else if (msg.Type == KAnpType.KANP_EVT_PB_TRIGGER_KWS) return HandleTriggerKwsEvent(msg); // We don't care about this event. else if (msg.Type == KAnpType.KANP_EVT_PB_CHAT_ACCEPTED) return KwsAnpEventStatus.Processed; else return KwsAnpEventStatus.Unprocessed; }
public override void AddToMsg(AnpMsg M) { M.AddUInt32(5); M.AddUInt32(IsFile ? KAnpType.KANP_KFS_OP_CREATE_FILE : KAnpType.KANP_KFS_OP_CREATE_DIR); M.AddUInt64(ParentInode); M.AddUInt64(ParentCommitID); M.AddString(Path); }
public AnpMsg getRecv() { Debug.Assert(doneReceiving); AnpMsg m = inMsg; flushRecv(); return(m); }
/// <summary> /// Handle a received event, send it to Outlook /// </summary> /// <param name="msg"></param> public void EventReceivedHandler(object sender, AnpMsg msg) { switch (msg.Type) { case KAnpType.KANP_EVT_KWS_INVITED: case KAnpType.KANP_EVT_KWS_USER_REGISTERED: if (!BatchPush || !UserStatusSent) SendUserUpdateEvent(m_Kws, msg); break; } }
/// <summary> /// Handle an ANP event. /// </summary> public KwsAnpEventStatus HandleAnpEvent(AnpMsg msg) { UInt32 type = msg.Type; // Dispatch. if (type == KAnpType.KANP_EVT_KWS_CREATED) return HandleKwsCreatedEvent(msg); else if (type == KAnpType.KANP_EVT_KWS_INVITED) return HandleKwsInvitationEvent(msg); else if (type == KAnpType.KANP_EVT_KWS_USER_REGISTERED) return HandleUserRegisteredEvent(msg); else if (type == KAnpType.KANP_EVT_KWS_DELETED) return HandleKwsDeletedEvent(); else return KwsAnpEventStatus.Unprocessed; }
private KwsAnpEventStatus HandleTriggerKwsEvent(AnpMsg msg) { if (NotifiedCaughtUpFlag) { UInt32 userID = msg.Elements[3].UInt32; String subject = msg.Elements[4].String; String userName = Helper.GetUserByID(userID).UiSimpleName; String userEmail = Helper.GetUserByID(userID).EmailAddress; PublicCreateKwsGer req = new PublicCreateKwsGer(userName, userEmail, subject); Helper.PostGuiExecRequest(req); } return KwsAnpEventStatus.Processed; }
private KwsAnpEventStatus HandleTriggerChatEvent(AnpMsg msg) { if (NotifiedCaughtUpFlag) { UInt64 reqID = msg.Minor <= 2 ? msg.Elements[2].UInt32 : msg.Elements[2].UInt64; UInt32 userID = msg.Elements[3].UInt32; String subject = msg.Elements[4].String; UInt32 timeout = msg.Elements[5].UInt32; String userName = Helper.GetUserByID(userID).UiSimpleName; PublicChatGer req = new PublicChatGer(this, reqID, userID, timeout, userName, subject); Helper.PostGuiExecRequest(req); } return KwsAnpEventStatus.Processed; }
/// <summary> /// Creates a new object from an AnpMsg. The AnpMsg elements /// before the actual workspace details must be consumed. /// </summary> /// <param name="msg"></param> public OutlookKws(AnpMsg msg) { InternalID = msg.PopHead().UInt64; ExternalID = msg.PopHead().UInt64; KcdAddress = msg.PopHead().String; KwmoAddress = msg.PopHead().String; KwsName = msg.PopHead().String; FolderPath = msg.PopHead().String; SecureFlag = (msg.PopHead().UInt32 > 0); InvitePowerFlag = (msg.PopHead().UInt32 > 0); ConnectedFlag = (msg.PopHead().UInt32 > 0); FreezeFlag = (msg.PopHead().UInt32 > 0); DeepFreezeFlag = (msg.PopHead().UInt32 > 0); PublicFlag = (msg.PopHead().UInt32 > 0); CreationDate = (msg.PopHead().UInt64); }
/// <summary> /// Fill the given AnpMsg. /// </summary> public void FillAnp(ref AnpMsg msg) { msg.AddUInt64(InternalID); msg.AddUInt64(ExternalID); msg.AddString(KcdAddress); msg.AddString(KwmoAddress); msg.AddString(KwsName); msg.AddString(FolderPath); msg.AddUInt32(Convert.ToUInt32(SecureFlag)); msg.AddUInt32(Convert.ToUInt32(InvitePowerFlag)); msg.AddUInt32(Convert.ToUInt32(ConnectedFlag)); msg.AddUInt32(Convert.ToUInt32(FreezeFlag)); msg.AddUInt32(Convert.ToUInt32(DeepFreezeFlag)); msg.AddUInt32(Convert.ToUInt32(PublicFlag)); msg.AddUInt64(CreationDate); }
private void SendUserUpdateEvent(Workspace kws, AnpMsg msg) { AnpMsg evt = m_Wm.OutlookBroker.MakeEvent(OAnpType.OANP_EVT_USER_UPDATE); evt.AddUInt64(kws.InternalID); evt.AddUInt64(msg.Elements[1].UInt64); evt.AddUInt32((UInt32)kws.CoreData.UserInfo.UserTree.Count); foreach (KwsUser user in kws.CoreData.UserInfo.UserTree.Values) { evt.AddUInt32(user.UserID); evt.AddString(user.AdminName); evt.AddString(user.UserName); evt.AddString(user.EmailAddress); evt.AddUInt32(user.Power); evt.AddString(user.OrgName); } m_Wm.OutlookBroker.SendEvent(evt); }
/// <summary> /// Fill the content of InviteParams from the content of the Outlook /// Create or Invite command specified. /// </summary> public void FillInviteParamsFromOutlookCmd(AnpMsg cmd, int index) { InviteParams.UserArray.Clear(); UInt32 nbUser = cmd.Elements[index++].UInt32; for (UInt32 i = 0; i < nbUser; i++) { KwsInviteOpUser iu = new KwsInviteOpUser(); InviteParams.UserArray.Add(iu); iu.UserName = cmd.Elements[index++].String; iu.EmailAddress = cmd.Elements[index++].String; iu.KeyID = cmd.Elements[index++].UInt64; iu.OrgName = cmd.Elements[index++].String; iu.Pwd = cmd.Elements[index++].String; } }
private KwsAnpEventStatus HandleKwsInvitationEvent(AnpMsg msg) { UInt32 nbUser = msg.Elements[msg.Minor <= 2 ? 2 : 3].UInt32; // This is not supposed to happen, unless in the case of a broken // KWM. Indeed, the server does not enforce any kind of restriction // regarding the number of invitees in an INVITE command. If a KWM // sends such a command with no invitees, the server will fire an // empty INVITE event. if (nbUser < 1) return KwsAnpEventStatus.Processed; List<KwsUser> users = new List<KwsUser>(); // Add the users in the user list. int j = (msg.Minor <= 2) ? 3 : 4; for (int i = 0; i < nbUser; i++) { KwsUser user = new KwsUser(); user.UserID = msg.Elements[j++].UInt32; user.InvitationDate = msg.Elements[1].UInt64; if (msg.Minor >= 3) user.InvitedBy = msg.Elements[2].UInt32; user.AdminName = msg.Elements[j++].String; user.EmailAddress = msg.Elements[j++].String; if (msg.Minor <= 2) j += 2; user.OrgName = msg.Elements[j++].String; users.Add(user); m_kws.CoreData.UserInfo.UserTree[user.UserID] = user; } m_kws.StateChangeUpdate(false); // Never notify new public workspace invitations. They are automatically // generated when a recipient takes an action on the Web page. if (!m_kws.IsPublicKws()) { // Notify the new invitees to the user if it was not him that invited them. // Note: we only have this information from v3 and later. In case of an older // version, notify in all cases. if (msg.Minor >= 3) { if (msg.Elements[2].UInt32 != m_kws.CoreData.Credentials.UserID) m_kws.NotifyUser(new KwsInvitationNotificationItem(m_kws, users)); } else { m_kws.NotifyUser(new KwsInvitationNotificationItem(m_kws, users)); } } return KwsAnpEventStatus.Processed; }
/// <summary> /// This method returns an exception when an unexpected reply is /// received from the KAS. /// </summary> public static Exception HandleUnexpectedKAnpReply(String command, AnpMsg msg) { try { if (msg.Type == KAnpType.KANP_RES_FAIL) return new Exception("command " + command + " failed: " + msg.Elements[1].String); } // Handle malformed messages. catch (Exception ex) { return ex; } return new Exception("Unexpected KAnp reply " + msg.Type + " for command " + command); }
/// <summary> /// Fill the content of InviteParams from the content of the Outlook /// LookupRecAddr command specified. /// </summary> public void FillInviteParamsFromOutlookLookupRecCmd(AnpMsg cmd) { InviteParams.UserArray.Clear(); UInt32 nbUser = cmd.Elements[0].UInt32; for (int i = 1; i <= nbUser; i++) { KwsInviteOpUser iu = new KwsInviteOpUser(); InviteParams.UserArray.Add(iu); iu.EmailAddress = cmd.Elements[i].String; } }
/// <summary> /// Fill the content of the Outlook result specified from the content /// of InviteParams. /// </summary> public void FillOutlookResultWithInviteParms(AnpMsg res) { res.AddString(InviteParams.WLEU); res.AddUInt32((UInt32)InviteParams.UserArray.Count); foreach (KwsInviteOpUser iu in InviteParams.UserArray) { res.AddString(iu.EmailAddress); res.AddString(iu.Url); } }
public void doXfer() { bool loop = true; while (loop) { loop = false; if (inState == InState.RecvHdr) { int r = Base.SockRead(sock, inBuf, inPos, inBuf.Length - inPos); if (r > 0) { loop = true; inPos += r; if (inPos == inBuf.Length) { inMsg = new AnpMsg(); UInt32 size = 0; AnpMsg.ParseHdr(inBuf, ref inMsg.Major, ref inMsg.Minor, ref inMsg.Type, ref inMsg.ID, ref size); if (size > AnpMsg.MaxSize) { throw new AnpException("ANP message is too large"); } if (size > 0) { inState = InState.RecvPayload; inBuf = new byte[size]; inPos = 0; } else { inState = InState.Received; } } } } if (inState == InState.RecvPayload) { int r = Base.SockRead(sock, inBuf, inPos, inBuf.Length - inPos); if (r > 0) { loop = true; inPos += r; if (inPos == inBuf.Length) { inMsg.Elements = AnpMsg.ParsePayload(inBuf); inState = InState.Received; } } } if (outState == OutState.Sending) { int r = Base.SockWrite(sock, outBuf, outPos, outBuf.Length - outPos); if (r > 0) { loop = true; outPos += r; if (outPos == outBuf.Length) { outState = OutState.NoPacket; break; } } } } }
public virtual void ProcessCommand(AnpMsg msg) { Logging.Log("Process Command Unhandled"); }
/// <summary> /// Handle an ANP event associated to this application. /// </summary> public virtual KwsAnpEventStatus HandleAnpEvent(AnpMsg msg) { return KwsAnpEventStatus.Unprocessed; }
/// <summary> /// This method is called when a upload ticket reply is received. /// </summary> public void OnTicket(AnpMsg m) { Debug.Assert(Status == MetaDataManagerStatus.Ticket); Debug.Assert(Phase1Payload != null); Debug.Assert(Ticket == null); // Store the ticket and run the pipeline. if (m.Type == KAnpType.KANP_RES_KFS_UPLOAD_REQ) { Status = MetaDataManagerStatus.Queued; Ticket = m.Elements[0].Bin; Share.Pipeline.Run("got meta-data ticket", false); } // On failure, cancel all uploads. else { ReportError(m.Elements[0].String); Share.Pipeline.Run("could not obtain meta-data ticket", true); } }
/// <summary> /// Validate a ticket reply. /// </summary> private void ValidateTicketReply(AnpMsg m, bool uploadFlag) { if (m.Type == KAnpType.KANP_RES_KFS_DOWNLOAD_REQ) { if (uploadFlag) throw new Exception("invalid ticket reply type"); if (m.Elements[0].Type != AnpMsg.AnpType.Bin) throw new Exception("invalid ticket format"); } else if (m.Type == KAnpType.KANP_RES_KFS_UPLOAD_REQ) { if (!uploadFlag) throw new Exception("invalid ticket reply type"); if (m.Elements[0].Type != AnpMsg.AnpType.Bin) throw new Exception("invalid ticket format"); } else if (m.Type == KAnpType.KANP_RES_FAIL) { if (m.Elements[0].Type != AnpMsg.AnpType.String) throw new Exception("server refused to provide ticket"); } else throw new Exception("invalid ticket reply type"); }
// Called when a phase 1 or 2 server event is received. private void OnPhase1Or2Event(AnpMsg m, bool phaseOneFlag) { // Add the operations in the operation list. bool firstFlag = (OpList.Count == 0); if (phaseOneFlag) { List<KfsServerOp> opList; ServerView.DecomposePhase1Event(m, out opList); foreach (KfsServerOp o in opList) OpList.Enqueue(o); } else { KfsPhase2ServerOp o; ServerView.DecomposePhase2Event(m, out o); OpList.Enqueue(o); } // Run the pipeline if there were no other buffered events. if (firstFlag) Pipeline.Run("received server event", false); }
public KasQuery(AnpMsg cmd, Object[] metaData, KasQueryDelegate callback) { Debug.Assert(cmd.ID != 0); Cmd = cmd; MetaData = metaData; Callback = callback; }
/// <summary> /// Called when a phase 2 server event is received. /// </summary> public void OnPhase2Event(AnpMsg m) { // Call the global handler for phase 1 and phase 2 events. OnPhase1Or2Event(m, false); // The upload manager might be interested by the commit ID. UploadManager.OnPhase2Event(m.Elements[4].UInt64); }
/// <summary> /// Post a command to the KAS of the workspace. A query object having /// the meta-data specified is returned. The query object will be /// re-supplied when the reply to the command is received. The reply of /// the command will be ignored if the workspace logs out for any /// reason. /// </summary> public KasQuery PostKasQuery(AnpMsg cmd, Object[] metaData, KasQueryDelegate callback) { return Helper.PostAppKasQuery(cmd, metaData, callback, this); }
public void sendMsg(AnpMsg msg) { outState = OutState.Sending; outBuf = msg.ToByteArray(true); outPos = 0; }
private KwsAnpEventStatus HandleUserRegisteredEvent(AnpMsg msg) { UInt32 userID = msg.Elements[2].UInt32; String userName = msg.Elements[3].String; KwsUser user = m_kws.CoreData.UserInfo.GetUserByID(userID); if (user == null) throw new Exception("no such user"); user.UserName = userName; // Refresh the user list. m_kws.StateChangeUpdate(false); return KwsAnpEventStatus.Processed; }
/// <summary> /// Create an ANP message that can be sent to the server in transfer mode. /// </summary> public AnpMsg CreateTransferMsg(UInt32 type) { AnpMsg m = new AnpMsg(); m.Minor = KAnp.Minor; m.Type = type; return m; }
public KcmAnpMsg(AnpMsg msg, KasIdentifier kasID) { Msg = msg; KasID = kasID; }
/// <summary> /// Called when a phase 1 server event is received. /// </summary> public void OnPhase1Event(AnpMsg m) { // Call the global handler for phase 1 and phase 2 events. OnPhase1Or2Event(m, true); // The meta-data manager might be interested by the commit ID. MetaDataManager.OnPhase1Event(m.Elements[4].UInt64); }