本文整理汇总了C#中ASC.Xmpp.Server.Handler.XmppHandlerContext类的典型用法代码示例。如果您正苦于以下问题:C# XmppHandlerContext类的具体用法?C# XmppHandlerContext怎么用?C# XmppHandlerContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmppHandlerContext类属于ASC.Xmpp.Server.Handler命名空间,在下文中一共展示了XmppHandlerContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleMessage
public override void HandleMessage(XmppStream stream, Message message, XmppHandlerContext context)
{
if (!message.HasTo || message.To.IsServer)
{
context.Sender.SendTo(stream, XmppStanzaError.ToServiceUnavailable(message));
return;
}
var sessions = context.SessionManager.GetBareJidSessions(message.To);
if (0 < sessions.Count)
{
foreach(var s in sessions)
{
try
{
context.Sender.SendTo(s, message);
}
catch
{
context.Sender.SendToAndClose(s.Stream, message);
}
}
}
else
{
StoreOffline(message, context.StorageManager.OfflineStorage);
}
}
示例2: ProcessAuthIQSet
private void ProcessAuthIQSet(XmppStream stream, AuthIq iq, XmppHandlerContext context)
{
if (string.IsNullOrEmpty(iq.Query.Username) || string.IsNullOrEmpty(iq.Query.Resource))
{
context.Sender.SendTo(stream, XmppStanzaError.ToNotAcceptable(iq));
return;
}
bool authorized = false;
if (!string.IsNullOrEmpty(iq.Query.Digest))
{
authorized = AuthDigest(iq.Query.Username, iq.Query.Digest, stream, context.UserManager);
}
if (!string.IsNullOrEmpty(iq.Query.Password))
{
authorized = AuthPlain(iq.Query.Username, iq.Query.Password, stream, context.UserManager);
}
if (authorized)
{
stream.Authenticate(iq.Query.Username);
var answer = new IQ(IqType.result);
answer.Id = iq.Id;
answer.To = iq.From;
answer.From = iq.To;
context.Sender.SendTo(stream, answer);
}
else
{
context.Sender.SendTo(stream, XmppStanzaError.ToNotAuthorized(iq));
}
}
示例3: StreamStartHandle
public void StreamStartHandle(XmppStream xmppStream, Stream stream, XmppHandlerContext context)
{
var streamHeader = new StringBuilder();
streamHeader.AppendLine("<?xml version='1.0' encoding='UTF-8'?>");
streamHeader.AppendFormat("<stream:{0} xmlns:{0}='{1}' xmlns='{2}' from='{3}' id='{4}' version='1.0'>",
Uri.PREFIX, Uri.STREAM, Uri.CLIENT, stream.To, xmppStream.Id);
context.Sender.SendTo(xmppStream, streamHeader.ToString());
var features = new Features();
features.Prefix = Uri.PREFIX;
if (xmppStream.Authenticated)
{
features.AddChild(new Bind());
features.AddChild(new Core.protocol.iq.session.Session());
}
else
{
features.Mechanisms = new Mechanisms();
var listener = (BoshXmppListener)(context.XmppGateway.GetXmppListener("Bosh Listener"));
var storage = new DbLdapSettingsStore();
storage.GetLdapSettings(xmppStream.Domain);
if (!storage.EnableLdapAuthentication || listener.GetXmppConnection(xmppStream.ConnectionId) != null)
{
features.Mechanisms.AddChild(new Mechanism(MechanismType.DIGEST_MD5));
}
else
{
features.Mechanisms.AddChild(new Mechanism(MechanismType.PLAIN));
}
features.Mechanisms.AddChild(new Element("required"));
features.Register = new Register();
}
streamHeader.Append(features.ToString());
context.Sender.SendTo(xmppStream, features);
}
示例4: ElementHandle
public override void ElementHandle(XmppStream stream, Element element, XmppHandlerContext context)
{
context.Sender.SendTo(stream, new Compressed());
var connection = context.Sender.GetXmppConnection(stream.ConnectionId);
connection.SetStreamTransformer(new GZipTransformer());
context.Sender.ResetStream(stream);
}
示例5: StreamStartHandle
public void StreamStartHandle(XmppStream xmppStream, Stream stream, XmppHandlerContext context)
{
lock (this)
{
//Check tennats here
if (ValidateHost(stream.To))
{
//Create new services
foreach (var template in templates)
{
var service = (IXmppService)Activator.CreateInstance(template.Value);
service.Jid = new Jid(Stringprep.NamePrep(string.Format("{0}.{1}", template.Key, stream.To.Server).Trim('.')));
if (serviceManager.GetService(service.Jid) != null)
{
continue;
}
service.Name = service.Jid.ToString();
if (!string.IsNullOrEmpty(template.Key))
{
service.ParentService = serviceManager.GetService(new Jid(Stringprep.NamePrep(stream.To.Server)));
}
service.Configure(new Dictionary<string, string>());
serviceManager.RegisterService(service);
}
//Reroute
handlerManager.ProcessStreamStart(stream, Uri.CLIENT, xmppStream);
}
else
{
context.Sender.SendToAndClose(xmppStream, XmppStreamError.HostUnknown);
}
}
}
示例6: HandleIQ
public override IQ HandleIQ(XmppStream stream, IQ iq, XmppHandlerContext context)
{
if (iq.HasTo && iq.To != Jid) return XmppStanzaError.ToServiceUnavailable(iq);
if (iq.Query is DiscoInfo && iq.Type == IqType.get) return GetDiscoInfo(stream, iq, context);
if (iq.Query is DiscoItems && iq.Type == IqType.get) return GetDiscoItems(stream, iq, context);
return XmppStanzaError.ToServiceUnavailable(iq);
}
示例7: HandleMessage
public override void HandleMessage(XmppStream stream, Message message, XmppHandlerContext context)
{
if (!message.HasTo) return;
if (archiveStore.GetMessageLogging(message.From, message.To))
{
if (!string.IsNullOrEmpty(message.Body) ||
!string.IsNullOrEmpty(message.Subject) ||
!string.IsNullOrEmpty(message.Thread) ||
message.Html != null)
{
var flush = false;
lock (messageBuffer)
{
//Add xdelay
if (message.XDelay == null)
{
message.XDelay = new Delay();
message.XDelay.Stamp = DateTime.UtcNow;
}
messageBuffer.Add(message);
flush = BUFFER_SIZE <= messageBuffer.Count;
}
if (flush) FlushMessageBuffer();
}
}
}
示例8: HandleMessage
public override void HandleMessage(XmppStream stream, Message msg, XmppHandlerContext context)
{
msg.SwitchDirection();
msg.Type = MessageType.error;
msg.Error = new Error(ErrorType.cancel, ErrorCondition.ItemNotFound);
context.Sender.SendTo(stream, msg);
}
示例9: HandleMessage
public override void HandleMessage(XmppStream stream, Message message, XmppHandlerContext context)
{
if (!message.HasTo) return;
if (archiveStore == null)
{
archiveStore = new DbMessageArchive();
var properties = new Dictionary<string, string>(1);
properties.Add("connectionStringName", "core");
archiveStore.Configure(properties);
}
if (archiveStore.GetMessageLogging(message.From, message.To))
{
if (!string.IsNullOrEmpty(message.Body) ||
!string.IsNullOrEmpty(message.Subject) ||
!string.IsNullOrEmpty(message.Thread) ||
message.Html != null)
{
var flush = false;
lock (messageBuffer)
{
//Add xdelay
if (message.XDelay == null)
{
message.XDelay = new Delay();
message.XDelay.Stamp = DateTime.UtcNow;
}
messageBuffer.Add(message);
flush = BUFFER_SIZE <= messageBuffer.Count;
}
if (flush) FlushMessageBuffer();
}
}
}
示例10: GetPrivate
private IQ GetPrivate(XmppStream stream, IQ iq, XmppHandlerContext context)
{
var privateStore = (Private)iq.Query;
if (!privateStore.HasChildElements) return XmppStanzaError.ToNotAcceptable(iq);
var retrived = new List<Element>();
foreach (var childNode in privateStore.ChildNodes)
{
if (childNode is Element)
{
var elementToRetrive = (Element)childNode;
var elementRestored = context.StorageManager.PrivateStorage.GetPrivate(iq.From, elementToRetrive);
retrived.Add(elementRestored ?? elementToRetrive);
}
}
privateStore.RemoveAllChildNodes();
foreach (var element in retrived)
{
privateStore.AddChild(element);
}
iq.SwitchDirection();
iq.Type = IqType.result;
return iq;
}
示例11: HandleIQ
public override IQ HandleIQ(XmppStream stream, IQ iq, XmppHandlerContext context)
{
if (!iq.HasTo) iq.To = iq.From;
if (iq.Type == IqType.get) return GetVCardSearch(stream, iq, context);
else if (iq.Type == IqType.set) return SetVCardSearch(stream, iq, context);
else return XmppStanzaError.ToBadRequest(iq);
}
示例12: StreamStartHandle
public void StreamStartHandle(XmppStream xmppStream, Stream stream, XmppHandlerContext context)
{
var streamHeader = new StringBuilder();
streamHeader.AppendLine("<?xml version='1.0' encoding='UTF-8'?>");
streamHeader.AppendFormat("<stream:{0} xmlns:{0}='{1}' xmlns='{2}' from='{3}' id='{4}' version='1.0'>",
Uri.PREFIX, Uri.STREAM, Uri.CLIENT, stream.To, xmppStream.Id);
context.Sender.SendTo(xmppStream, streamHeader.ToString());
var features = new Features();
features.Prefix = Uri.PREFIX;
if (xmppStream.Authenticated)
{
features.AddChild(new Bind());
features.AddChild(new Core.protocol.iq.session.Session());
}
else
{
features.Mechanisms = new Mechanisms();
features.Mechanisms.AddChild(new Mechanism(MechanismType.DIGEST_MD5));
features.Mechanisms.AddChild(new Element("required"));
features.Register = new Register();
}
streamHeader.Append(features.ToString());
context.Sender.SendTo(xmppStream, features);
}
示例13: ProcessAuth
private void ProcessAuth(XmppStream stream, Auth auth, XmppHandlerContext context)
{
AuthData authStep;
lock (authData)
{
authData.TryGetValue(stream.Id, out authStep);
}
if (auth.MechanismType != MechanismType.DIGEST_MD5)
{
context.Sender.SendToAndClose(stream, XmppFailureError.InvalidMechanism);
}
else if (authStep != null)
{
context.Sender.SendToAndClose(stream, XmppFailureError.TemporaryAuthFailure);
}
else
{
lock (authData)
{
authData[stream.Id] = new AuthData();
}
var challenge = GetChallenge(stream.Domain);
context.Sender.SendTo(stream, challenge);
}
}
示例14: HandleMessage
public override void HandleMessage(XmppStream stream, Message message, XmppHandlerContext context)
{
if (!message.HasTo || !message.To.HasResource) return;
string[] commands = message.To.Resource.Split('/');
if (commands.Length == 1 && commands[0] == ANNOUNCE)
{
Announce(stream, message, context);
}
else if (commands.Length == 2 && commands[1] == ONLINE)
{
AnnounceOnline(stream, message, context);
}
else if (commands.Length == 2 && commands[1] == ONLINEBROADCAST)
{
AnnounceOnlineBroadcast(stream, message, context);
}
else if (commands.Length == 2 && commands[1] == SERVICE)
{
AnnounceService(stream, message, context);
}
else
{
context.Sender.SendTo(stream, XmppStanzaError.ToServiceUnavailable(message));
}
}
示例15: StreamEndHandle
public override void StreamEndHandle(XmppStream stream, ICollection<Node> notSendedBuffer, XmppHandlerContext context)
{
lock (authData)
{
authData.Remove(stream.Id);
}
}