root / trunk / plugins / jsonrpc / jsonrpc_events.c @ 1913
History | View | Annotate | Download (24.4 KB)
| 1 | 
                  /* 
                 | 
              
|---|---|
| 2 | 
                  Copyright (C) 2005-2010 Erik van Pienbroek  | 
              
| 3 | 
                   | 
              
| 4 | 
                  This program is free software; you can redistribute it and/or modify  | 
              
| 5 | 
                  it under the terms of the GNU General Public License as published by  | 
              
| 6 | 
                  the Free Software Foundation; either version 2 of the License, or  | 
              
| 7 | 
                  (at your option) any later version.  | 
              
| 8 | 
                   | 
              
| 9 | 
                  This program is distributed in the hope that it will be useful,  | 
              
| 10 | 
                  but WITHOUT ANY WARRANTY; without even the implied warranty of  | 
              
| 11 | 
                  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  | 
              
| 12 | 
                  GNU General Public License for more details.  | 
              
| 13 | 
                   | 
              
| 14 | 
                  You should have received a copy of the GNU General Public License  | 
              
| 15 | 
                  along with this program; if not, write to the Free Software  | 
              
| 16 | 
                  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA  | 
              
| 17 | 
                  */  | 
              
| 18 | 
                   | 
              
| 19 | 
                  #ifdef _MSC_VER
                 | 
              
| 20 | 
                  #include "config.h.win32"  | 
              
| 21 | 
                  #else
                 | 
              
| 22 | 
                  #include "config.h"  | 
              
| 23 | 
                  #endif
                 | 
              
| 24 | 
                   | 
              
| 25 | 
                  #include  | 
              
| 26 | 
                  #include  | 
              
| 27 | 
                  #include  | 
              
| 28 | 
                   | 
              
| 29 | 
                  #include  | 
              
| 30 | 
                  #include  | 
              
| 31 | 
                   | 
              
| 32 | 
                  #include "nntpgrab_plugin.h"  | 
              
| 33 | 
                  #include "nntpgrab_utils.h"  | 
              
| 34 | 
                   | 
              
| 35 | 
                  #include "json.h"  | 
              
| 36 | 
                  #include "jsonrpc.h"  | 
              
| 37 | 
                   | 
              
| 38 | 
                  #undef max
                 | 
              
| 39 | 
                  #define max(a,b) (((a) > (b)) ? (a) : (b))
                 | 
              
| 40 | 
                   | 
              
| 41 | 
                  void jsonrpc_tcp_emit_event(const char *json_data);  | 
              
| 42 | 
                   | 
              
| 43 | 
                  static void  | 
              
| 44 | 
                  emit_event(const char *event_name, struct json_object *event)  | 
              
| 45 | 
                  {
                 | 
              
| 46 | 
                      struct json_object *tcp_event = json_object_new_object();
                 | 
              
| 47 | 
                   | 
              
| 48 | 
                      jsonrpc_add_event((char*) event_name, json_object_get(event));
                 | 
              
| 49 | 
                   | 
              
| 50 | 
                  json_object_object_add(tcp_event, "id", NULL);  | 
              
| 51 | 
                  json_object_object_add(tcp_event, "method", json_object_new_string((char*) event_name));  | 
              
| 52 | 
                      json_object_object_add(tcp_event, "params", event);
                 | 
              
| 53 | 
                  jsonrpc_tcp_emit_event(json_object_to_json_string(tcp_event));  | 
              
| 54 | 
                   | 
              
| 55 | 
                  json_object_put(tcp_event);  | 
              
| 56 | 
                  }  | 
              
| 57 | 
                   | 
              
| 58 | 
                  static void  | 
              
| 59 | 
                  config_changed (NGPlugin *plugin_data, gpointer data)  | 
              
| 60 | 
                  {
                 | 
              
| 61 | 
                      struct json_object *event = json_object_new_object();
                 | 
              
| 62 | 
                   | 
              
| 63 | 
                      emit_event("config_changed", event);
                 | 
              
| 64 | 
                   | 
              
| 65 | 
                  json_object_put(event);  | 
              
| 66 | 
                  }  | 
              
| 67 | 
                   | 
              
| 68 | 
                  static void  | 
              
| 69 | 
                  part_download_start (NGPlugin *plugin_data, const char *servername, int conn_id, const char *collection_name, const char *subject, int part_num, gpointer data)  | 
              
| 70 | 
                  {
                 | 
              
| 71 | 
                      struct json_object *event = json_object_new_object();
                 | 
              
| 72 | 
                   | 
              
| 73 | 
                  json_object_object_add(event, "servername", json_object_new_string((char*) servername));  | 
              
| 74 | 
                      json_object_object_add(event, "conn_id", json_object_new_int(conn_id));
                 | 
              
| 75 | 
                  json_object_object_add(event, "collection_name", json_object_new_string((char*) collection_name));  | 
              
| 76 | 
                  json_object_object_add(event, "subject", json_object_new_string((char*) subject));  | 
              
| 77 | 
                      json_object_object_add(event, "part_num", json_object_new_int(part_num));
                 | 
              
| 78 | 
                   | 
              
| 79 | 
                      emit_event("part_download_start", event);
                 | 
              
| 80 | 
                   | 
              
| 81 | 
                  json_object_put(event);  | 
              
| 82 | 
                  }  | 
              
| 83 | 
                   | 
              
| 84 | 
                  static void  | 
              
| 85 | 
                  part_done (NGPlugin *plugin_data, const char *servername, int conn_id, const char *collection_name, const char *subject, int part_num, int size, gpointer data)  | 
              
