summaryrefslogtreecommitdiff
path: root/src/events.c
blob: 4fc7a990fb132731821f06f72268908588b66069 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
/* Events functions.
 *
 * (C) 2004-2011 Anope Team
 * Contact us at team@anope.org
 *
 * Please read COPYING and README for further details.
 *
 * Based on the original code of Epona by Lara.
 * Based on the original code of Services by Andy Church. 
 * 
 *
 */

#include "modules.h"
#include "language.h"
#include "version.h"

char *mod_current_evtbuffer = NULL;

EvtMessageHash *EVENT[MAX_CMD_HASH];
EvtHookHash *EVENTHOOKS[MAX_CMD_HASH];

EvtMessage *find_event(const char *name)
{
    EvtMessage *m;
    m = findEventHandler(EVENT, name);
    return m;
}

EvtHook *find_eventhook(const char *name)
{
    EvtHook *m;
    m = findEventHook(EVENTHOOKS, name);
    return m;
}

void send_event(const char *name, int argc, ...)
{
    va_list va;
    char *a;
    int idx = 0;
    char **argv;

    argv = (char **) malloc(sizeof(char *) * argc);
    va_start(va, argc);
    for (idx = 0; idx < argc; idx++) {
        a = va_arg(va, char *);
        argv[idx] = sstrdup(a);
    }
    va_end(va);

    if (debug)
        alog("debug: Emitting event \"%s\" (%d args)", name, argc);

    event_process_hook(name, argc, argv);

    /**
     * Now that the events have seen the message, free it up
     **/
    for (idx = 0; idx < argc; idx++) {
        free(argv[idx]);
    }
    free(argv);
}

void eventprintf(char *fmt, ...)
{
    va_list args;
    char buf[16384];            /* Really huge, to try and avoid truncation */
    char *event;

    va_start(args, fmt);
    vsnprintf(buf, sizeof(buf), fmt, args);
    event = sstrdup(buf);
    event_message_process(event);
    va_end(args);
    if (event) {
        free(event);
    }
    return;
}

void event_message_process(char *eventbuf)
{
    int retVal = 0;
    EvtMessage *current = NULL;
    char source[64];
    char cmd[64];
    char buf[512];              /* Longest legal IRC command line */
    char *s;
    int ac;                     /* Parameters for the command */
    char **av;
    EvtMessage *evm;

    /* zero out the buffers before we do much else */
    *buf = '\0';
    *source = '\0';
    *cmd = '\0';

    strscpy(buf, eventbuf, sizeof(buf));

    doCleanBuffer((char *) buf);

    /* Split the buffer into pieces. */
    if (*buf == ':') {
        s = strpbrk(buf, " ");
        if (!s)
            return;
        *s = 0;
        while (isspace(*++s));
        strscpy(source, buf + 1, sizeof(source));
        memmove(buf, s, strlen(s) + 1);
    } else {
        *source = 0;
    }
    if (!*buf)
        return;
    s = strpbrk(buf, " ");
    if (s) {
        *s = 0;
        while (isspace(*++s));
    } else
        s = buf + strlen(buf);
    strscpy(cmd, buf, sizeof(cmd));
    ac = split_buf(s, &av, 1);

    /* Do something with the message. */
    evm = find_event(cmd);
    if (evm) {
        char *mod_current_module_name_save = mod_current_module_name;
        Module *mod_current_module_save = mod_current_module;
        if (evm->func) {
            mod_current_module_name = evm->mod_name;
            mod_current_module = findModule(evm->mod_name);
            retVal = evm->func(source, ac, av);
            if (retVal == MOD_CONT) {
                current = evm->next;
                while (current && current->func && retVal == MOD_CONT) {
                    mod_current_module_name = current->mod_name;
                    mod_current_module = findModule(current->mod_name);
                    retVal = current->func(source, ac, av);
                    current = current->next;
                }
            }
            mod_current_module_name = mod_current_module_name_save;
            mod_current_module = mod_current_module_save;
        }
    }
    /* Free argument list we created */
    free(av);
}

