modules/nt/notification.cc
/* [<][>][^][v][top][bottom][index][help] */
FUNCTIONS
This source file includes following functions.
- NT_ntfy_filename_generate
- NT_forwd_filename_generate
- NT_cross_filename_generate
- NT_crossntfy_filename_generate
- NT_add_to_ntfy_hash
- NT_add_to_frwd_hash
- NT_add_to_cross_hash
- NT_add_to_ntfy_hash_list
- NT_add_to_frwd_hash_list
- NT_add_to_cross_hash_list
- NT_add_to_ntfy
- NT_add_to_cross
- NT_add_to_ntfy_list
- NT_send_ntfy
- NT_log_ntfy
- NT_delete_ntfy
- nt_gfunc_send
- NT_send_ntfy_list
- nt_gfunc_log
- NT_log_ntfy_list
- nt_gfunc_delete
- NT_delete_ntfy_list
- NT_gather_ntfy_addresses
- NT_gather_frwd_addresses
- get_overlapping_routes_list
- NT_write_all_ntfs
- NT_write_all_frwds
1 /***************************************
2 $Revision: 1.11 $
3
4 NT (Notifications) module
5
6 Status: NOT REVIEWED, NOT TESTED
7
8 Author(s): Engin Gunduz
9
10 ******************/ /******************
11 Modification History:
12 engin (06/07/2000) Created.
13 ******************/ /******************
14 Copyright (c) 2000 RIPE NCC
15
16 All Rights Reserved
17
18 Permission to use, copy, modify, and distribute this software and its
19 documentation for any purpose and without fee is hereby granted,
20 provided that the above copyright notice appear in all copies and that
21 both that copyright notice and this permission notice appear in
22 supporting documentation, and that the name of the author not be
23 used in advertising or publicity pertaining to distribution of the
24 software without specific, written prior permission.
25
26 THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
27 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
28 AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
29 DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
30 AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
31 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
32 ***************************************/
33
34
35
36
37
38
39 #include "notification.h"
40 extern int supress_ack_notif;
41 extern char * defmail;
42
43 /* Generates a unique file name and returns the full path of the filename
44 for storing notification message. Creates the file at the same time.
45 May use PID or time or both to ensure uniqueness. */
46
47 char * NT_ntfy_filename_generate( const char * tmpdir, const char * e_mail){
/* [<][>][^][v][top][bottom][index][help] */
48
49 FILE * ntfy_file;
50 char * name;
51
52 /* allocate space for name. 32 should be enough for PID */
53 name = (char*)malloc(strlen(tmpdir) + strlen(e_mail) + strlen("notify") +32 );
54
55 sprintf(name, "%s/%s-%s.%i", tmpdir, "notify", e_mail, getpid());
56
57 /* create the file */
58 if(( ntfy_file = fopen(name, "w")) == NULL){
59 fprintf(stderr, "Can't open notification file for creating, %s", name);
60 }
61
62 fprintf(ntfy_file, "To: %s\nFrom: %s\nSubject: Notification of RIPE Database changes\nReply-To: %s\n\n%s\n", e_mail, humailbox, humailbox, notitxt);
63 if(reading_from_mail){
64 fprintf(ntfy_file, "%s\n\n", notimailtxt);
65 }
66 /* close it */
67 fclose(ntfy_file);
68
69 return name;
70
71 }
72
73
74
75
76
77 /* Generates a unique file name and returns the full path of the filename
78 for storing forwarded message. Creates the file at the same time. */
79 char * NT_forwd_filename_generate( const char * tmpdir, const char * e_mail){
/* [<][>][^][v][top][bottom][index][help] */
80
81 FILE * forwd_file;
82 char * name;
83
84 /* allocate space for name. 32 should be enough for PID */
85 name = (char*)malloc(strlen(tmpdir) + strlen(e_mail) + strlen("forwd") +32 );
86
87 sprintf(name, "%s/%s-%s.%i", tmpdir, "forwd", e_mail, getpid());
88 //printf("DEBUG: NT_forwd_filename_generate: will generate %s\n", name);
89 /* create the file */
90 if(( forwd_file = fopen(name, "w")) == NULL){
91 fprintf(stderr, "Can't open forward file, %s", name);
92 }
93
94 fprintf(forwd_file, "To: %s\nFrom: %s\nSubject: Requested RIPE database object changes \nReply-To: %s\n\n%s\n", e_mail, humailbox, humailbox, fwtxt);
95 if(reading_from_mail){
96 fprintf(forwd_file, "\n%s\n", fwmailtxt);
97 }
98
99 /* close it */
100 fclose(forwd_file);
101
102 return name;
103
104 }
105
106
107
108
109
110 /* Generates a unique file name and returns the full path of the filename
111 for storing cross notification message. Creates the file at the same time. */
112 char * NT_cross_filename_generate( const char * tmpdir, const char * e_mail, int mode){
/* [<][>][^][v][top][bottom][index][help] */
113
114 FILE * cross_file;
115 char * name;
116
117 /* allocate space for name. 32 should be enough for PID */
118 name = (char*)malloc(strlen(tmpdir) + strlen(e_mail) + strlen("cross") +32 );
119
120 sprintf(name, "%s/%s-%s.%i", tmpdir, "cross", e_mail, getpid());
121 //printf("DEBUG: NT_cross_filename_generate: will generate %s\n", name);
122 /* create the file */
123 if(( cross_file = fopen(name, "w")) == NULL){
124 fprintf(stderr, "Can't open cross notif file, %s", name);
125 }
126
127 //printf("DEBUG: NT_cross_filename_generate: e_mail=[%s], humailbox=[%s]\n", e_mail, humailbox);
128 if(mode == ADDITION){
129 fprintf(cross_file, "To: %s\nFrom: %s\n%s\nReply-To: %s\n\n", e_mail, humailbox, cno_subject_add, humailbox);
130 }else{
131 fprintf(cross_file, "To: %s\nFrom: %s\n%s\nReply-To: %s\n\n", e_mail, humailbox, cno_subject_del, humailbox);
132 }
133
134 /* close it */
135 fclose(cross_file);
136
137 return name;
138
139 }
140
141
142
143
144
145
146
147 /* Generates a unique file name and returns the full path of the filename for
148 storing notification message. Creates the file at the same time. */
149 char * NT_crossntfy_filename_generate( const char * tmpdir, const char * e_mail){
/* [<][>][^][v][top][bottom][index][help] */
150 FILE * cross_file;
151 char * name;
152
153 /* allocate space for name. 32 should be enough for PID */
154 name = (char*)malloc(strlen(tmpdir) + strlen(e_mail) + strlen("cross") +32 );
155
156 sprintf(name, "%s/%s-%s.%i", tmpdir, "cross", e_mail, getpid());
157
158 /* create the file */
159 if(( cross_file = fopen(name, "w")) == NULL){
160 fprintf(stderr, "Can't open cross file, %s", name);
161 }
162
163 /* close it */
164 fclose(cross_file);
165
166 return name;
167
168 }
169
170
171
172
173
174 /* Adds the e-mail to the notify hash, generating appropriate temp files */
175 void NT_add_to_ntfy_hash(GHashTable * ntfy_hash, char * e_mail){
/* [<][>][^][v][top][bottom][index][help] */
176
177 if(g_hash_table_lookup(ntfy_hash ,e_mail) == NULL){/* there is no such entry, so create it */
178 g_hash_table_insert(ntfy_hash, strdup(e_mail), NT_ntfy_filename_generate(tmpdir, e_mail));
179 }
180
181 }
182
183
184
185
186 /* Adds the e-mail to the forw hash, generating appropriate temp files */
187 void NT_add_to_frwd_hash(GHashTable * frwd_hash, char * e_mail){
/* [<][>][^][v][top][bottom][index][help] */
188
189 if(g_hash_table_lookup(frwd_hash ,e_mail) == NULL){/* there is no such entry, so create it */
190 g_hash_table_insert(frwd_hash, strdup(e_mail), NT_forwd_filename_generate(tmpdir, e_mail));
191 }
192
193 }
194
195
196
197
198
199 /* Adds the e-mail to the cross hash, generating appropriate temp files */
200 void NT_add_to_cross_hash(GHashTable * cross_hash, const char * e_mail, int mode){
/* [<][>][^][v][top][bottom][index][help] */
201
202 if(g_hash_table_lookup(cross_hash ,e_mail) == NULL){/* there is no such entry, so create it */
203 g_hash_table_insert(cross_hash, strdup(e_mail), NT_cross_filename_generate(tmpdir, e_mail, mode));
204 }
205
206 }
207
208
209
210
211
212 /* Adds the e-mails in a linked list to the hash */
213 void NT_add_to_ntfy_hash_list(GHashTable * ntfy_hash, GSList * e_mail_list){
/* [<][>][^][v][top][bottom][index][help] */
214
215 GSList * temp = NULL;
216
217 for(temp = e_mail_list; temp != NULL; temp = g_slist_next(temp)){
218 NT_add_to_ntfy_hash(ntfy_hash, (char *)temp->data);
219 }
220
221 }
222
223
224
225
226 /* Adds the e-mails in a linked list to the hash */
227 void NT_add_to_frwd_hash_list(GHashTable * frwd_hash, GSList * e_mail_list){
/* [<][>][^][v][top][bottom][index][help] */
228
229 GSList * temp = NULL;
230
231 for(temp = e_mail_list; temp != NULL; temp = g_slist_next(temp)){
232 NT_add_to_frwd_hash(frwd_hash, (char *)temp->data);
233 }
234
235 }
236
237
238
239 /* Adds the e-mails in a linked list to the hash */
240 void NT_add_to_cross_hash_list(GHashTable * cross_hash, GSList * e_mail_list, int mode){
/* [<][>][^][v][top][bottom][index][help] */
241
242 GSList * temp = NULL;
243
244 for(temp = e_mail_list; temp != NULL; temp = g_slist_next(temp)){
245 NT_add_to_cross_hash(cross_hash, (char *)temp->data, mode);
246 }
247
248 }
249
250
251
252
253
254
255 /* Appends the argument strings to the file. */
256 void NT_add_to_ntfy( char * filename, char * fmt, ... ){
/* [<][>][^][v][top][bottom][index][help] */
257 va_list ap; /* points to each unnamed arg in turn */
258 FILE * ntfy_file;
259
260 if(tracing){
261 printf("TRACING: NT_add_to_ntfy\n");
262 }
263 if(( ntfy_file = fopen(filename, "a")) == NULL){
264 fprintf(stderr, "Can't open notification file for writing, %s\n", filename);
265 return;
266 }
267
268 va_start(ap, fmt);
269 vfprintf(ntfy_file, fmt, ap);
270
271 va_end(ap); /* clean up */
272 fclose(ntfy_file);
273 }
274
275
276
277 /* Appends the argument strings to the file. */
278 void NT_add_to_cross(const char * e_mail, GHashTable * hash, char * fmt, ...){
/* [<][>][^][v][top][bottom][index][help] */
279 //va_list ap; /* points to each unnamed arg in turn */
280 //FILE * cross_file;
281
282 //if(tracing){
283 // printf("TRACING: NT_add_to_cross\n");
284 //}
285 //if(( ack_file = fopen(filename, "a")) == NULL){
286 // fprintf(stderr, "Can't open cross notification file, %s\n", filename);
287 //}
288
289 //va_start(ap, fmt);
290 //vfprintf(ack_file, fmt, ap);
291
292 //va_end(ap); /* clean up */
293 //fclose(ack_file);
294
295 //printf("DEBUG: NT_add_to_cross: will now call NT_add_to_ntfy: e_mail=[%s], arg=[%s]\n", e_mail, arg);
296 //NT_add_to_ntfy((char *)g_hash_table_lookup(hash, find_email_address(e_mail)), arg);
297
298 va_list ap; /* points to each unnamed arg in turn */
299 FILE * cross_file;
300 char * filename;
301
302 if(g_hash_table_lookup(hash, find_email_address(e_mail)) != NULL){
303 filename = (char *)g_hash_table_lookup(hash, find_email_address(e_mail));
304 }else{
305 fprintf(stderr, "Can't find a cross notification file for e-mail %s\n", e_mail);
306 return;
307 }
308
309 if(( cross_file = fopen(filename, "a")) == NULL){
310 fprintf(stderr, "Can't open cross notification file, %s\n", filename);
311 }
312
313
314
315 if(tracing){
316 printf("TRACING: NT_add_to_cross\n");
317 }
318 if(( cross_file = fopen(filename, "a")) == NULL){
319 fprintf(stderr, "Can't open cross notification file for writing, %s\n", filename);
320 }
321
322 va_start(ap, fmt);
323 vfprintf(cross_file, fmt, ap);
324
325 va_end(ap); /* clean up */
326 fclose(cross_file);
327
328
329 }
330
331
332
333
334
335 /* Appends the argument string to the temp notif files in the list */
336 void NT_add_to_ntfy_list(GSList * list, GHashTable * hash, char * arg){
/* [<][>][^][v][top][bottom][index][help] */
337
338 GSList * temp = NULL;
339
340 for(temp = list; temp != NULL; temp = g_slist_next(temp)){
341 NT_add_to_ntfy((char *)g_hash_table_lookup(hash, ((char *)temp->data)), arg);
342 }
343 }
344
345
346
347
348
349
350
351
352 /* Sends the notification message which is stored in the temporary filefilename. */
353 void NT_send_ntfy( const char * filename, const char * to_address, const char * mailercommand){
/* [<][>][^][v][top][bottom][index][help] */
354
355 char * mail_command_line = NULL;
356 char * supress_file = NULL;
357 FILE * notif_file, * supr_file_hdl;
358 char buf[1024];
359
360
361 /* if we are not supressing acks and notifs, send the notif */
362 if(!supress_ack_notif){
363 if(to_address != NULL){
364 mail_command_line = (char *)malloc(strlen(mailercommand) + strlen(filename) + 128);
365 sprintf(mail_command_line, "%s %s < %s", mailercommand, to_address, filename);
366 system(mail_command_line);
367 }
368 /* if we are supressing acks and notifs, send notif to DEFMAIL */
369 }else{
370 supress_file = (char *)malloc(strlen(filename) + strlen(".supress") + 2);
371 sprintf(supress_file, "%s.supress", filename);
372 if(( supr_file_hdl = fopen(supress_file, "w")) == NULL){
373 fprintf(stderr, "Can't open supress notif file, %s", supress_file);
374 }else{
375 fprintf(supr_file_hdl, "From: %s\nTo: %s\nSubject: Supressed notif mail\n\n",
376 humailbox, defmail);
377 if(( notif_file = fopen(filename, "r")) == NULL){
378 fprintf(stderr, "Can't open notif file for reading, %s", filename);
379 }else{
380 while(fgets(buf, 1024, notif_file) != NULL){
381 fprintf(supr_file_hdl, buf);
382 }
383 fclose(notif_file);
384 }
385 }
386 fclose(supr_file_hdl);
387 mail_command_line = (char *)malloc(strlen(mailercommand) + strlen(defmail)
388 + strlen(supress_file) + 128);
389 sprintf(mail_command_line, "%s %s < %s", mailercommand, defmail, supress_file);
390 system(mail_command_line);
391 unlink(supress_file);
392 free(supress_file);
393 }
394
395
396 }
397
398
399
400 /* Adds the notification message which is in the filename into log_file. */
401 void NT_log_ntfy( const char * filename, const char * logfilename){
/* [<][>][^][v][top][bottom][index][help] */
402
403 FILE * notif_file, * log_file;
404 char * buf;
405 time_t cur_time;
406 char * time_str;
407
408 buf = (char *)malloc(1024);
409 if(( notif_file = fopen(filename, "r")) == NULL){
410 fprintf(stderr, "Can't open notification file for reading, [%s]\n", filename);
411 return;
412 }
413
414 if(( log_file = fopen(logfilename, "a")) == NULL){
415 fprintf(stderr, "Can't open log file, %s\n", logfilename);
416 return;
417 }
418
419 /* get time */
420 cur_time = time(NULL);
421 time_str = strdup(ctime(&cur_time));
422 /* cut the '\n' at the end */
423 time_str[strlen(time_str) - 1] = '\0';
424
425 fprintf(log_file, ">>> time: %s NOTIF <<<\n\n", time_str);
426
427
428 while((buf=fgets(buf, 1023, notif_file)) > 0){
429 fprintf(log_file, "%s", buf);
430 }
431
432 fclose(notif_file);
433 fclose(log_file);
434
435 }
436
437
438 /* Deletes the temporary notification file. */
439 void NT_delete_ntfy( const char * filename){
/* [<][>][^][v][top][bottom][index][help] */
440
441 unlink(filename);
442
443 }
444
445
446 /* The function required for NT_send_ntfy_list */
447 void nt_gfunc_send(gpointer key, gpointer value, gpointer user_data){
/* [<][>][^][v][top][bottom][index][help] */
448 NT_send_ntfy((char *)value, (char *)key, (char *)user_data);
449 }
450
451
452
453 /* Sends the notification messages whose temp files are stored in filehash. */
454 void NT_send_ntfy_list( GHashTable * filehash, char * mailercommand){
/* [<][>][^][v][top][bottom][index][help] */
455
456 g_hash_table_foreach( filehash, (GHFunc)nt_gfunc_send, mailercommand);
457
458 }
459
460
461
462
463 /* The function required for NT_log_ntfy_list */
464 void nt_gfunc_log(gpointer key, gpointer value, gpointer user_data){
/* [<][>][^][v][top][bottom][index][help] */
465 NT_log_ntfy((char *)value, (char *)user_data);
466 }
467
468
469
470
471 /* Logs the notification whose temp files are in filehash to log_file. */
472 void NT_log_ntfy_list( GHashTable * filehash, char * log_file){
/* [<][>][^][v][top][bottom][index][help] */
473
474 g_hash_table_foreach( filehash, (GHFunc)nt_gfunc_log, log_file);
475
476 }
477
478
479
480 /* The function required for NT_delete_ntfy_list */
481 void nt_gfunc_delete(gpointer key, gpointer value, gpointer user_data){
/* [<][>][^][v][top][bottom][index][help] */
482 NT_delete_ntfy((char *)value);
483 }
484
485
486
487 /* Deletes the temporary notification messages in the filehash. Empties and frees
488 the hash too. */
489 void NT_delete_ntfy_list( GHashTable * filehash){
/* [<][>][^][v][top][bottom][index][help] */
490
491 g_hash_table_foreach(filehash, (GHFunc)nt_gfunc_delete, NULL);
492 g_hash_table_destroy(filehash);
493
494 }
495
496
497 /* Gathers e-mail boxes to which we will send normal notification messages. It
498 takes old and new objects, looks up maintainers and less specific inetnums/domains/routes
499 when necessary, finds the addresses (in mnt-nfy and notify attributes) and returns
500 a list of them. */
501 GSList * NT_gather_ntfy_addresses( char * old_object, char * new_object){
/* [<][>][^][v][top][bottom][index][help] */
502 GSList *temp = NULL;
503 GSList * mntners = NULL;
504
505 if(old_object != NULL && new_object != NULL){/* it was an update */
506 temp = get_attr_list(old_object, "notify");
507 mntners = get_mntners(old_object);
508 temp = g_slist_concat(temp, get_mntnfy_vector(mntners));
509 }else if(old_object == NULL && new_object != NULL){/* it was a creation */
510 temp = get_attr_list(new_object, "notify");
511 mntners = get_mntners(new_object);
512 temp = g_slist_concat(temp, get_mntnfy_vector(mntners));
513 }else if(old_object != NULL && new_object == NULL){/* it was a deletion */
514 temp = get_attr_list(old_object, "notify");
515 mntners = get_mntners(old_object);
516 temp = g_slist_concat(temp, get_mntnfy_vector(mntners));
517 }
518 return temp;
519 }
520
521
522
523 /* Gathers e-mail boxes to which we will forward messages (or rather, objects). It
524 an object, looks up maintainers, finds the addresses (in upd-to attributes) and returns
525 a list of them. */
526 GSList * NT_gather_frwd_addresses(char * object){
/* [<][>][^][v][top][bottom][index][help] */
527 GSList *temp = NULL;
528 GSList * mntners = NULL;
529
530 mntners = get_mntners(object);
531 temp = get_updto_vector(mntners);
532 return temp;
533 }
534
535
536
537
538 /* Accepts a route object as a "* char" and returns a list of overlapping routes */
539 overlap_routes get_overlapping_routes_list(char * object){
/* [<][>][^][v][top][bottom][index][help] */
540
541 char * route_prefix = NULL;
542 GSList * tmp_list;
543 char * result;
544 char * query_string;
545 overlap_routes result_routes;
546
547 result_routes.less_spec = NULL;
548 result_routes.exact_match = NULL;
549 result_routes.more_spec = NULL;
550
551 tmp_list = get_attr_list(object, "route");
552
553 if(tmp_list != NULL && tmp_list->data != NULL){
554 route_prefix = strdup((char *)(tmp_list->data));
555 }else{
556 return result_routes; /* then, this wasn't a route object */
557 }
558
559 /* get the less specific route objects */
560 /* form the query string */
561 query_string = (char *)malloc(strlen("-Troute -r -L ") + strlen(route_prefix) + 2);
562 sprintf(query_string, "-Troute -r -L %s", route_prefix);
563
564 /* get the results */
565 result = send_and_get(query_host, query_port, query_string);
566 free(query_string);
567
568 /* and fill in the result field */
569 result_routes.less_spec = take_objects(result);
570
571 /* get the exact match route objects */
572 /* form the query string */
573 query_string = (char *)malloc(strlen("-Troute -r -x ") + strlen(route_prefix) + 2);
574 sprintf(query_string, "-Troute -r -x %s", route_prefix);
575
576 /* get the results */
577 result = send_and_get(query_host, query_port, query_string);
578 free(query_string);
579
580 /* and fill in the result field */
581 result_routes.exact_match = take_objects(result);
582
583 /* get the more specific route objects */
584 /* form the query string */
585 query_string = (char *)malloc(strlen("-Troute -r -M ") + strlen(route_prefix) + 2);
586 sprintf(query_string, "-Troute -r -M %s", route_prefix);
587
588 /* get the results */
589 result = send_and_get(query_host, query_port, query_string);
590 free(query_string);
591
592 /* and fill in the result field */
593 result_routes.more_spec = take_objects(result);
594
595 /* Return the results */
596 return result_routes;
597
598 }
599
600
601
602
603
604 /* Gets old and new versions of the object, and creates temporary notification
605 files when necessary, and then writes appropriate strings into those
606 temporary files. */
607 void NT_write_all_ntfs(char * old_object, char * new_object, /*const char * notif_log,
/* [<][>][^][v][top][bottom][index][help] */
608 const char * forw_log, const char * cross_log,*/ const char * tempdir,
609 GHashTable * ntfy_hash, GHashTable * forwd_hash, GHashTable * cross_hash,
610 char * from_address){
611
612 GSList * e_mail_list = NULL;
613 //GSList * cross_route_list = NULL;
614 GSList * temp = NULL;
615 char * e_mail_address;
616 overlap_routes overlapping_routes;
617
618 /* from_address may contain also the name, like "Johnny Bravo <johnny@inter.net>",
619 so extract the e-mail address from it */
620 e_mail_address = find_email_address(from_address);
621
622
623 if(tracing){
624 printf("TRACING: NT_write_all_ntfs: from_address=[%s], e_mail_address=[%s]\n", from_address, e_mail_address);
625 }
626 if(old_object != NULL && new_object != NULL){/* it was an update */
627 e_mail_list = NT_gather_ntfy_addresses(old_object, new_object);
628 NT_add_to_ntfy_hash_list(ntfy_hash, e_mail_list);
629 NT_add_to_ntfy_list(e_mail_list, ntfy_hash, "---\nPREVIOUS OBJECT:\n\n");
630 NT_add_to_ntfy_list(e_mail_list, ntfy_hash, old_object);
631 NT_add_to_ntfy_list(e_mail_list, ntfy_hash, "\n\nREPLACED BY:\n\n");
632 NT_add_to_ntfy_list(e_mail_list, ntfy_hash, new_object);
633 NT_add_to_ntfy_list(e_mail_list, ntfy_hash, "\n");
634 }else if(old_object == NULL && new_object != NULL){/* it was a creation */
635 e_mail_list = NT_gather_ntfy_addresses(old_object, new_object);
636 NT_add_to_ntfy_hash_list(ntfy_hash, e_mail_list);
637 NT_add_to_ntfy_list(e_mail_list, ntfy_hash, "---\nOBJECT BELOW CREATED:\n\n");
638 NT_add_to_ntfy_list(e_mail_list, ntfy_hash, new_object);
639 NT_add_to_ntfy_list(e_mail_list, ntfy_hash, "\n");
640 /* We'll deal with cross notifications only when we create or delete route objects */
641 if(strcmp(get_class_type_char(new_object), "route") == 0){
642 NT_add_to_cross_hash(cross_hash, e_mail_address, ADDITION);
643 overlapping_routes = get_overlapping_routes_list(new_object);
644 if(overlapping_routes.less_spec != NULL || overlapping_routes.exact_match != NULL ||
645 overlapping_routes.more_spec != NULL ){
646 //printf("DEBUG: NT_write_all_ntfs: e_mail_address=[%s]\n", e_mail_address);
647 NT_add_to_cross(e_mail_address, cross_hash, "%s\n\n%s\n\n%s\n\n", cno_explain_add, new_object, cno_overlap_add);
648 if(overlapping_routes.less_spec != NULL){
649 NT_add_to_cross(from_address, cross_hash, "LESS SPECIFIC MATCHES\n\n");
650 for(temp = overlapping_routes.less_spec; temp != NULL; temp = g_slist_next(temp)){
651 NT_add_to_cross(from_address, cross_hash, "%s\n\n", (char *)temp->data);
652 }
653 }
654 if(overlapping_routes.exact_match != NULL){
655 NT_add_to_cross(from_address, cross_hash, "EXACT MATCHES\n\n");
656 for(temp = overlapping_routes.exact_match; temp != NULL; temp = g_slist_next(temp)){
657 NT_add_to_cross(from_address, cross_hash, "%s\n\n", (char *)temp->data);
658 }
659 }
660 if(overlapping_routes.more_spec != NULL){
661 NT_add_to_cross(from_address, cross_hash, "MORE SPECIFIC MATCHES\n\n");
662 for(temp = overlapping_routes.more_spec; temp != NULL; temp = g_slist_next(temp)){
663 NT_add_to_cross(from_address, cross_hash, "%s\n\n", (char *)temp->data);
664 }
665 }
666 }
667 }
668 }else if(old_object != NULL && new_object == NULL){/* it was a deletion */
669 old_object = delete_delete_attrib(old_object);
670 e_mail_list = NT_gather_ntfy_addresses(old_object, new_object);
671 NT_add_to_ntfy_hash_list(ntfy_hash, e_mail_list);
672 NT_add_to_ntfy_list(e_mail_list, ntfy_hash, "---\nOBJECT BELOW DELETED:\n\n");
673 NT_add_to_ntfy_list(e_mail_list, ntfy_hash, old_object);
674 NT_add_to_ntfy_list(e_mail_list, ntfy_hash, "\n");
675 /* We'll deal with cross notifications only when we create or delete route objects */
676 if(strcmp(get_class_type_char(old_object), "route") == 0){
677 NT_add_to_cross_hash(cross_hash, e_mail_address, DELETION);
678 overlapping_routes = get_overlapping_routes_list(old_object);
679 if(overlapping_routes.less_spec != NULL || overlapping_routes.exact_match != NULL ||
680 overlapping_routes.more_spec != NULL ){
681 //printf("DEBUG: NT_write_all_ntfs: e_mail_address=[%s]\n", e_mail_address);
682 NT_add_to_cross(e_mail_address, cross_hash, "%s\n\n%s\n\n%s\n\n", cno_explain_del, old_object, cno_overlap_del);
683 if(overlapping_routes.less_spec != NULL){
684 NT_add_to_cross(from_address, cross_hash, "LESS SPECIFIC MATCHES\n\n");
685 for(temp = overlapping_routes.less_spec; temp != NULL; temp = g_slist_next(temp)){
686 NT_add_to_cross(from_address, cross_hash, "%s\n\n", (char *)temp->data);
687 }
688 }
689 if(overlapping_routes.exact_match != NULL){
690 NT_add_to_cross(from_address, cross_hash, "EXACT MATCHES\n\n");
691 for(temp = overlapping_routes.exact_match; temp != NULL; temp = g_slist_next(temp)){
692 NT_add_to_cross(from_address, cross_hash, "%s\n\n", (char *)temp->data);
693 }
694 }
695 if(overlapping_routes.more_spec != NULL){
696 NT_add_to_cross(from_address, cross_hash, "MORE SPECIFIC MATCHES\n\n");
697 for(temp = overlapping_routes.more_spec; temp != NULL; temp = g_slist_next(temp)){
698 NT_add_to_cross(from_address, cross_hash, "%s\n\n", (char *)temp->data);
699 }
700 }
701 }
702 }
703 }
704 }
705
706
707
708
709
710 /* Gets old and new versions of the object, and creates temporary notification
711 files when necessary, and then writes appropriate strings into those
712 temporary files. */
713 void NT_write_all_frwds(char * old_object, char * new_object, /*const char * notif_log,
/* [<][>][^][v][top][bottom][index][help] */
714 const char * forw_log, const char * cross_log,*/ const char * tempdir,
715 GHashTable * ntfy_hash, GHashTable * forwd_hash, GHashTable * cross_hash,
716 const char * from_address){
717
718 GSList * e_mail_list = NULL;
719
720
721 if(tracing){
722 printf("TRACING: NT_write_all_frwds\n");
723 }
724 if(old_object != NULL && new_object != NULL){/* it was an update */
725 e_mail_list = NT_gather_frwd_addresses(old_object);
726 NT_add_to_frwd_hash_list(forwd_hash, e_mail_list);
727 NT_add_to_ntfy_list(e_mail_list, forwd_hash, "----\nUPDATE REQUESTED FOR:\n\n");
728 //NT_add_to_ntfy_list(e_mail_list, forwd_hash, old_object);
729 //NT_add_to_ntfy_list(e_mail_list, forwd_hash, "\n\n");
730 NT_add_to_ntfy_list(e_mail_list, forwd_hash, new_object);
731 }else if(old_object == NULL && new_object != NULL){/* it was a creation */
732 e_mail_list = NT_gather_frwd_addresses(new_object);
733 NT_add_to_frwd_hash_list(forwd_hash, e_mail_list);
734 NT_add_to_ntfy_list(e_mail_list, forwd_hash, "----\nADDITION REQUESTED FOR:\n\n");
735 NT_add_to_ntfy_list(e_mail_list, forwd_hash, new_object);
736 }else if(old_object != NULL && new_object == NULL){/* it was a deletion */
737 e_mail_list = NT_gather_frwd_addresses(old_object);
738 NT_add_to_frwd_hash_list(forwd_hash, e_mail_list);
739 NT_add_to_ntfy_list(e_mail_list, forwd_hash, "----\nDELETION REQUESTED FOR:\n\n");
740 NT_add_to_ntfy_list(e_mail_list, forwd_hash, old_object);
741 }
742 }
743