| 86 | 
                  {
                 | 
              
| 87 | 
                      struct json_object *event = json_object_new_object();
                 | 
              
| 88 | 
                   | 
              
| 89 | 
                  json_object_object_add(event, "servername", json_object_new_string((char*) servername));  | 
              
| 90 | 
                      json_object_object_add(event, "conn_id", json_object_new_int(conn_id));
                 | 
              
| 91 | 
                  json_object_object_add(event, "collection_name", json_object_new_string((char*) collection_name));  | 
              
| 92 | 
                  json_object_object_add(event, "subject", json_object_new_string((char*) subject));  | 
              
| 93 | 
                      json_object_object_add(event, "part_num", json_object_new_int(part_num));
                 | 
              
| 94 | 
                      json_object_object_add(event, "size", json_object_new_int(size));
                 | 
              
| 95 | 
                   | 
              
| 96 | 
                      emit_event("part_done", event);
                 | 
              
| 97 | 
                   | 
              
| 98 | 
                  json_object_put(event);  | 
              
| 99 | 
                  }  | 
              
| 100 | 
                   | 
              
| 101 | 
                  static void  | 
              
| 102 | 
                  part_failed (NGPlugin *plugin_data, const char *servername, int conn_id, const char *collection_name, const char *subject, int part_num, int size, gboolean all_servers_tried, gpointer data)  | 
              
| 103 | 
                  {
                 | 
              
| 104 | 
                      struct json_object *event = json_object_new_object();
                 | 
              
| 105 | 
                   | 
              
| 106 | 
                  json_object_object_add(event, "servername", json_object_new_string((char*) servername));  | 
              
| 107 | 
                      json_object_object_add(event, "conn_id", json_object_new_int(conn_id));
                 | 
              
| 108 | 
                  json_object_object_add(event, "collection_name", json_object_new_string((char*) collection_name));  | 
              
| 109 | 
                  json_object_object_add(event, "subject", json_object_new_string((char*) subject));  | 
              
| 110 | 
                      json_object_object_add(event, "part_num", json_object_new_int(part_num));
                 | 
              
| 111 | 
                      json_object_object_add(event, "size", json_object_new_int(size));
                 | 
              
| 112 | 
                      json_object_object_add(event, "all_servers_tried", json_object_new_boolean(all_servers_tried));
                 | 
              
| 113 | 
                   | 
              
| 114 | 
                      emit_event("part_failed", event);
                 | 
              
| 115 | 
                   | 
              
| 116 | 
                  json_object_put(event);  | 
              
| 117 | 
                  }  | 
              
| 118 | 
                   | 
              
| 119 | 
                  static void  | 
              
| 120 | 
                  traffic_monitor_update (NGPlugin *plugin_data, int bytes_received1, int bytes_received2, int bytes_received3, int bytes_received4, int bytes_received5, int bytes_received6, int bytes_received7, int bytes_received8, int bytes_received9, int bytes_received10, guint64 stamp, double average, gpointer data)  | 
              
| 121 | 
                  {
                 | 
              
| 122 | 
                      struct json_object *event = json_object_new_object();
                 | 
              
| 123 | 
                   | 
              
| 124 | 
                      json_object_object_add(event, "bytes_received1", json_object_new_int(bytes_received1));
                 | 
              
| 125 | 
                      json_object_object_add(event, "bytes_received2", json_object_new_int(bytes_received2));
                 | 
              
| 126 | 
                      json_object_object_add(event, "bytes_received3", json_object_new_int(bytes_received3));
                 | 
              
| 127 | 
                      json_object_object_add(event, "bytes_received4", json_object_new_int(bytes_received4));
                 | 
              
| 128 | 
                      json_object_object_add(event, "bytes_received5", json_object_new_int(bytes_received5));
                 | 
              
| 129 | 
                      json_object_object_add(event, "bytes_received6", json_object_new_int(bytes_received6));
                 | 
              
| 130 | 
                      json_object_object_add(event, "bytes_received7", json_object_new_int(bytes_received7));
                 | 
              
| 131 | 
                      json_object_object_add(event, "bytes_received8", json_object_new_int(bytes_received8));
                 | 
              
| 132 | 
                      json_object_object_add(event, "bytes_received9", json_object_new_int(bytes_received9));
                 | 
              
| 133 | 
                      json_object_object_add(event, "bytes_received10", json_object_new_int(bytes_received10));
                 | 
              
| 134 | 
                      json_object_object_add(event, "stamp", json_object_new_int(stamp));
                 | 
              
| 135 | 
                      json_object_object_add(event, "average", json_object_new_double(average));
                 | 
              
| 136 | 
                   | 
              
| 137 | 
                      emit_event("traffic_monitor_update", event);
                 | 
              
| 138 | 
                   | 
              
| 139 | 
                  json_object_put(event);  | 
              
| 140 | 
                  }  | 
              
| 141 | 
                   | 
              
| 142 | 
                  static void  | 
              
| 143 | 
                  part_progress_update (NGPlugin *plugin_data, const char *servername, int conn_id, const char *collection_name, const char *subject, int part_num, int bytes_downloaded, int bytes_total, gpointer data)  | 
              