void event_process_hook(const char *name, int argc, char **argv)
{
    int retVal = 0;
    EvtHook *current = NULL;
    EvtHook *evh;
    if (mod_current_evtbuffer) {
        free(mod_current_evtbuffer);
    }
    /* Do something with the message. */
    evh = find_eventhook(name);
    if (evh) {
        if (evh->func) {
            char *mod_current_module_name_save = mod_current_module_name;
            Module *mod_current_module_save = mod_current_module;
            mod_current_module = findModule(evh->mod_name);
            mod_current_module_name = evh->mod_name;
            retVal = evh->func(argc, argv);
            if (retVal == MOD_CONT) {
                current = evh->next;
                while (current && current->func && retVal == MOD_CONT) {
                    mod_current_module = findModule(current->mod_name);
                    mod_current_module_name = current->mod_name;
                    retVal = current->func(argc, argv);
                    current = current->next;
                }
            }
            mod_current_module_name = mod_current_module_name_save;
            mod_current_module = mod_current_module_save;
        }
    }
}

/**
 * Displays a message list for a given message.
 * Again this is of little use other than debugging.
 * @param m the message to display
 * @return 0 is returned and has no meaning 
 */
int displayEventMessage(EvtMessage * evm)
{
    EvtMessage *msg = NULL;
    int i = 0;
    alog("Displaying message list for %s", evm->name);
    for (msg = evm; msg; msg = msg->next) {
        alog("%d: 0x%p", ++i, (void *) msg);
    }
    alog("end");
    return 0;
}

/**
 * Displays a message list for a given message.
 * Again this is of little use other than debugging.
 * @param m the message to display
 * @return 0 is returned and has no meaning 
 */
int displayEventHook(EvtHook * evh)
{
    EvtHook *msg = NULL;
    int i = 0;
    alog("Displaying message list for %s", evh->name);
    for (msg = evh; msg; msg = msg->next) {
        alog("%d: 0x%p", ++i, (void *) msg);
    }
    alog("end");
    return 0;
}

/**
 * Display the message call stak.
 * Prints the call stack for a message based on the message name, again useful for debugging and little lese :)
 * @param name the name of the message to print info for
 * @return the return int has no relevence atm :)
 */
int displayHookFromHash(char *name)
{
    EvtHookHash *current = NULL;
    int index = 0;
    index = CMD_HASH(name);
    if (debug > 1) {
        alog("debug: trying to display message %s", name);
    }
    for (current = EVENTHOOKS[index]; current; current = current->next) {
        if (stricmp(name, current->name) == 0) {
            displayEventHook(current->evh);
        }
    }
    if (debug > 1) {
        alog("debug: done displaying message %s", name);
    }
    return 0;
}

/**
 * Display the message call stak.
 * Prints the call stack for a message based on the message name, again useful for debugging and little lese :)
 * @param name the name of the message to print info for
 * @return the return int has no relevence atm :)
 */
int displayEvtMessageFromHash(char *name)
{
    EvtMessageHash *current = NULL;
    int index = 0;
    index = CMD_HASH(name);
    if (debug > 1) {
        alog("debug: trying to display message %s", name);
    }
    for (current = EVENT[index]; current; current = current->next) {
        if (stricmp(name, current->name) == 0) {
            displayEventMessage(current->evm);
        }
    }
    if (debug > 1) {
        alog("debug: done displaying message %s", name);
    }
    return 0;
}

/*******************************************************************************
 * Message Functions
 *******************************************************************************/

 /**
  * Create a new Message struct.
  * @param name the name of the message
  * @param func a pointer to the function to call when we recive this message
  * @return a new Message object
  **/
EvtMessage *createEventHandler(char *name,
                               int (*func) (char *source, int ac,
                                            char **av))
{
    EvtMessage *evm = NULL;
    if (!func) {
        return NULL;
    }
    if ((evm = malloc(sizeof(EvtMessage))) == NULL) {
        fatal("Out of memory!");
    }
    evm->name = sstrdup(name);
    evm->func = func;
    evm->mod_name = NULL;
    evm->next = NULL;
    return evm;
}

 /**
  * Create a new Message struct.
  * @param name the name of the message
  * @param func a pointer to the function to call when we recive this message
  * @return a new Message object
  **/
EvtHook *createEventHook(char *name, int (*func) (int argc, char **argv))
{
    EvtHook *evh = NULL;
    if (!func) {
        return NULL;
    }
    if ((evh = malloc(sizeof(EvtHook))) == NULL) {
        fatal("Out of memory!");
    }
    evh->name = sstrdup(name);
    evh->func = func;
    evh->mod_name = NULL;
    evh->next = NULL;
    return evh;
}

