Mercurial > pidgin.yaz
comparison libpurple/protocols/jabber/usermood.c @ 17571:2f23a77eaa04
Some more code style changes
author | Andreas Monitzer <pidgin@monitzer.com> |
---|---|
date | Tue, 12 Jun 2007 00:37:50 +0000 |
parents | 8338e171a43b |
children | 2e0799b916b9 |
comparison
equal
deleted
inserted
replaced
17570:8338e171a43b | 17571:2f23a77eaa04 |
---|---|
23 #include "pep.h" | 23 #include "pep.h" |
24 | 24 |
25 #include <string.h> | 25 #include <string.h> |
26 | 26 |
27 static char *moodstrings[] = { | 27 static char *moodstrings[] = { |
28 "unknown", | |
28 "afraid", | 29 "afraid", |
29 "amazed", | 30 "amazed", |
30 "angry", | 31 "angry", |
31 "annoyed", | 32 "annoyed", |
32 "anxious", | 33 "anxious", |
93 /* it doesn't make sense to have more than one item here, so let's just pick the first one */ | 94 /* it doesn't make sense to have more than one item here, so let's just pick the first one */ |
94 xmlnode *item = xmlnode_get_child(items, "item"); | 95 xmlnode *item = xmlnode_get_child(items, "item"); |
95 JabberMood newmood = UNKNOWN; | 96 JabberMood newmood = UNKNOWN; |
96 char *moodtext = NULL; | 97 char *moodtext = NULL; |
97 JabberBuddy *buddy = jabber_buddy_find(js, from, FALSE); | 98 JabberBuddy *buddy = jabber_buddy_find(js, from, FALSE); |
99 xmlnode *moodinfo, *mood; | |
98 /* ignore the mood of people not on our buddy list */ | 100 /* ignore the mood of people not on our buddy list */ |
99 if(!buddy) | 101 if (!buddy || !item) |
100 return; | 102 return; |
101 | 103 |
102 if(item) { | 104 mood = xmlnode_get_child_with_namespace(item, "mood", "http://jabber.org/protocol/mood"); |
103 xmlnode *mood = xmlnode_get_child_with_namespace(item, "mood", "http://jabber.org/protocol/mood"); | 105 if (!mood) |
104 if(mood) { | 106 return; |
105 xmlnode *moodinfo; | 107 for (moodinfo = mood->child; moodinfo != mood->lastchild; moodinfo = moodinfo->next) { |
106 for(moodinfo = mood->child; moodinfo != mood->lastchild; moodinfo = moodinfo->next) { | 108 if (moodinfo->type == XMLNODE_TYPE_TAG) { |
107 if(moodinfo->type == XMLNODE_TYPE_TAG) { | 109 if (!strcmp(moodinfo->name, "text")) { |
108 if(!strcmp(moodinfo->name, "text")) { | 110 if (!moodtext) /* only pick the first one */ |
109 if(!moodtext) /* only pick the first one */ | 111 moodtext = xmlnode_get_data(moodinfo); |
110 moodtext = xmlnode_get_data(moodinfo); | 112 } else { |
111 } else { | 113 int i; |
112 int i; | 114 for (i = 1; moodstrings[i]; ++i) { |
113 for(i = 0; moodstrings[i]; ++i) { | 115 if (!strcmp(moodinfo->name, moodstrings[i])) { |
114 if(!strcmp(moodinfo->name, moodstrings[i])) { | 116 newmood = (JabberMood)i; |
115 newmood = (JabberMood)(i+1); /* 0 is "unknown", so we have to add 1 */ | 117 break; |
116 break; | |
117 } | |
118 } | |
119 } | 118 } |
120 if(newmood != UNKNOWN && moodtext != NULL) | |
121 break; | |
122 } | 119 } |
123 } | 120 } |
121 if (newmood != UNKNOWN && moodtext != NULL) | |
122 break; | |
124 } | 123 } |
125 } | 124 } |
126 if(newmood != UNKNOWN) { | 125 if (newmood != UNKNOWN) { |
127 JabberBuddyResource *resource = jabber_buddy_find_resource(buddy, NULL); | 126 JabberBuddyResource *resource = jabber_buddy_find_resource(buddy, NULL); |
128 const char *status_id = jabber_buddy_state_get_status_id(resource->state); | 127 const char *status_id = jabber_buddy_state_get_status_id(resource->state); |
129 | 128 |
130 purple_prpl_got_user_status(js->gc->account, from, status_id, "mood", newmood, "moodtext", moodtext?moodtext:"", NULL); | 129 purple_prpl_got_user_status(js->gc->account, from, status_id, "mood", newmood, "moodtext", moodtext?moodtext:"", NULL); |
131 } | 130 } |
132 if(moodtext) | 131 if (moodtext) |
133 g_free(moodtext); | 132 g_free(moodtext); |
134 } | 133 } |
135 | 134 |
136 void jabber_mood_init(void) { | 135 void jabber_mood_init(void) { |
137 jabber_add_feature("mood", "http://jabber.org/protocol/mood"); | 136 jabber_add_feature("mood", "http://jabber.org/protocol/mood"); |
138 jabber_pep_register_handler("moodn", "http://jabber.org/protocol/mood", jabber_mood_cb); | 137 jabber_pep_register_handler("moodn", "http://jabber.org/protocol/mood", jabber_mood_cb); |
139 } | 138 } |
140 | 139 |
141 void jabber_set_mood(JabberStream *js, JabberMood mood, const char *text) { | 140 void jabber_set_mood(JabberStream *js, JabberMood mood, const char *text) { |
142 xmlnode *publish, *moodnode; | 141 xmlnode *publish, *moodnode; |
143 if(mood == UNKNOWN) | 142 if (mood == UNKNOWN) |
144 return; | 143 return; |
145 | 144 |
146 publish = xmlnode_new("publish"); | 145 publish = xmlnode_new("publish"); |
147 xmlnode_set_attrib(publish,"node","http://jabber.org/protocol/mood"); | 146 xmlnode_set_attrib(publish,"node","http://jabber.org/protocol/mood"); |
148 moodnode = xmlnode_new_child(xmlnode_new_child(publish, "item"), "mood"); | 147 moodnode = xmlnode_new_child(xmlnode_new_child(publish, "item"), "mood"); |
149 xmlnode_set_namespace(moodnode, "http://jabber.org/protocol/mood"); | 148 xmlnode_set_namespace(moodnode, "http://jabber.org/protocol/mood"); |
150 xmlnode_new_child(moodnode, moodstrings[mood-1]); | 149 xmlnode_new_child(moodnode, moodstrings[mood]); |
151 | 150 |
152 if(text) { | 151 if (text) { |
153 xmlnode *textnode = xmlnode_new_child(moodnode, "text"); | 152 xmlnode *textnode = xmlnode_new_child(moodnode, "text"); |
154 xmlnode_insert_data(textnode, text, -1); | 153 xmlnode_insert_data(textnode, text, -1); |
155 } | 154 } |
156 | 155 |
157 jabber_pep_publish(js, publish); | 156 jabber_pep_publish(js, publish); |