@@ -1,10 +1,10 @@ /* - * Copyright (c) 2011, Jonathan Schleifer - * Copyright (c) 2011, Florian Zeitz + * Copyright (c) 2011, 2012, 2013, 2016, Jonathan Schleifer + * Copyright (c) 2011, 2012, 2013, Florian Zeitz * - * https://webkeks.org/git/?p=objxmpp.git + * https://heap.zone/git/?p=objxmpp.git * * 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. * @@ -23,25 +23,29 @@ #ifdef HAVE_CONFIG_H # include "config.h" #endif -#include - #import "XMPPPresence.h" #import "namespaces.h" -// This provides us with sortable values for show values -static int show_to_int(OFString *show) -{ - if ([show isEqual: @"chat"]) return 0; - if (show == nil) return 1; // available - if ([show isEqual: @"away"]) return 2; - if ([show isEqual: @"dnd"]) return 3; - if ([show isEqual: @"xa"]) return 4; - - assert(0); +/* This provides us with sortable values for show values */ +static int +show_to_int(OFString *show) +{ + if ([show isEqual: @"chat"]) + return 0; + if (show == nil) + return 1; /* available */ + if ([show isEqual: @"away"]) + return 2; + if ([show isEqual: @"dnd"]) + return 3; + if ([show isEqual: @"xa"]) + return 4; + + OF_ENSURE(0); } @implementation XMPPPresence + (instancetype)presence { @@ -139,20 +143,23 @@ - (void)setShow: (OFString*)show { OFXMLElement *oldShow = [self elementForName: @"show" namespace: XMPP_NS_CLIENT]; + OFString *old; if (oldShow != nil) [self removeChild: oldShow]; if (show != nil) [self addChild: [OFXMLElement elementWithName: @"show" namespace: XMPP_NS_CLIENT stringValue: show]]; - OF_SETTER(_show, show, true, 1) + old = _show; + _show = [show copy]; + [old release]; } - (OFString*)show { return [[_show copy] autorelease]; @@ -160,20 +167,23 @@ - (void)setStatus: (OFString*)status { OFXMLElement *oldStatus = [self elementForName: @"status" namespace: XMPP_NS_CLIENT]; + OFString *old; if (oldStatus != nil) [self removeChild: oldStatus]; if (status != nil) [self addChild: [OFXMLElement elementWithName: @"status" namespace: XMPP_NS_CLIENT stringValue: status]]; - OF_SETTER(_status, status, true, 1) + old = _status; + _status = [status copy]; + [old release]; } - (OFString*)status { return [[_status copy] autorelease]; @@ -180,10 +190,11 @@ } - (void)setPriority: (OFNumber*)priority { intmax_t prio = [priority intMaxValue]; + OFNumber *old; if ((prio < -128) || (prio > 127)) @throw [OFInvalidArgumentException exception]; OFXMLElement *oldPriority = [self elementForName: @"priority" @@ -196,11 +207,13 @@ [OFString stringWithFormat: @"%" @PRId8, [priority int8Value]]; [self addChild: [OFXMLElement elementWithName: @"priority" namespace: XMPP_NS_CLIENT stringValue: priority_s]]; - OF_SETTER(_priority, priority, true, 1) + old = _priority; + _priority = [priority copy]; + [old release]; } - (OFNumber*)priority { return [[_priority copy] autorelease];