Add xml:lang support.

This commit is contained in:
Jonathan Schleifer 2012-02-03 17:26:34 +01:00
parent 1b9c63195a
commit 6ddf416e50
4 changed files with 53 additions and 4 deletions

View file

@ -146,6 +146,7 @@
OFString *domain, *domainToASCII; OFString *domain, *domainToASCII;
XMPPJID *JID; XMPPJID *JID;
uint16_t port; uint16_t port;
OFString *language;
XMPPMulticastDelegate *delegates; XMPPMulticastDelegate *delegates;
OFMutableDictionary *callbacks; OFMutableDictionary *callbacks;
XMPPAuthenticator *authModule; XMPPAuthenticator *authModule;
@ -170,6 +171,8 @@
@property (copy) OFString *domain; @property (copy) OFString *domain;
/// \brief The resource to request for the connection /// \brief The resource to request for the connection
@property (copy) OFString *resource; @property (copy) OFString *resource;
/// \brief The language to request for the connection
@property (copy) OFString *language;
/// \brief A private key file to use for authentication /// \brief A private key file to use for authentication
@property (copy) OFString *privateKeyFile; @property (copy) OFString *privateKeyFile;
/// \brief A certificate file to use for authentication /// \brief A certificate file to use for authentication
@ -321,6 +324,8 @@
- (XMPPJID*)JID; - (XMPPJID*)JID;
- (void)setPort: (uint16_t)port; - (void)setPort: (uint16_t)port;
- (uint16_t)port; - (uint16_t)port;
- (void)setLanguage: (OFString*)language;
- (OFString*)language;
/// \cond internal /// \cond internal
- (void)XMPP_startStream; - (void)XMPP_startStream;

View file

@ -52,6 +52,8 @@
#import "XMPPXMLElementBuilder.h" #import "XMPPXMLElementBuilder.h"
#import "namespaces.h" #import "namespaces.h"
#import <ObjFW/macros.h>
@implementation XMPPConnection @implementation XMPPConnection
+ connection + connection
{ {
@ -528,6 +530,8 @@
- (void)XMPP_startStream - (void)XMPP_startStream
{ {
OFString *langString = @"";
/* Make sure we don't get any old events */ /* Make sure we don't get any old events */
[parser setDelegate: nil]; [parser setDelegate: nil];
[elementBuilder setDelegate: nil]; [elementBuilder setDelegate: nil];
@ -545,11 +549,16 @@
elementBuilder = [[XMPPXMLElementBuilder alloc] init]; elementBuilder = [[XMPPXMLElementBuilder alloc] init];
[elementBuilder setDelegate: self]; [elementBuilder setDelegate: self];
if (language != nil)
langString = [OFString stringWithFormat: @"xml:lang='%@' ",
language];
[sock writeFormat: @"<?xml version='1.0'?>\n" [sock writeFormat: @"<?xml version='1.0'?>\n"
@"<stream:stream to='%@' " @"<stream:stream to='%@' "
@"xmlns='" XMPP_NS_CLIENT @"' " @"xmlns='" XMPP_NS_CLIENT @"' "
@"xmlns:stream='" XMPP_NS_STREAM @"' " @"xmlns:stream='" XMPP_NS_STREAM @"' %@"
@"version='1.0'>", domain]; @"version='1.0'>", domain, langString];
streamOpen = YES; streamOpen = YES;
} }
@ -1042,6 +1051,16 @@
return port; return port;
} }
- (void)setLanguage: (OFString*)language_
{
OF_SETTER(language, language_, YES, YES)
}
- (OFString*)language
{
OF_GETTER(language, YES)
}
- (void)addDelegate: (id <XMPPConnectionDelegate>)delegate - (void)addDelegate: (id <XMPPConnectionDelegate>)delegate
{ {
[delegates addDelegate: delegate]; [delegates addDelegate: delegate];

View file

@ -35,6 +35,7 @@
XMPPJID *to; XMPPJID *to;
OFString *type; OFString *type;
OFString *ID; OFString *ID;
OFString *language;
/// \endcond /// \endcond
} }
@ -47,6 +48,7 @@
@property (copy) OFString *type; @property (copy) OFString *type;
/// \brief The value of the stanza's id attribute /// \brief The value of the stanza's id attribute
@property (copy) OFString *ID; @property (copy) OFString *ID;
/// \brief The stanza's xml:lang
#endif #endif
/** /**
@ -158,4 +160,6 @@
- (OFString*)type; - (OFString*)type;
- (void)setID: (OFString*)ID; - (void)setID: (OFString*)ID;
- (OFString*)ID; - (OFString*)ID;
- (void)setLanguage: (OFString*)language;
- (OFString*)language;
@end @end

View file

@ -211,7 +211,7 @@
- (void)setID: (OFString*)ID_ - (void)setID: (OFString*)ID_
{ {
OFString* old = ID; OFString *old = ID;
ID = [ID_ copy]; ID = [ID_ copy];
[old release]; [old release];
@ -219,11 +219,32 @@
if (ID_ != nil) if (ID_ != nil)
[self addAttributeWithName: @"id" [self addAttributeWithName: @"id"
stringValue: ID]; stringValue: ID_];
} }
- (OFString*)ID - (OFString*)ID
{ {
return [[ID copy] autorelease]; return [[ID copy] autorelease];
} }
- (void)setLanguage: (OFString*)language_
{
OFString *old = language;
language = [language_ copy];
[old release];
[self removeAttributeForName: @"lang"
namespace: @"http://www.w3.org/XML/1998/namespace"];
if (language_ != nil)
[self addAttributeWithName: @"lang"
namespace: @"http://www.w3.org/XML/1998/"
@"namespace"
stringValue: language_];
}
- (OFString*)language
{
return [[language copy] autorelease];
}
@end @end