Avoid string duplication

FossilOrigin-Name: b31637cfd1da7d0b147b508f5777603fb3ed2b96bc2671604055b96e91f7a2cf
This commit is contained in:
Jonathan Schleifer 2021-04-29 00:14:09 +00:00
parent 098092053c
commit b5da765571
4 changed files with 65 additions and 20 deletions

View file

@ -29,10 +29,10 @@ SRCS = XMPPANONYMOUSAuth.m \
XMPPSCRAMAuth.m \ XMPPSCRAMAuth.m \
XMPPStanza.m \ XMPPStanza.m \
XMPPStreamManagement.m \ XMPPStreamManagement.m \
XMPPXMLElementBuilder.m XMPPXMLElementBuilder.m \
namespaces.m
INCLUDES = ${SRCS:.m=.h} \ INCLUDES = ${SRCS:.m=.h} \
namespaces.h \
ObjXMPP.h \ ObjXMPP.h \
XMPPStorage.h XMPPStorage.h

View file

@ -638,9 +638,13 @@
[_socket writeFormat: @"<?xml version='1.0'?>\n" [_socket writeFormat: @"<?xml version='1.0'?>\n"
@"<stream:stream to='%@' " @"<stream:stream to='%@' "
@"xmlns='" XMPPClientNS @"' " @"xmlns='%@' "
@"xmlns:stream='" XMPPStreamNS @"' %@" @"xmlns:stream='%@' %@"
@"version='1.0'>", _domain, langString]; @"version='1.0'>",
_domain,
XMPPClientNS,
XMPPStreamNS,
langString];
_streamOpen = true; _streamOpen = true;
} }

View file

@ -20,18 +20,20 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#define XMPPBindNS @"urn:ietf:params:xml:ns:xmpp-bind" #import <ObjFW/ObjFW.h>
#define XMPPCapsNS @"http://jabber.org/protocol/caps"
#define XMPPClientNS @"jabber:client" extern OFString *const XMPPBindNS;
#define XMPPDiscoInfoNS @"http://jabber.org/protocol/disco#info" extern OFString *const XMPPCapsNS;
#define XMPPDiscoItemsNS @"http://jabber.org/protocol/disco#items" extern OFString *const XMPPClientNS;
#define XMPPMUCNS @"http://jabber.org/protocol/muc" extern OFString *const XMPPDiscoInfoNS;
#define XMPPRosterNS @"jabber:iq:roster" extern OFString *const XMPPDiscoItemsNS;
#define XMPPRosterVerNS @"urn:xmpp:features:rosterver" extern OFString *const XMPPMUCNS;
#define XMPPSASLNS @"urn:ietf:params:xml:ns:xmpp-sasl" extern OFString *const XMPPRosterNS;
#define XMPPSessionNS @"urn:ietf:params:xml:ns:xmpp-session" extern OFString *const XMPPRosterVerNS;
#define XMPPSMNS @"urn:xmpp:sm:3" extern OFString *const XMPPSASLNS;
#define XMPPStanzasNS @"urn:ietf:params:xml:ns:xmpp-stanzas" extern OFString *const XMPPSessionNS;
#define XMPPStartTLSNS @"urn:ietf:params:xml:ns:xmpp-tls" extern OFString *const XMPPSMNS;
#define XMPPStreamNS @"http://etherx.jabber.org/streams" extern OFString *const XMPPStanzasNS;
#define XMPPXMPPStreamNS @"urn:ietf:params:xml:ns:xmpp-streams" extern OFString *const XMPPStartTLSNS;
extern OFString *const XMPPStreamNS;
extern OFString *const XMPPXMPPStreamNS;

39
src/namespaces.m Normal file
View file

@ -0,0 +1,39 @@
/*
* Copyright (c) 2011, 2021, Jonathan Schleifer <js@nil.im>
*
* https://heap.zone/objxmpp/
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice is present in all copies.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#import "namespaces.h"
OFString *const XMPPBindNS = @"urn:ietf:params:xml:ns:xmpp-bind";
OFString *const XMPPCapsNS = @"http://jabber.org/protocol/caps";
OFString *const XMPPClientNS = @"jabber:client";
OFString *const XMPPDiscoInfoNS = @"http://jabber.org/protocol/disco#info";
OFString *const XMPPDiscoItemsNS = @"http://jabber.org/protocol/disco#items";
OFString *const XMPPMUCNS = @"http://jabber.org/protocol/muc";
OFString *const XMPPRosterNS = @"jabber:iq:roster";
OFString *const XMPPRosterVerNS = @"urn:xmpp:features:rosterver";
OFString *const XMPPSASLNS = @"urn:ietf:params:xml:ns:xmpp-sasl";
OFString *const XMPPSessionNS = @"urn:ietf:params:xml:ns:xmpp-session";
OFString *const XMPPSMNS = @"urn:xmpp:sm:3";
OFString *const XMPPStanzasNS = @"urn:ietf:params:xml:ns:xmpp-stanzas";
OFString *const XMPPStartTLSNS = @"urn:ietf:params:xml:ns:xmpp-tls";
OFString *const XMPPStreamNS = @"http://etherx.jabber.org/streams";
OFString *const XMPPXMPPStreamNS = @"urn:ietf:params:xml:ns:xmpp-streams";