43 "Recognizes options cmd_shell, cmd_redirect_stderr, cmd_header and cmd_header_inline\n" \ |
43 "Recognizes options cmd_shell, cmd_redirect_stderr, cmd_header and cmd_header_inline\n" \ |
44 "Provides command /cmd" ) |
44 "Provides command /cmd" ) |
45 |
45 |
46 static module_info_t info_cmd_experimental = { |
46 static module_info_t info_cmd_experimental = { |
47 .branch = "experimental", |
47 .branch = "experimental", |
48 .api = 5, |
48 .api = 10, |
49 .version = PROJECT_VERSION, |
49 .version = PROJECT_VERSION, |
50 .description = DESCRIPTION, |
50 .description = DESCRIPTION, |
51 .requires = NULL, |
51 .requires = NULL, |
52 .init = mcmd_init, |
52 .init = mcmd_init, |
53 .uninit = mcmd_uninit, |
53 .uninit = mcmd_uninit, |
54 .next = NULL, |
54 .next = NULL, |
55 }; |
55 }; |
56 |
56 |
57 module_info_t info_cmd = { |
57 module_info_t info_cmd = { |
58 .branch = "dev", |
58 .branch = "dev", |
59 .api = 4, |
59 .api = 11, |
60 .version = PROJECT_VERSION, |
60 .version = PROJECT_VERSION, |
61 .description = DESCRIPTION, |
61 .description = DESCRIPTION, |
62 .requires = NULL, |
62 .requires = NULL, |
63 .init = mcmd_init, |
63 .init = mcmd_init, |
64 .uninit = mcmd_uninit, |
64 .uninit = mcmd_uninit, |
88 gint crypted; |
88 gint crypted; |
89 |
89 |
90 xmpp_send_msg (to, body, room ? ROSTER_TYPE_ROOM : ROSTER_TYPE_USER, room ? NULL : subject, FALSE /* ? */, &crypted, LM_MESSAGE_SUB_TYPE_NOT_SET, &xep184); |
90 xmpp_send_msg (to, body, room ? ROSTER_TYPE_ROOM : ROSTER_TYPE_USER, room ? NULL : subject, FALSE /* ? */, &crypted, LM_MESSAGE_SUB_TYPE_NOT_SET, &xep184); |
91 |
91 |
92 if (crypted == -1) { |
92 if (crypted == -1) { |
93 scr_LogPrint (LPRINT_LOGNORM, "cmd: Encryption error. Message not sent."); |
93 scr_log_print (LPRINT_LOGNORM, "cmd: Encryption error. Message not sent."); |
94 return FALSE; |
94 return FALSE; |
95 } |
95 } |
96 |
96 |
97 if (!room) { |
97 if (!room) { |
98 if (subject) { |
98 if (subject) { |
117 GError *error = NULL; |
117 GError *error = NULL; |
118 |
118 |
119 chstat = g_io_channel_read_chars (channel, buf, HBB_BLOCKSIZE, &endpos, &error); |
119 chstat = g_io_channel_read_chars (channel, buf, HBB_BLOCKSIZE, &endpos, &error); |
120 |
120 |
121 if (error) { |
121 if (error) { |
122 scr_LogPrint (LPRINT_DEBUG, "cmd: Reading error: %s.", error -> message); |
122 scr_log_print (LPRINT_DEBUG, "cmd: Reading error: %s.", error -> message); |
123 g_clear_error (&error); |
123 g_clear_error (&error); |
124 } |
124 } |
125 |
125 |
126 if (chstat == G_IO_STATUS_ERROR || chstat == G_IO_STATUS_EOF) { |
126 if (chstat == G_IO_STATUS_ERROR || chstat == G_IO_STATUS_EOF) { |
127 cb->source = 0; |
127 cb->source = 0; |
135 gchar *utf8 = NULL; |
135 gchar *utf8 = NULL; |
136 |
136 |
137 g_string_append_len (input, buf, endpos); |
137 g_string_append_len (input, buf, endpos); |
138 |
138 |
139 if (!xmpp_is_online ()) { |
139 if (!xmpp_is_online ()) { |
140 scr_LogPrint (LPRINT_LOGNORM, "cmd: Connection is not ready, delaying data"); |
140 scr_log_print (LPRINT_LOGNORM, "cmd: Connection is not ready, delaying data"); |
141 return TRUE; |
141 return TRUE; |
142 } |
142 } |
143 |
143 |
144 // usual g_locale_to_utf8 seem to be unable to detect locale charset |
144 // usual g_locale_to_utf8 seem to be unable to detect locale charset |
145 // maybe, proper solution will be to call setlocale on module loading, |
145 // maybe, proper solution will be to call setlocale on module loading, |
164 if (written - sent > HBB_BLOCKSIZE) { |
164 if (written - sent > HBB_BLOCKSIZE) { |
165 gchar *c = utf8 + sent + HBB_BLOCKSIZE; |
165 gchar *c = utf8 + sent + HBB_BLOCKSIZE; |
166 c = g_utf8_find_prev_char (utf8 + sent, c); |
166 c = g_utf8_find_prev_char (utf8 + sent, c); |
167 |
167 |
168 if (!c) { |
168 if (!c) { |
169 scr_LogPrint (LPRINT_LOGNORM, "cmd: Cannot determine utf8 character end! End of data chunk will be discarded!"); |
169 scr_log_print (LPRINT_LOGNORM, "cmd: Cannot determine utf8 character end! End of data chunk will be discarded!"); |
170 break; |
170 break; |
171 } |
171 } |
172 |
172 |
173 len = c - utf8 - sent; |
173 len = c - utf8 - sent; |
174 bbuf = g_strndup (utf8 + sent, len); |
174 bbuf = g_strndup (utf8 + sent, len); |
178 |
178 |
179 if (cb -> subject) |
179 if (cb -> subject) |
180 subject = g_strdup_printf (cb -> subject, cb -> seq); |
180 subject = g_strdup_printf (cb -> subject, cb -> seq); |
181 |
181 |
182 if (!cmd_send_msg (cb->jid, subject, len ? bbuf : (utf8 + sent))) |
182 if (!cmd_send_msg (cb->jid, subject, len ? bbuf : (utf8 + sent))) |
183 scr_LogPrint (LPRINT_LOGNORM, "cmd: Encryption error. Message not sent."); |
183 scr_log_print (LPRINT_LOGNORM, "cmd: Encryption error. Message not sent."); |
184 |
184 |
185 if (subject) |
185 if (subject) |
186 g_free (subject); |
186 g_free (subject); |
187 |
187 |
188 if (!len) |
188 if (!len) |
287 |
287 |
288 channel = g_io_channel_unix_new (fd[0]); |
288 channel = g_io_channel_unix_new (fd[0]); |
289 |
289 |
290 g_io_channel_set_encoding (channel, NULL, &error); |
290 g_io_channel_set_encoding (channel, NULL, &error); |
291 if (error) { |
291 if (error) { |
292 scr_LogPrint (LPRINT_DEBUG, "cmd: Cannot unset channel encoding: %s.", error -> message); |
292 scr_log_print (LPRINT_DEBUG, "cmd: Cannot unset channel encoding: %s.", error -> message); |
293 g_clear_error (&error); |
293 g_clear_error (&error); |
294 } |
294 } |
295 g_io_channel_set_buffered (channel, FALSE); |
295 g_io_channel_set_buffered (channel, FALSE); |
296 g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, &error); |
296 g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, &error); |
297 if (error) { |
297 if (error) { |
298 scr_LogPrint (LPRINT_DEBUG, "cmd: Cannot set nonblocking flag on channel: %s.", error -> message); |
298 scr_log_print (LPRINT_DEBUG, "cmd: Cannot set nonblocking flag on channel: %s.", error -> message); |
299 g_error_free (error); |
299 g_error_free (error); |
300 } |
300 } |
301 g_io_channel_set_close_on_unref (channel, TRUE); |
301 g_io_channel_set_close_on_unref (channel, TRUE); |
302 } |
302 } |
303 |
303 |