| 144 | 
                  {
                 | 
              
| 145 | 
                      struct json_object *event = json_object_new_object();
                 | 
              
| 146 | 
                   | 
              
| 147 | 
                  json_object_object_add(event, "servername", json_object_new_string((char*) servername));  | 
              
| 148 | 
                      json_object_object_add(event, "conn_id", json_object_new_int(conn_id));
                 | 
              
| 149 | 
                  json_object_object_add(event, "collection_name", json_object_new_string((char*) collection_name));  | 
              
| 150 | 
                  json_object_object_add(event, "subject", json_object_new_string((char*) subject));  | 
              
| 151 | 
                      json_object_object_add(event, "part_num", json_object_new_int(part_num));
                 | 
              
| 152 | 
                      json_object_object_add(event, "bytes_downloaded", json_object_new_int(bytes_downloaded));
                 | 
              
| 153 | 
                      json_object_object_add(event, "bytes_total", json_object_new_int(bytes_total));
                 | 
              
| 154 | 
                   | 
              
| 155 | 
                      emit_event("part_progress_update", event);
                 | 
              
| 156 | 
                   | 
              
| 157 | 
                  json_object_put(event);  | 
              
| 158 | 
                  }  | 
              
| 159 | 
                   | 
              
| 160 | 
                  static void  | 
              
| 161 | 
                  collection_added (NGPlugin *plugin_data, const char *collection_name, const char *poster, gpointer data)  | 
              
| 162 | 
                  {
                 | 
              
| 163 | 
                      struct json_object *event = json_object_new_object();
                 | 
              
| 164 | 
                   | 
              
| 165 | 
                  json_object_object_add(event, "collection_name", json_object_new_string((char*) collection_name));  | 
              
| 166 | 
                  json_object_object_add(event, "poster", json_object_new_string((char*) poster));  | 
              
| 167 | 
                   | 
              
| 168 | 
                      emit_event("collection_added", event);
                 | 
              
| 169 | 
                   | 
              
| 170 | 
                  json_object_put(event);  | 
              
| 171 | 
                  }  | 
              
| 172 | 
                   | 
              
| 173 | 
                  static void  | 
              
| 174 | 
                  collection_removed (NGPlugin *plugin_data, const char *collection_name, gpointer data)  | 
              
| 175 | 
                  {
                 | 
              
| 176 | 
                      struct json_object *event = json_object_new_object();
                 | 
              
| 177 | 
                   | 
              
| 178 | 
                  json_object_object_add(event, "collection_name", json_object_new_string((char*) collection_name));  | 
              
| 179 | 
                   | 
              
| 180 | 
                      emit_event("collection_removed", event);
                 | 
              
| 181 | 
                   | 
              
| 182 | 
                  json_object_put(event);  | 
              
| 183 | 
                  }  | 
              
| 184 | 
                   | 
              
| 185 | 
                  static void  | 
              
| 186 | 
                  collection_modified (NGPlugin *plugin_data, const char *collection_name, const char *poster, gpointer data)  | 
              
| 187 | 
                  {
                 | 
              
| 188 | 
                      struct json_object *event = json_object_new_object();
                 | 
              
| 189 | 
                   | 
              
| 190 | 
                  json_object_object_add(event, "collection_name", json_object_new_string((char*) collection_name));  | 
              
| 191 | 
                  json_object_object_add(event, "poster", json_object_new_string((char*) poster));  | 
              
| 192 | 
                   | 
              
| 193 | 
                      emit_event("collection_modified", event);
                 | 
              
| 194 | 
                   | 
              
| 195 | 
                  json_object_put(event);  | 
              
| 196 | 
                  }  | 
              
| 197 | 
                   | 
              
| 198 | 
                  static void  | 
              
| 199 | 
                  file_added (NGPlugin *plugin_data, const char *collection_name, const char *subject, const char *poster, guint64 stamp, guint64 file_size, guint64 total_size, guint64 total_size_remaining, NGTaskState status, int num_parts, GList *groups, gpointer data)  | 
              
| 200 | 
                  {
                 | 
              
| 201 | 
                      struct json_object *event = json_object_new_object();
                 | 
              
| 202 | 
                      struct json_object *obj_groups = json_object_new_array();
                 | 
              
| 203 | 
                  GList *list;  | 
              
| 204 | 
                  int i_file_size = 0;  | 
              
| 205 | 
                  int i_total_size = 0;  | 
              
| 206 | 
                  int i_total_size_remaining = 0;  | 
              
| 207 | 
                   | 
              
| 208 | 
                  if (file_size != 0) {  | 
              
| 209 | 
                  i_file_size = max(1, file_size / 1024);  | 
              
| 210 | 
                  }  | 
              
| 211 | 
                  if (total_size != 0) {  | 
              
| 212 | 
                  i_total_size = max(1, total_size / 1024);  | 
              
| 213 | 
                  }  | 
              
| 214 | 
                  if (total_size_remaining != 0) {  | 
              
| 215 | 
                  i_total_size_remaining = max(1, total_size_remaining / 1024);  | 
              
| 216 | 
                  }  | 
              
| 217 | 
                   | 
              
| 218 | 
                  json_object_object_add(event, "collection_name", json_object_new_string((char*) collection_name));  | 
              
| 219 | 
                  json_object_object_add(event, "subject", json_object_new_string((char*) subject));  | 
              
| 220 | 
                  json_object_object_add(event, "poster", json_object_new_string((char*) poster));  | 
              
| 221 | 
                      json_object_object_add(event, "stamp", json_object_new_int(stamp));
                 | 
              
| 222 | 
                      json_object_object_add(event, "file_size", json_object_new_int(i_file_size));
                 | 
              
| 223 | 
                      json_object_object_add(event, "total_size", json_object_new_int(i_total_size));
                 | 
              
| 224 | 
                      json_object_object_add(event, "total_size_remaining", json_object_new_int(i_total_size_remaining));
                 | 
              
| 225 | 
                      json_object_object_add(event, "status", json_object_new_int(status));
                 | 
              
| 226 | 
                      json_object_object_add(event, "num_parts", json_object_new_int(num_parts));
                 | 
              
| 227 | 
                      json_object_object_add(event, "groups", obj_groups);
                 | 
              
| 228 | 
                   | 
              
| 229 | 
                  list = groups;  | 
              
| 230 | 
                      while (list) {
                 | 
              
| 231 | 
                          char *groupname = list->data;
                 | 
              
| 232 | 
                   | 
              
| 233 | 
                  json_object_array_add(obj_groups, json_object_new_string(groupname));  | 
              
| 234 | 
                   | 
              
| 235 | 
                  list = g_list_next(list);  | 
              
| 236 | 
                  }  | 
              
| 237 | 
                   | 
              
| 238 | 
                      emit_event("file_added", event);
                 | 
              
| 239 | 
                   | 
              
| 240 | 
                  json_object_put(event);  | 
              
| 241 | 
                  }  | 
              