/** 
 * find a message in the given table. 
 * Looks up the message <name> in the MessageHash given
 * @param MessageHash the message table to search for this command, will almost always be IRCD
 * @param name the name of the command were looking for
 * @return NULL if we cant find it, or a pointer to the Message if we can
 **/
EvtMessage *findEventHandler(EvtMessageHash * msgEvtTable[],
                             const char *name)
{
    int idx;
    EvtMessageHash *current = NULL;
    if (!msgEvtTable || !name) {
        return NULL;
    }
    idx = CMD_HASH(name);

    for (current = msgEvtTable[idx]; current; current = current->next) {
        if (stricmp(name, current->name) == 0) {
            return current->evm;
        }
    }
    return NULL;
}

/** 
 * find a message in the given table. 
 * Looks up the message <name> in the MessageHash given
 * @param MessageHash the message table to search for this command, will almost always be IRCD
 * @param name the name of the command were looking for
 * @return NULL if we cant find it, or a pointer to the Message if we can
 **/
EvtHook *findEventHook(EvtHookHash * hookEvtTable[], const char *name)
{
    int idx;
    EvtHookHash *current = NULL;
    if (!hookEvtTable || !name) {
        return NULL;
    }
    idx = CMD_HASH(name);

    for (current = hookEvtTable[idx]; current; current = current->next) {
        if (stricmp(name, current->name) == 0) {
            return current->evh;
        }
    }
    return NULL;
}

/**
 * Add the given message (m) to the MessageHash marking it as a core command
 * @param msgTable the MessageHash we want to add to
 * @param m the Message we are adding
 * @return MOD_ERR_OK on a successful add.
 **/
int addCoreEventHandler(EvtMessageHash * msgEvtTable[], EvtMessage * evm)
{
    if (!msgEvtTable || !evm) {
        return MOD_ERR_PARAMS;
    }
    evm->core = 1;
    return addEventHandler(msgEvtTable, evm);
}

/**
 * Add a message to the MessageHash.
 * @param msgTable the MessageHash we want to add a message to
 * @param m the Message we want to add
 * @return MOD_ERR_OK on a successful add.
 **/
int addEventHandler(EvtMessageHash * msgEvtTable[], EvtMessage * evm)
{
    /* We can assume both param's have been checked by this point.. */
    int index = 0;
    EvtMessageHash *current = NULL;
    EvtMessageHash *newHash = NULL;
    EvtMessageHash *lastHash = NULL;

    if (!msgEvtTable || !evm) {
        return MOD_ERR_PARAMS;
    }

    index = CMD_HASH(evm->name);

    for (current = msgEvtTable[index]; current; current = current->next) {
        if (stricmp(evm->name, current->name) == 0) {   /* the msg exist's we are a addHead */
            evm->next = current->evm;
            current->evm = evm;
            if (debug)
                alog("debug: existing msg: (0x%p), new msg (0x%p)",
                     (void *) evm->next, (void *) evm);
            return MOD_ERR_OK;
        }
        lastHash = current;
    }

    if ((newHash = malloc(sizeof(EvtMessageHash))) == NULL) {
        fatal("Out of memory");
    }
    newHash->next = NULL;
    newHash->name = sstrdup(evm->name);
    newHash->evm = evm;

    if (lastHash == NULL)
        msgEvtTable[index] = newHash;
    else
        lastHash->next = newHash;
    return MOD_ERR_OK;
}

/**
 * Add a message to the MessageHash.
 * @param msgTable the MessageHash we want to add a message to
 * @param m the Message we want to add
 * @return MOD_ERR_OK on a successful add.
 **/
int addEventHook(EvtHookHash * hookEvtTable[], EvtHook * evh)
{
    /* We can assume both param's have been checked by this point.. */
    int index = 0;
    EvtHookHash *current = NULL;
    EvtHookHash *newHash = NULL;
    EvtHookHash *lastHash = NULL;

    if (!hookEvtTable || !evh) {
        return MOD_ERR_PARAMS;
    }

    index = CMD_HASH(evh->name);

    for (current = hookEvtTable[index]; current; current = current->next) {
        if (stricmp(evh->name, current->name) == 0) {   /* the msg exist's we are a addHead */
            evh->next = current->evh;
            current->evh = evh;
            if (debug)
                alog("debug: existing msg: (0x%p), new msg (0x%p)",
                     (void *) evh->next, (void *) evh);
            return MOD_ERR_OK;
        }
        lastHash = current;
    }

    if ((newHash = malloc(sizeof(EvtHookHash))) == NULL) {
        fatal("Out of memory");
    }
    newHash->next = NULL;
    newHash->name = sstrdup(evh->name);
    newHash->evh = evh;

    if (lastHash == NULL)
        hookEvtTable[index] = newHash;
    else
        lastHash->next = newHash;
    return MOD_ERR_OK;
}

