Skip to content

Commit 2aea1a6

Browse files
committed
stanza: avoid copy-paste in 'get' functions
1 parent e475ca1 commit 2aea1a6

File tree

1 file changed

+5
-35
lines changed

1 file changed

+5
-35
lines changed

src/stanza.c

+5-35
Original file line numberDiff line numberDiff line change
@@ -712,13 +712,7 @@ int xmpp_stanza_set_text_with_size(xmpp_stanza_t *stanza,
712712
*/
713713
char *xmpp_stanza_get_id(xmpp_stanza_t * const stanza)
714714
{
715-
if (stanza->type != XMPP_STANZA_TAG)
716-
return NULL;
717-
718-
if (!stanza->attributes)
719-
return NULL;
720-
721-
return (char *)hash_get(stanza->attributes, "id");
715+
return xmpp_stanza_get_attribute(stanza, "id");
722716
}
723717

724718
/** Get the namespace attribute of the stanza object.
@@ -733,13 +727,7 @@ char *xmpp_stanza_get_id(xmpp_stanza_t * const stanza)
733727
*/
734728
char *xmpp_stanza_get_ns(xmpp_stanza_t * const stanza)
735729
{
736-
if (stanza->type != XMPP_STANZA_TAG)
737-
return NULL;
738-
739-
if (!stanza->attributes)
740-
return NULL;
741-
742-
return (char *)hash_get(stanza->attributes, "xmlns");
730+
return xmpp_stanza_get_attribute(stanza, "xmlns");
743731
}
744732

745733
/** Get the 'type' attribute of the stanza object.
@@ -754,13 +742,7 @@ char *xmpp_stanza_get_ns(xmpp_stanza_t * const stanza)
754742
*/
755743
char *xmpp_stanza_get_type(xmpp_stanza_t * const stanza)
756744
{
757-
if (stanza->type != XMPP_STANZA_TAG)
758-
return NULL;
759-
760-
if (!stanza->attributes)
761-
return NULL;
762-
763-
return (char *)hash_get(stanza->attributes, "type");
745+
return xmpp_stanza_get_attribute(stanza, "type");
764746
}
765747

766748
/** Get the 'to' attribute of the stanza object.
@@ -775,13 +757,7 @@ char *xmpp_stanza_get_type(xmpp_stanza_t * const stanza)
775757
*/
776758
char *xmpp_stanza_get_to(xmpp_stanza_t * const stanza)
777759
{
778-
if (stanza->type != XMPP_STANZA_TAG)
779-
return NULL;
780-
781-
if (!stanza->attributes)
782-
return NULL;
783-
784-
return (char *)hash_get(stanza->attributes, "to");
760+
return xmpp_stanza_get_attribute(stanza, "to");
785761
}
786762

787763
/** Get the 'from' attribute of the stanza object.
@@ -796,13 +772,7 @@ char *xmpp_stanza_get_to(xmpp_stanza_t * const stanza)
796772
*/
797773
char *xmpp_stanza_get_from(xmpp_stanza_t * const stanza)
798774
{
799-
if (stanza->type != XMPP_STANZA_TAG)
800-
return NULL;
801-
802-
if (!stanza->attributes)
803-
return NULL;
804-
805-
return (char *)hash_get(stanza->attributes, "from");
775+
return xmpp_stanza_get_attribute(stanza, "from");
806776
}
807777

808778
/** Get the first child of stanza with name.

0 commit comments

Comments
 (0)