| 242 | 
                   | 
              
| 243 | 
                  static void  | 
              
| 244 | 
                  file_removed (NGPlugin *plugin_data, const char *collection_name, const char *subject, guint64 total_size, guint64 total_size_remaining, gpointer data)  | 
              
| 245 | 
                  {
                 | 
              
| 246 | 
                      struct json_object *event = json_object_new_object();
                 | 
              
| 247 | 
                  int i_total_size = 0;  | 
              
| 248 | 
                  int i_total_size_remaining = 0;  | 
              
| 249 | 
                   | 
              
| 250 | 
                  if (total_size != 0) {  | 
              
| 251 | 
                  i_total_size = max(1, total_size / 1024);  | 
              
| 252 | 
                  }  | 
              
| 253 | 
                  if (total_size_remaining != 0) {  | 
              
| 254 | 
                  i_total_size_remaining = max(1, total_size_remaining / 1024);  | 
              
| 255 | 
                  }  | 
              
| 256 | 
                   | 
              
| 257 | 
                  json_object_object_add(event, "collection_name", json_object_new_string((char*) collection_name));  | 
              
| 258 | 
                  json_object_object_add(event, "subject", json_object_new_string((char*) subject));  | 
              
| 259 | 
                      json_object_object_add(event, "total_size", json_object_new_int(i_total_size));
                 | 
              
| 260 | 
                      json_object_object_add(event, "total_size_remaining", json_object_new_int(i_total_size_remaining));
                 | 
              
| 261 | 
                   | 
              
| 262 | 
                      emit_event("file_removed", event);
                 | 
              
| 263 | 
                   | 
              
| 264 | 
                  json_object_put(event);  | 
              
| 265 | 
                  }  | 
              
| 266 | 
                   | 
              
| 267 | 
                  static void  | 
              
| 268 | 
                  file_download_state_update (NGPlugin *plugin_data, const char *collection_name, const char *subject, int num_parts_total, int num_parts_done, int num_parts_failed, guint64 file_size, guint64 file_size_remaining, guint64 total_size, guint64 total_size_remaining, gpointer data)  | 
              
| 269 | 
                  {
                 | 
              
| 270 | 
                      struct json_object *event = json_object_new_object();
                 | 
              
| 271 | 
                  int i_file_size = 0;  | 
              
| 272 | 
                  int i_file_size_remaining = 0;  | 
              
| 273 | 
                  int i_total_size = 0;  | 
              
| 274 | 
                  int i_total_size_remaining = 0;  | 
              
| 275 | 
                   | 
              
| 276 | 
                  if (file_size != 0) {  | 
              
| 277 | 
                  i_file_size = max(1, file_size / 1024);  | 
              
| 278 | 
                  }  | 
              
| 279 | 
                      if (file_size_remaining) {
                 | 
              
| 280 | 
                  i_file_size_remaining = max(1, file_size_remaining / 1024);  | 
              
| 281 | 
                  }  | 
              
| 282 | 
                  if (total_size != 0) {  | 
              
| 283 | 
                  i_total_size = max(1, total_size / 1024);  | 
              
| 284 | 
                  }  | 
              
| 285 | 
                  if (total_size_remaining != 0) {  | 
              
| 286 | 
                  i_total_size_remaining = max(1, total_size_remaining / 1024);  | 
              
| 287 | 
                  }  | 
              
| 288 | 
                   | 
              
| 289 | 
                  json_object_object_add(event, "collection_name", json_object_new_string((char*) collection_name));  | 
              
| 290 | 
                  json_object_object_add(event, "subject", json_object_new_string((char*) subject));  | 
              
| 291 | 
                      json_object_object_add(event, "num_parts_total", json_object_new_int(num_parts_total));
                 | 
              
| 292 | 
                      json_object_object_add(event, "num_parts_done", json_object_new_int(num_parts_done));
                 | 
              
| 293 | 
                      json_object_object_add(event, "num_parts_failed", json_object_new_int(num_parts_failed));
                 | 
              
| 294 | 
                      json_object_object_add(event, "file_size", json_object_new_int(i_file_size));
                 | 
              
| 295 | 
                      json_object_object_add(event, "file_size_remaining", json_object_new_int(i_file_size_remaining));
                 | 
              
| 296 | 
                      json_object_object_add(event, "total_size", json_object_new_int(i_total_size));
                 | 
              
| 297 | 
                      json_object_object_add(event, "total_size_remaining", json_object_new_int(i_total_size_remaining));
                 | 
              
| 298 | 
                   | 
              
| 299 | 
                      emit_event("file_download_state_update", event);
                 | 
              
| 300 | 
                   | 
              
| 301 | 
                  json_object_put(event);  | 
              
| 302 | 
                  }  | 
              
