comparison mcabber/mcabber/xmpp_iqrequest.c @ 1707:184de76b5b18

Refactor some code
author Mikael Berthe <mikael@lilotux.net>
date Mon, 08 Feb 2010 22:00:40 +0100
parents a5263e93c5d7
children f3c5e1175b22
comparison
equal deleted inserted replaced
1706:a5263e93c5d7 1707:184de76b5b18
81 struct timeval *timestamp = (struct timeval *)user_data; 81 struct timeval *timestamp = (struct timeval *)user_data;
82 struct timeval now; 82 struct timeval now;
83 time_t dsec; 83 time_t dsec;
84 suseconds_t dusec; 84 suseconds_t dusec;
85 const gchar *fjid; 85 const gchar *fjid;
86 gchar *bjid; 86 gchar *bjid, *mesg = NULL;
87 87
88 gettimeofday(&now, NULL); 88 gettimeofday(&now, NULL);
89 dsec = now.tv_sec - timestamp->tv_sec; 89 dsec = now.tv_sec - timestamp->tv_sec;
90 if (now.tv_usec < timestamp->tv_usec) { 90 if (now.tv_usec < timestamp->tv_usec) {
91 dusec = now.tv_usec + 1000000 - timestamp->tv_usec; 91 dusec = now.tv_usec + 1000000 - timestamp->tv_usec;
104 104
105 bjid = jidtodisp(fjid); 105 bjid = jidtodisp(fjid);
106 106
107 switch (lm_message_get_sub_type(m)) { 107 switch (lm_message_get_sub_type(m)) {
108 case LM_MESSAGE_SUB_TYPE_RESULT: 108 case LM_MESSAGE_SUB_TYPE_RESULT:
109 { // print to buddy's buffer 109 mesg = g_strdup_printf("Pong from <%s>: %d second%s %d ms.", fjid,
110 gchar *mesg = g_strdup_printf("Pong: %d second%s %d ms.", 110 (int)dsec, dsec > 1 ? "s" : "",
111 (int)dsec, 111 (int)(dusec/1000L));
112 dsec > 1 ? "s" : "",
113 (int)(dusec/1000L));
114
115 scr_WriteIncomingMessage(bjid, mesg, 0, HBB_PREFIX_INFO, 0);
116 g_free(mesg);
117 }
118 break; 112 break;
119 113
120 case LM_MESSAGE_SUB_TYPE_ERROR: 114 case LM_MESSAGE_SUB_TYPE_ERROR:
121 { 115 display_server_error(lm_message_node_get_child(m->node, "error"));
122 LmMessageNode *node = lm_message_get_node(m); 116 mesg = g_strdup_printf("Ping to <%s> failed. "
123 const gchar *type; 117 "Response time: %d second%s %d ms.",
124 const gchar *reason; 118 fjid, (int)dsec, dsec > 1 ? "s" : "",
125 119 (int)(dusec/1000L));
126 node = lm_message_node_get_child(node, "error");
127 type = lm_message_node_get_attribute(node, "type");
128 if (node->children)
129 reason = node->children->name;
130 else
131 reason = "undefined";
132
133 { // print to buddy's buffer
134 gchar *mesg = g_strdup_printf("Ping to %s failed: %s - %s (response time %d second%s %d microseconds)",
135 fjid, type, reason,
136 (int)dsec,
137 dsec > 1 ? "s" : "",
138 (int)(dusec/1000L));
139
140 scr_WriteIncomingMessage(bjid, mesg, 0, HBB_PREFIX_INFO, 0);
141 g_free(mesg);
142 }
143 }
144 break; 120 break;
145 121
146 default: 122 default:
147 g_free(bjid); 123 g_free(bjid);
148 return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS; 124 return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
149 break; 125 break;
150 } 126 }
151 127
128 if (mesg)
129 scr_WriteIncomingMessage(bjid, mesg, 0, HBB_PREFIX_INFO, 0);
130 g_free(mesg);
152 g_free(bjid); 131 g_free(bjid);
153 return LM_HANDLER_RESULT_REMOVE_MESSAGE; 132 return LM_HANDLER_RESULT_REMOVE_MESSAGE;
154 } 133 }
155 134
156 // Warning!! xmlns has to be a namespace from iq_request_handlers[].xmlns 135 // Warning!! xmlns has to be a namespace from iq_request_handlers[].xmlns