01 #ifndef IRCD_MESSAGE_TAG_HH
02 #define IRCD_MESSAGE_TAG_HH
03 U8 *IrcParseMessageTag(U8 *str,U8 *who) {
04   if(*str!='@') return NULL;
05   I64 wl=StrLen(who);
06   U8 *ret=MAlloc(4096),*into;
07   str++;
08   while(*str) {
09     if(!StrNICmp(who,str,wl)) {
10       str+=wl;
11       if(*str==' '||*str==';') {
12 //Empty value
13         Free(ret);
14         return StrNew("");
15       } else if(*str=='=') {
16 //Gxt a value
17         str++;
18         into=ret;
19         while(*str!=' '&&*str&&*str!=';') {
20           switch(*str) {
21             case '\\':
22               str++;
23               switch(*str) {
24                 start:
25                 case ':':
26                   *into++=';';
27                   break;
28                   case 's':
29                     *into++=' ';
30                     break;
31                   case '\\':
32                     *into++='\\';
33                     break;
34                   case 'r':
35                     *into++='\r';
36                     break;
37                   case 'n':
38                     *into++='\n';
39                     break;
40                 end:
41                   str++;
42                   break;
43                 default:
44                   *into++=*str++;
45               }
46             break;
47            default:
48              *into++=*str++;
49           }
50         }
51         *into++=0;
52         return ret;
53       }
54     } else {
55         while(*str&&*str!=';')
56           str++;
57         if(*str==';')
58           str++;
59       }
60   }
61   Free(ret);
62   return NULL;
63 }
64 U8 *IrcGetClientMsgs(U8 *str) {
65   U8 *ret=CAlloc(StrLen(str)+1),*ptr=ret;
66   U8 *st;
67   Bool first=TRUE;
68   if(*str!='@') return ret;
69   str++;
70   while(*str&&*str!=' ') {
71     for(st=str;*str&&*str!=' '&&*str!=';';str++)
72       ;
73     if(*str==';')
74       str++;
75     if(*st=='+') {
76       if(first) {
77         first=FALSE;
78       } else
79         *ptr++=';';
80       while(*st!=';'&&*st!=' '&&*st)
81         *ptr++=*st++;
82     }
83   }
84   return ret;
85 }
86 /*
87 "%s\n",GetClientMsgs("@+typing=paused;poo=123;+msgid=123;+poop=yummy ");
88 "%s\n",ParseMessageTag("@aaa=bbb;ccc;example.com/ddd=eee","aaa");
89 "%s\n",ParseMessageTag("@aaa=bbb;ccc;example.com/ddd=eee","example.com/ddd");
90 "%x\n",ParseMessageTag("@aaa=bbb;ccc;example.com/ddd=eee","ccc");*/
91 #endif