| 303 | 
                   | 
              
| 304 | 
                  static void  | 
              
| 305 | 
                  file_state_changed (NGPlugin *plugin_data, const char *collection_name, const char *subject, const char *real_filename, NGTaskState old_state, NGTaskState new_state, guint64 file_size_remaining, guint64 total_size, guint64 total_size_remaining, gpointer data)  | 
              
| 306 | 
                  {
                 | 
              
| 307 | 
                      struct json_object *event = json_object_new_object();
                 | 
              
| 308 | 
                  int i_file_size_remaining = 0;  | 
              
| 309 | 
                  int i_total_size = 0;  | 
              
| 310 | 
                  int i_total_size_remaining = 0;  | 
              
| 311 | 
                   | 
              
| 312 | 
                      if (file_size_remaining) {
                 | 
              
| 313 | 
                  i_file_size_remaining = max(1, file_size_remaining / 1024);  | 
              
| 314 | 
                  }  | 
              
| 315 | 
                  if (total_size != 0) {  | 
              
| 316 | 
                  i_total_size = max(1, total_size / 1024);  | 
              
| 317 | 
                  }  | 
              
| 318 | 
                  if (total_size_remaining != 0) {  | 
              
| 319 | 
                  i_total_size_remaining = max(1, total_size_remaining / 1024);  | 
              
| 320 | 
                  }  | 
              
| 321 | 
                   | 
              
| 322 | 
                  json_object_object_add(event, "collection_name", json_object_new_string((char*) collection_name));  | 
              
| 323 | 
                  json_object_object_add(event, "subject", json_object_new_string((char*) subject));  | 
              
| 324 | 
                  json_object_object_add(event, "real_filename", json_object_new_string((char*) (real_filename ? real_filename : "")));  | 
              
| 325 | 
                      json_object_object_add(event, "old_state", json_object_new_int(old_state));
                 | 
              
| 326 | 
                      json_object_object_add(event, "new_state", json_object_new_int(new_state));
                 | 
              
| 327 | 
                      json_object_object_add(event, "file_size_remaining", json_object_new_int(i_file_size_remaining));
                 | 
              
| 328 | 
                      json_object_object_add(event, "total_size", json_object_new_int(i_total_size));
                 | 
              
| 329 | 
                      json_object_object_add(event, "total_size_remaining", json_object_new_int(i_total_size_remaining));
                 | 
              
| 330 | 
                   | 
              
| 331 | 
                      emit_event("file_state_changed", event);
                 | 
              
| 332 | 
                   | 
              
| 333 | 
                  json_object_put(event);  | 
              
| 334 | 
                  }  | 
              
| 335 | 
                   | 
              
| 336 | 
                  static void  | 
              
| 337 | 
                  connection_connecting (NGPlugin *plugin_data, const char *servername, int conn_id, gpointer data)  | 
              
| 338 | 
                  {
                 | 
              
| 339 | 
                      struct json_object *event = json_object_new_object();
                 | 
              
| 340 | 
                   | 
              
| 341 | 
                  json_object_object_add(event, "servername", json_object_new_string((char*) servername));  | 
              
| 342 | 
                      json_object_object_add(event, "conn_id", json_object_new_int(conn_id));
                 | 
              
| 343 | 
                   | 
              
| 344 | 
                      emit_event("connection_connecting", event);
                 | 
              
| 345 | 
                   | 
              
| 346 | 
                  json_object_put(event);  | 
              
| 347 | 
                  }  | 
              
| 348 | 
                   | 
              
| 349 | 
                  static void  | 
              
| 350 | 
                  connection_connected (NGPlugin *plugin_data, const char *servername, int conn_id, const char *welcome_msg, gpointer data)  | 
              
| 351 | 
                  {
                 | 
              
| 352 | 
                      struct json_object *event = json_object_new_object();
                 | 
              
| 353 | 
                   | 
              
| 354 | 
                  json_object_object_add(event, "servername", json_object_new_string((char*) servername));  | 
              
| 355 | 
                      json_object_object_add(event, "conn_id", json_object_new_int(conn_id));
                 | 
              
| 356 | 
                  json_object_object_add(event, "welcome_msg", json_object_new_string((char*) welcome_msg));  | 
              
| 357 | 
                   | 
              
| 358 | 
                      emit_event("connection_connected", event);
                 | 
              
| 359 | 
                   | 
              
| 360 | 
                  json_object_put(event);  | 
              
| 361 | 
                  }  | 
              
| 362 | 
                   | 
              
| 363 | 
                  static void  | 
              
| 364 | 
                  connection_disconnect (NGPlugin *plugin_data, const char *servername, int conn_id, NNTPDisconnectType disconnect_type, const char *msg, gpointer data)  | 
              
| 365 | 
                  {
                 | 
              
| 366 | 
                      struct json_object *event = json_object_new_object();
                 | 
              
| 367 | 
                   | 
              
| 368 | 
                  json_object_object_add(event, "servername", json_object_new_string((char*) servername));  | 
              
| 369 | 
                      json_object_object_add(event, "conn_id", json_object_new_int(conn_id));
                 | 
              
| 370 | 
                      json_object_object_add(event, "disconnect_type", json_object_new_int(disconnect_type));
                 | 
              
| 371 | 
                  json_object_object_add(event, "reason", json_object_new_string((char*) (msg ? msg : "")));  | 
              
| 372 | 
                   | 
              
| 373 | 
                      emit_event("connection_disconnect", event);
                 | 
              
| 374 | 
                   | 
              
| 375 | 
                  json_object_put(event);  | 
              
| 376 | 
                  }  | 
              
