]>
Commit | Line | Data |
---|---|---|
f1903ace CP |
1 | /* |
2 | * TIMESTAMP functionality | |
3 | */ | |
4 | ||
5 | #include "newsearch.h" | |
6 | ||
7 | #include <stdio.h> | |
8 | #include <stdlib.h> | |
9 | ||
10 | #include "../irc/irc_config.h" | |
f1903ace CP |
11 | #include "../lib/irc_string.h" |
12 | ||
c8be5183 CP |
13 | void *timestamp_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput); |
14 | void timestamp_free(searchCtx *ctx, struct searchNode *thenode); | |
f1903ace | 15 | |
c8be5183 | 16 | struct searchNode *timestamp_parse(searchCtx *ctx, int type, int argc, char **argv) { |
f1903ace CP |
17 | struct searchNode *thenode; |
18 | ||
4354c087 | 19 | if ((type != SEARCHTYPE_NICK) && (type != SEARCHTYPE_CHANNEL)){ |
20 | parseError = "timestamp: this function is only valid for nick or channel searches."; | |
f1903ace CP |
21 | return NULL; |
22 | } | |
23 | ||
9ce4f0be IB |
24 | if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) { |
25 | parseError = "malloc: could not allocate memory for this search."; | |
26 | return NULL; | |
27 | } | |
f1903ace CP |
28 | |
29 | thenode->returntype = RETURNTYPE_INT; | |
fc5bfa31 | 30 | thenode->localdata = (void *)(long)type; |
f1903ace CP |
31 | thenode->exe = timestamp_exe; |
32 | thenode->free = timestamp_free; | |
33 | ||
34 | return thenode; | |
35 | } | |
36 | ||
c8be5183 | 37 | void *timestamp_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) { |
f1903ace | 38 | nick *np = (nick *)theinput; |
4354c087 | 39 | chanindex *cip = (chanindex *)theinput; |
40 | ||
fc5bfa31 | 41 | if ((long)thenode->localdata == SEARCHTYPE_NICK) { |
4354c087 | 42 | return (void *)np->timestamp; |
43 | } else { | |
44 | if (cip->channel) | |
45 | return (void *)cip->channel->timestamp; | |
46 | else | |
47 | return 0; | |
48 | } | |
f1903ace CP |
49 | } |
50 | ||
c8be5183 | 51 | void timestamp_free(searchCtx *ctx, struct searchNode *thenode) { |
f1903ace CP |
52 | free(thenode); |
53 | } |