/**
 * Add the given message (m) to the MessageHash marking it as a core command
 * @param msgTable the MessageHash we want to add to
 * @param m the Message we are adding
 * @return MOD_ERR_OK on a successful add.
 **/
int addCoreEventHook(EvtHookHash * hookEvtTable[], EvtHook * evh)
{
    if (!hookEvtTable || !evh) {
        return MOD_ERR_PARAMS;
    }
    evh->core = 1;
    return addEventHook(hookEvtTable, evh);
}

/**
 * Add a module message to the IRCD message hash
 * @param m the Message to add
 * @param pos the Position to add the message to, e.g. MOD_HEAD, MOD_TAIL, MOD_UNIQUE
 * @return MOD_ERR_OK on success, althing else on fail.
 **/
int moduleAddEventHandler(EvtMessage * evm)
{
    int status;

    if (!evm) {
        return MOD_ERR_PARAMS;
    }

    if (!mod_current_module) {
        return MOD_ERR_UNKNOWN;
    }                           /* shouldnt happen */

    evm->core = 0;
    if (!evm->mod_name) {
        evm->mod_name = sstrdup(mod_current_module->name);
    }

    status = addEventHandler(EVENT, evm);
    if (debug) {
        displayEvtMessageFromHash(evm->name);
    }
    return status;
}

/**
 * Add a module message to the IRCD message hash
 * @param m the Message to add
 * @param pos the Position to add the message to, e.g. MOD_HEAD, MOD_TAIL, MOD_UNIQUE
 * @return MOD_ERR_OK on success, althing else on fail.
 **/
int moduleAddEventHook(EvtHook * evh)
{
    int status;

    if (!evh) {
        return MOD_ERR_PARAMS;
    }

    if (!mod_current_module) {
        return MOD_ERR_UNKNOWN;
    }                           /* shouldnt happen */

    evh->core = 0;
    if (!evh->mod_name) {
        evh->mod_name = sstrdup(mod_current_module->name);
    }

    status = addEventHook(EVENTHOOKS, evh);
    if (debug) {
        displayHookFromHash(evh->name);
    }
    return status;
}

/**
 * remove the given message from the IRCD message hash
 * @param name the name of the message to remove
 * @return MOD_ERR_OK on success, althing else on fail.
 **/
int moduleEventDelHandler(char *name)
{
    EvtMessage *evm;
    int status;

    if (!mod_current_module) {
        return MOD_ERR_UNKNOWN;
    }
    evm = findEventHandler(EVENT, name);
    if (!evm) {
        return MOD_ERR_NOEXIST;
    }

    status = delEventHandler(EVENT, evm, mod_current_module->name);
    if (debug) {
        displayEvtMessageFromHash(evm->name);
    }
    return status;
}

/**
 * remove the given message from the IRCD message hash
 * @param name the name of the message to remove
 * @return MOD_ERR_OK on success, althing else on fail.
 **/
int moduleEventDelHook(const char *name)
{
    EvtHook *evh;
    int status;

    if (!mod_current_module) {
        return MOD_ERR_UNKNOWN;
    }
    evh = findEventHook(EVENTHOOKS, name);
    if (!evh) {
        return MOD_ERR_NOEXIST;
    }

    status = delEventHook(EVENTHOOKS, evh, mod_current_module->name);
    if (debug) {
        displayHookFromHash(evh->name);
    }
    return status;
}

/**
 * remove the given message from the given message hash, for the given module
 * @param msgTable which MessageHash we are removing from
 * @param m the Message we want to remove
 * @mod_name the name of the module we are removing
 * @return MOD_ERR_OK on success, althing else on fail.
 **/