| 377 | 
                   | 
              
| 378 | 
                  static void  | 
              
| 379 | 
                  schedular_state_changed (NGPlugin *plugin_data, NGSchedularState new_state, const char *reason, gpointer data)  | 
              
| 380 | 
                  {
                 | 
              
| 381 | 
                      struct json_object *event = json_object_new_object();
                 | 
              
| 382 | 
                   | 
              
| 383 | 
                      json_object_object_add(event, "new_state", json_object_new_int(new_state));
                 | 
              
| 384 | 
                  json_object_object_add(event, "reason", json_object_new_string((char*) (reason ? reason : "")));  | 
              
| 385 | 
                   | 
              
| 386 | 
                      emit_event("schedular_state_changed", event);
                 | 
              
| 387 | 
                   | 
              
| 388 | 
                  json_object_put(event);  | 
              
| 389 | 
                  }  | 
              
| 390 | 
                   | 
              
| 391 | 
                  static void  | 
              
| 392 | 
                  log_message (NGPlugin *plugin_data, const char *component, NGLogLevel log_level, const char *msg, gpointer data)  | 
              
| 393 | 
                  {
                 | 
              
| 394 | 
                      struct json_object *event = json_object_new_object();
                 | 
              
| 395 | 
                   | 
              
| 396 | 
                  json_object_object_add(event, "component", json_object_new_string((char*) component));  | 
              
| 397 | 
                      json_object_object_add(event, "log_level", json_object_new_int(log_level));
                 | 
              
| 398 | 
                  json_object_object_add(event, "msg", json_object_new_string((char*) msg));  | 
              
| 399 | 
                   | 
              
| 400 | 
                      emit_event("log_message", event);
                 | 
              
| 401 | 
                   | 
              
| 402 | 
                  json_object_put(event);  | 
              
| 403 | 
                  }  | 
              
| 404 | 
                   | 
              
| 405 | 
                  static void  | 
              
| 406 | 
                  task_moved (NGPlugin *plugin_data, const char *orig_collection_name, const char *subject, const char *new_collection_name, int old_position, int new_position, gpointer data)  | 
              
| 407 | 
                  {
                 | 
              
| 408 | 
                      struct json_object *event = json_object_new_object();
                 | 
              
| 409 | 
                   | 
              
| 410 | 
                  json_object_object_add(event, "orig_collection_name", json_object_new_string((char*) orig_collection_name));  | 
              
| 411 | 
                  json_object_object_add(event, "subject", json_object_new_string((char*) subject));  | 
              
| 412 | 
                  json_object_object_add(event, "new_collection_name", json_object_new_string((char*) new_collection_name));  | 
              
| 413 | 
                      json_object_object_add(event, "old_position", json_object_new_int(old_position));
                 | 
              
| 414 | 
                      json_object_object_add(event, "new_position", json_object_new_int(new_position));
                 | 
              
| 415 | 
                   | 
              
| 416 | 
                      emit_event("task_moved", event);
                 | 
              
| 417 | 
                   | 
              
| 418 | 
                  json_object_put(event);  | 
              
| 419 | 
                  }  | 
              
| 420 | 
                   | 
              
| 421 | 
                  static void  | 
              
| 422 | 
                  collection_moved (NGPlugin *plugin_data, const char *collection_name, int old_position, int new_position, gpointer data)  | 
              
| 423 | 
                  {
                 | 
              
| 424 | 
                      struct json_object *event = json_object_new_object();
                 | 
              
| 425 | 
                   | 
              
| 426 | 
                  json_object_object_add(event, "collection_name", json_object_new_string((char*) collection_name));  | 
              
| 427 | 
                      json_object_object_add(event, "old_position", json_object_new_int(old_position));
                 | 
              
| 428 | 
                      json_object_object_add(event, "new_position", json_object_new_int(new_position));
                 | 
              
| 429 | 
                   | 
              
| 430 | 
                      emit_event("collection_moved", event);
                 | 
              
| 431 | 
                   | 
              
| 432 | 
                  json_object_put(event);  | 
              
| 433 | 
                  }  | 
              
| 434 | 
                   | 
              
| 435 | 
                  static void  | 
              
| 436 | 
                  all_downloads_completed (NGPlugin *plugin_data, gpointer data)  | 
              
| 437 | 
                  {
                 | 
              
| 438 | 
                      struct json_object *event = json_object_new_object();
                 | 
              
| 439 | 
                   | 
              
| 440 | 
                      emit_event("all_downloads_completed", event);
                 | 
              
| 441 | 
                   | 
              
| 442 | 
                  json_object_put(event);  | 
              
| 443 | 
                  }  | 
              
| 444 | 
                   | 
              
| 445 | 
                  static void  | 
              
| 446 | 
                  plugin_loaded (NGPlugin *plugin_data, const char *plugin_name, gboolean is_persistent, gpointer data)  | 
              
| 447 | 
                  {
                 | 
              
| 448 | 
                      struct json_object *event = json_object_new_object();
                 | 
              
| 449 | 
                   | 
              
| 450 | 
                  json_object_object_add(event, "plugin_name", json_object_new_string((char*) plugin_name));  | 
              
| 451 | 
                      json_object_object_add(event, "is_persistent", json_object_new_boolean(is_persistent));
                 | 
              
| 452 | 
                   | 
              
| 453 | 
                      emit_event("plugin_loaded", event);
                 | 
              
| 454 | 
                   | 
              
| 455 | 
                  json_object_put(event);  | 
              
| 456 | 
                  }  | 
              