int delEventHandler(EvtMessageHash * msgEvtTable[], EvtMessage * evm,
                    char *mod_name)
{
    int index = 0;
    EvtMessageHash *current = NULL;
    EvtMessageHash *lastHash = NULL;
    EvtMessage *tail = NULL, *last = NULL;

    if (!evm || !msgEvtTable) {
        return MOD_ERR_PARAMS;
    }

    index = CMD_HASH(evm->name);

    for (current = msgEvtTable[index]; current; current = current->next) {
        if (stricmp(evm->name, current->name) == 0) {
            if (!lastHash) {
                tail = current->evm;
                if (tail->next) {
                    while (tail) {
                        if (mod_name && tail->mod_name
                            && (stricmp(mod_name, tail->mod_name) == 0)) {
                            if (last) {
                                last->next = tail->next;
                            } else {
                                current->evm = tail->next;
                            }
                            return MOD_ERR_OK;
                        }
                        last = tail;
                        tail = tail->next;
                    }
                } else {
                    msgEvtTable[index] = current->next;
                    free(current->name);
                    return MOD_ERR_OK;
                }
            } else {
                tail = current->evm;
                if (tail->next) {
                    while (tail) {
                        if (mod_name && tail->mod_name
                            && (stricmp(mod_name, tail->mod_name) == 0)) {
                            if (last) {
                                last->next = tail->next;
                            } else {
                                current->evm = tail->next;
                            }
                            return MOD_ERR_OK;
                        }
                        last = tail;
                        tail = tail->next;
                    }
                } else {
                    lastHash->next = current->next;
                    free(current->name);
                    return MOD_ERR_OK;
                }
            }
        }
        lastHash = current;
    }
    return MOD_ERR_NOEXIST;
}


/**
 * remove the given message from the given message hash, for the given module
 * @param msgTable which MessageHash we are removing from
 * @param m the Message we want to remove
 * @mod_name the name of the module we are removing
 * @return MOD_ERR_OK on success, althing else on fail.
 **/
int delEventHook(EvtHookHash * hookEvtTable[], EvtHook * evh,
                 char *mod_name)
{
    int index = 0;
    EvtHookHash *current = NULL;
    EvtHookHash *lastHash = NULL;
    EvtHook *tail = NULL, *last = NULL;

    if (!evh || !hookEvtTable) {
        return MOD_ERR_PARAMS;
    }

    index = CMD_HASH(evh->name);

    for (current = hookEvtTable[index]; current; current = current->next) {
        if (stricmp(evh->name, current->name) == 0) {
            if (!lastHash) {
                tail = current->evh;
                if (tail->next) {
                    while (tail) {
                        if (mod_name && tail->mod_name
                            && (stricmp(mod_name, tail->mod_name) == 0)) {
                            if (last) {
                                last->next = tail->next;
                            } else {
                                current->evh = tail->next;
                            }
                            return MOD_ERR_OK;
                        }
                        last = tail;
                        tail = tail->next;
                    }
                } else {
                    hookEvtTable[index] = current->next;
                    free(current->name);
                    return MOD_ERR_OK;
                }
            } else {
                tail = current->evh;
                if (tail->next) {
                    while (tail) {
                        if (mod_name && tail->mod_name
                            && (stricmp(mod_name, tail->mod_name) == 0)) {
                            if (last) {
                                last->next = tail->next;
                            } else {
                                current->evh = tail->next;
                            }
                            return MOD_ERR_OK;
                        }
                        last = tail;
                        tail = tail->next;
                    }
                } else {
                    lastHash->next = current->next;
                    free(current->name);
                    return MOD_ERR_OK;
                }
            }
        }
        lastHash = current;
    }
    return MOD_ERR_NOEXIST;
}


/**
 * Destory a message, freeing its memory.
 * @param m the message to be destroyed
 * @return MOD_ERR_SUCCESS on success
 **/
int destroyEventHandler(EvtMessage * evm)
{
    if (!evm) {
        return MOD_ERR_PARAMS;
    }
    if (evm->name) {
        free(evm->name);
    }
    evm->func = NULL;
    if (evm->mod_name) {
        free(evm->mod_name);
    }
    evm->next = NULL;
    return MOD_ERR_OK;
}

/**
 * Destory a message, freeing its memory.
 * @param m the message to be destroyed
 * @return MOD_ERR_SUCCESS on success
 **/
int destroyEventHook(EvtHook * evh)
{
    if (!evh) {
        return MOD_ERR_PARAMS;
    }
    if (evh->name) {
        free(evh->name);
    }
    evh->func = NULL;
    if (evh->mod_name) {
        free(evh->mod_name);
    }
    evh->next = NULL;
    return MOD_ERR_OK;
}