| 457 | 
                   | 
              
| 458 | 
                  static void  | 
              
| 459 | 
                  plugin_unloaded (NGPlugin *plugin_data, const char *plugin_name, gpointer data)  | 
              
| 460 | 
                  {
                 | 
              
| 461 | 
                      struct json_object *event = json_object_new_object();
                 | 
              
| 462 | 
                   | 
              
| 463 | 
                  json_object_object_add(event, "plugin_name", json_object_new_string((char*) plugin_name));  | 
              
| 464 | 
                   | 
              
| 465 | 
                      emit_event("plugin_unloaded", event);
                 | 
              
| 466 | 
                   | 
              
| 467 | 
                  json_object_put(event);  | 
              
| 468 | 
                  }  | 
              
| 469 | 
                   | 
              
| 470 | 
                  static void  | 
              
| 471 | 
                  plugin_event (NGPlugin *plugin_data, const char *plugin_name, const char *event_name, const char **values)  | 
              
| 472 | 
                  {
                 | 
              
| 473 | 
                      struct json_object *event = json_object_new_object();
                 | 
              
| 474 | 
                      struct json_object *obj_values = json_object_new_array();
                 | 
              
| 475 | 
                      int i;
                 | 
              
| 476 | 
                   | 
              
| 477 | 
                  json_object_object_add(event, "plugin_name", json_object_new_string((char*) plugin_name));  | 
              
| 478 | 
                  json_object_object_add(event, "event_name", json_object_new_string((char*) event_name));  | 
              
| 479 | 
                      json_object_object_add(event, "values", obj_values);
                 | 
              
| 480 | 
                   | 
              
| 481 | 
                      i = 0;
                 | 
              
| 482 | 
                      while (values && values[i]) {
                 | 
              
| 483 | 
                          json_object_array_add(obj_values, json_object_new_string((char*) values[i]));
                 | 
              
| 484 | 
                  i++;  | 
              
| 485 | 
                  }  | 
              
| 486 | 
                   | 
              
| 487 | 
                      emit_event("plugin_event", event);
                 | 
              
| 488 | 
                   | 
              
| 489 | 
                  json_object_put(event);  | 
              
| 490 | 
                  }  | 
              
| 491 | 
                   | 
              
| 492 | 
                  void
                 | 
              
| 493 | 
                  jsonrpc_connect_signal_handlers(NGPlugin *plugin_data)  | 
              
| 494 | 
                  {
                 | 
              
| 495 | 
                      gpointer data = NULL;
                 | 
              
| 496 | 
                   | 
              
| 497 | 
                      ng_plugin_connect_event(plugin_data, "config_changed", NG_PLUGIN_FUNCTION(config_changed), data);
                 | 
              
| 498 | 
                      ng_plugin_connect_event(plugin_data, "part_download_start", NG_PLUGIN_FUNCTION(part_download_start), data);
                 | 
              
| 499 | 
                      ng_plugin_connect_event(plugin_data, "part_done", NG_PLUGIN_FUNCTION(part_done), data);
                 | 
              
| 500 | 
                      ng_plugin_connect_event(plugin_data, "part_failed", NG_PLUGIN_FUNCTION(part_failed), data);
                 | 
              
| 501 | 
                      ng_plugin_connect_event(plugin_data, "traffic_monitor_update", NG_PLUGIN_FUNCTION(traffic_monitor_update), data);
                 | 
              
| 502 | 
                      ng_plugin_connect_event(plugin_data, "part_progress_update", NG_PLUGIN_FUNCTION(part_progress_update), data);
                 | 
              
| 503 | 
                      ng_plugin_connect_event(plugin_data, "collection_added", NG_PLUGIN_FUNCTION(collection_added), data);
                 | 
              
| 504 | 
                      ng_plugin_connect_event(plugin_data, "collection_removed", NG_PLUGIN_FUNCTION(collection_removed), data);
                 | 
              
| 505 | 
                      ng_plugin_connect_event(plugin_data, "collection_modified", NG_PLUGIN_FUNCTION(collection_modified), data);
                 | 
              
| 506 | 
                      ng_plugin_connect_event(plugin_data, "file_added", NG_PLUGIN_FUNCTION(file_added), data);
                 | 
              
| 507 | 
                      ng_plugin_connect_event(plugin_data, "file_removed", NG_PLUGIN_FUNCTION(file_removed), data);
                 | 
              
| 508 | 
                      ng_plugin_connect_event(plugin_data, "file_download_state_update", NG_PLUGIN_FUNCTION(file_download_state_update), data);
                 | 
              
| 509 | 
                      ng_plugin_connect_event(plugin_data, "file_state_changed", NG_PLUGIN_FUNCTION(file_state_changed), data);
                 | 
              
| 510 | 
                      ng_plugin_connect_event(plugin_data, "connection_connecting", NG_PLUGIN_FUNCTION(connection_connecting), data);
                 | 
              
| 511 | 
                      ng_plugin_connect_event(plugin_data, "connection_connected", NG_PLUGIN_FUNCTION(connection_connected), data);
                 | 
              
| 512 | 
                      ng_plugin_connect_event(plugin_data, "connection_disconnect", NG_PLUGIN_FUNCTION(connection_disconnect), data);
                 | 
              
| 513 | 
                      ng_plugin_connect_event(plugin_data, "schedular_state_changed", NG_PLUGIN_FUNCTION(schedular_state_changed), data);
                 | 
              
| 514 | 
                      ng_plugin_connect_event(plugin_data, "log_message", NG_PLUGIN_FUNCTION(log_message), data);
                 | 
              
| 515 | 
                      ng_plugin_connect_event(plugin_data, "task_moved", NG_PLUGIN_FUNCTION(task_moved), data);
                 | 
              
| 516 | 
                      ng_plugin_connect_event(plugin_data, "collection_moved", NG_PLUGIN_FUNCTION(collection_moved), data);
                 | 
              
| 517 | 
                      ng_plugin_connect_event(plugin_data, "all_downloads_completed", NG_PLUGIN_FUNCTION(all_downloads_completed), data);
                 | 
              
| 518 | 
                      ng_plugin_connect_event(plugin_data, "plugin_loaded", NG_PLUGIN_FUNCTION(plugin_loaded), data);
                 | 
              
| 519 | 
                      ng_plugin_connect_event(plugin_data, "plugin_unloaded", NG_PLUGIN_FUNCTION(plugin_unloaded), data);
                 | 
              
| 520 | 
                      ng_plugin_connect_event(plugin_data, "plugin_event", NG_PLUGIN_FUNCTION(plugin_event), data);
                 | 
              
| 521 | 
                  }  | 
              
| 522 | 
                   | 
              
| 523 | 
                  void
                 | 
              
| 524 | 
                  jsonrpc_disconnect_signal_handlers(NGPlugin *plugin_data)  | 
              
| 525 | 
                  {
                 | 
              
| 526 | 
                      gpointer data = NULL;
                 | 
              
| 527 | 
                   | 
              
| 528 | 
                  ng_plugin_disconnect_event_by_func(plugin_data, NG_PLUGIN_FUNCTION(config_changed), data);  | 
              
| 529 | 
                  ng_plugin_disconnect_event_by_func(plugin_data, NG_PLUGIN_FUNCTION(part_download_start), data);  | 
              
| 530 | 
                  ng_plugin_disconnect_event_by_func(plugin_data, NG_PLUGIN_FUNCTION(part_done), data);  | 
              
| 531 | 
                  ng_plugin_disconnect_event_by_func(plugin_data, NG_PLUGIN_FUNCTION(part_failed), data);  | 
              
| 532 | 
                  ng_plugin_disconnect_event_by_func(plugin_data, NG_PLUGIN_FUNCTION(traffic_monitor_update), data);  | 
              
| 533 | 
                  ng_plugin_disconnect_event_by_func(plugin_data, NG_PLUGIN_FUNCTION(part_progress_update), data);  | 
              
| 534 | 
                  ng_plugin_disconnect_event_by_func(plugin_data, NG_PLUGIN_FUNCTION(collection_added), data);  | 
              
| 535 | 
                  ng_plugin_disconnect_event_by_func(plugin_data, NG_PLUGIN_FUNCTION(collection_removed), data);  | 
              
| 536 | 
                  ng_plugin_disconnect_event_by_func(plugin_data, NG_PLUGIN_FUNCTION(collection_modified), data);  | 
              
| 537 | 
                  ng_plugin_disconnect_event_by_func(plugin_data, NG_PLUGIN_FUNCTION(file_added), data);  | 
              
| 538 | 
                  ng_plugin_disconnect_event_by_func(plugin_data, NG_PLUGIN_FUNCTION(file_removed), data);  | 
              
| 539 | 
                  ng_plugin_disconnect_event_by_func(plugin_data, NG_PLUGIN_FUNCTION(file_download_state_update), data);  | 
              
| 540 | 
                  ng_plugin_disconnect_event_by_func(plugin_data, NG_PLUGIN_FUNCTION(file_state_changed), data);  | 
              
| 541 | 
                  ng_plugin_disconnect_event_by_func(plugin_data, NG_PLUGIN_FUNCTION(connection_connecting), data);  | 
              
| 542 | 
                  ng_plugin_disconnect_event_by_func(plugin_data, NG_PLUGIN_FUNCTION(connection_connected), data);  | 
              
| 543 | 
                  ng_plugin_disconnect_event_by_func(plugin_data, NG_PLUGIN_FUNCTION(connection_disconnect), data);  | 
              
| 544 | 
                  ng_plugin_disconnect_event_by_func(plugin_data, NG_PLUGIN_FUNCTION(schedular_state_changed), data);  | 
              
| 545 | 
                  ng_plugin_disconnect_event_by_func(plugin_data, NG_PLUGIN_FUNCTION(log_message), data);  | 
              
| 546 | 
                  ng_plugin_disconnect_event_by_func(plugin_data, NG_PLUGIN_FUNCTION(task_moved), data);  | 
              
| 547 | 
                  ng_plugin_disconnect_event_by_func(plugin_data, NG_PLUGIN_FUNCTION(collection_moved), data);  | 
              
| 548 | 
                  ng_plugin_disconnect_event_by_func(plugin_data, NG_PLUGIN_FUNCTION(all_downloads_completed), data);  | 
              
| 549 | 
                  ng_plugin_disconnect_event_by_func(plugin_data, NG_PLUGIN_FUNCTION(plugin_loaded), data);  | 
              
| 550 | 
                  ng_plugin_disconnect_event_by_func(plugin_data, NG_PLUGIN_FUNCTION(plugin_unloaded), data);  | 
              
| 551 | 
                  ng_plugin_disconnect_event_by_func(plugin_data, NG_PLUGIN_FUNCTION(plugin_event), data);  | 
              
| 552 | 
                  }  | 
              
NNTPGrab

