annotate extensions/rt_ereg/rtereg.c @ 525:ecfa089bd29a

Forgot new files
author Sebastien Decugis <sdecugis@nict.go.jp>
date Wed, 01 Sep 2010 14:41:33 +0900
parents
children 6fe3e5cf9fb2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
525
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1 /*********************************************************************************************************
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2 * Software License Agreement (BSD License) *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
3 * Author: Sebastien Decugis <sdecugis@nict.go.jp> *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
4 * *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
5 * Copyright (c) 2010, WIDE Project and NICT *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
6 * All rights reserved. *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
7 * *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
8 * Redistribution and use of this software in source and binary forms, with or without modification, are *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
9 * permitted provided that the following conditions are met: *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
10 * *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
11 * * Redistributions of source code must retain the above *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
12 * copyright notice, this list of conditions and the *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
13 * following disclaimer. *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
14 * *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
15 * * Redistributions in binary form must reproduce the above *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
16 * copyright notice, this list of conditions and the *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
17 * following disclaimer in the documentation and/or other *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
18 * materials provided with the distribution. *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
19 * *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
20 * * Neither the name of the WIDE Project or NICT nor the *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
21 * names of its contributors may be used to endorse or *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
22 * promote products derived from this software without *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
23 * specific prior written permission of WIDE Project and *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
24 * NICT. *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
25 * *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
34 *********************************************************************************************************/
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
35
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
36 /*
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
37 * This extension allows to perform some pattern-matching on an AVP
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
38 * and send the message to a server accordingly.
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
39 * See rt_ereg.conf.sample file for the format of the configuration file.
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
40 */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
41
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
42 #include "rtereg.h"
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
43
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
44 /* The configuration structure */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
45 struct rtereg_conf rtereg_conf;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
46
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
47 #ifndef HAVE_REG_STARTEND
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
48 static char * buf = NULL;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
49 static size_t bufsz;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
50 static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
51 #endif /* HAVE_REG_STARTEND */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
52
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
53 static int proceed(char * value, size_t len, struct fd_list * candidates)
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
54 {
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
55 int i;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
56
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
57 for (i = 0; i < rtereg_conf.rules_nb; i++) {
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
58 /* Does this pattern match the value? */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
59 struct rtereg_rule * r = &rtereg_conf.rules[i];
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
60 int err = 0;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
61 struct fd_list * c;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
62
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
63 #ifdef HAVE_REG_STARTEND
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
64 {
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
65 regmatch_t pmatch[1];
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
66 memset(pmatch, 0, sizeof(pmatch));
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
67 pmatch[0].rm_so = 0;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
68 pmatch[0].rm_eo = len;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
69 err = regexec(&r->preg, value, 0, pmatch, REG_STARTEND);
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
70 }
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
71 #else /* HAVE_REG_STARTEND */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
72 {
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
73 /* We have a 0-terminated string */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
74 err = regexec(&r->preg, value, 0, NULL, 0);
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
75 }
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
76 #endif /* HAVE_REG_STARTEND */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
77
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
78 if (err == REG_NOMATCH)
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
79 continue;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
80
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
81 if (err != 0) {
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
82 char * errstr;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
83 size_t bl;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
84
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
85 /* Error while compiling the regex */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
86 TRACE_DEBUG(INFO, "Error while executing the regular expression '%s':", r->pattern);
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
87
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
88 /* Get the error message size */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
89 bl = regerror(err, &r->preg, NULL, 0);
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
90
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
91 /* Alloc the buffer for error message */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
92 CHECK_MALLOC( errstr = malloc(bl) );
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
93
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
94 /* Get the error message content */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
95 regerror(err, &r->preg, errstr, bl);
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
96 TRACE_DEBUG(INFO, "\t%s", errstr);
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
97
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
98 /* Free the buffer, return the error */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
99 free(errstr);
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
100
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
101 return (err == REG_ESPACE) ? ENOMEM : EINVAL;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
102 }
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
103
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
104 /* From this point, the expression matched the AVP value */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
105 TRACE_DEBUG(FULL, "[rt_ereg] Match: '%s' to value '%.*s' => '%s' += %d",
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
106 r->pattern,
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
107 len,
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
108 value,
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
109 r->server,
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
110 r->score);
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
111
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
112 for (c = candidates->next; c != candidates; c = c->next) {
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
113 struct rtd_candidate * cand = (struct rtd_candidate *)c;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
114
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
115 if (strcmp(r->server, cand->diamid) == 0) {
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
116 cand->score += r->score;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
117 break;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
118 }
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
119 }
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
120 };
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
121
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
122 return 0;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
123 }
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
124
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
125 /* The callback called on new messages */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
126 static int rtereg_out(void * cbdata, struct msg * msg, struct fd_list * candidates)
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
127 {
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
128 struct avp * avp = NULL;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
129
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
130 TRACE_ENTRY("%p %p %p", cbdata, msg, candidates);
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
131
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
132 CHECK_PARAMS(msg && candidates);
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
133
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
134 /* Check if it is worth processing the message */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
135 if (FD_IS_LIST_EMPTY(candidates)) {
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
136 return 0;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
137 }
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
138
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
139 /* Now search the AVP in the message */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
140 CHECK_FCT( fd_msg_search_avp ( msg, rtereg_conf.avp, &avp ) );
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
141 if (avp != NULL) {
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
142 struct avp_hdr * ahdr = NULL;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
143 CHECK_FCT( fd_msg_avp_hdr ( avp, &ahdr ) );
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
144 if (ahdr->avp_value != NULL) {
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
145 int ret;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
146
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
147 #ifndef HAVE_REG_STARTEND
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
148 /* Lock the buffer */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
149 CHECK_POSIX( pthread_mutex_lock(&mtx) );
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
150
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
151 /* Augment the buffer if needed */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
152 if (ahdr->avp_value->os.len >= bufsz) {
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
153 CHECK_MALLOC_DO( buf = realloc(buf, ahdr->avp_value->os.len + 1),
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
154 { pthread_mutex_unlock(&mtx); return ENOMEM; } );
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
155 }
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
156
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
157 /* Copy the AVP value */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
158 memcpy(buf, ahdr->avp_value->os.data, ahdr->avp_value->os.len);
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
159 buf[ahdr->avp_value->os.len] = '\0';
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
160
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
161 /* Now apply the rules */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
162 ret = proceed(buf, ahdr->avp_value->os.len, candidates);
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
163
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
164 CHECK_POSIX(pthread_mutex_unlock(&mtx));
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
165
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
166 CHECK_FCT(ret);
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
167 #else /* HAVE_REG_STARTEND */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
168 CHECK_FCT( proceed(ahdr->avp_value->os.data, ahdr->avp_value->os.len, candidates) );
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
169 #endif /* HAVE_REG_STARTEND */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
170 }
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
171 }
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
172
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
173 return 0;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
174 }
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
175
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
176 /* handler */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
177 static struct fd_rt_out_hdl * rtereg_hdl = NULL;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
178
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
179 /* entry point */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
180 static int rtereg_entry(char * conffile)
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
181 {
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
182 TRACE_ENTRY("%p", conffile);
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
183
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
184 /* Initialize the configuration */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
185 memset(&rtereg_conf, 0, sizeof(rtereg_conf));
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
186
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
187 /* Parse the configuration file */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
188 CHECK_FCT( rtereg_conf_handle(conffile) );
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
189
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
190 /* Register the callback */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
191 CHECK_FCT( fd_rt_out_register( rtereg_out, NULL, 1, &rtereg_hdl ) );
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
192
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
193 /* We're done */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
194 return 0;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
195 }
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
196
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
197 /* Unload */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
198 void fd_ext_fini(void)
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
199 {
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
200 int i;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
201 TRACE_ENTRY();
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
202
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
203 /* Unregister the cb */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
204 CHECK_FCT_DO( fd_rt_out_unregister ( rtereg_hdl, NULL ), /* continue */ );
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
205
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
206 /* Destroy the data */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
207 if (rtereg_conf.rules)
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
208 for (i = 0; i < rtereg_conf.rules_nb; i++) {
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
209 free(rtereg_conf.rules[i].pattern);
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
210 free(rtereg_conf.rules[i].server);
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
211 regfree(&rtereg_conf.rules[i].preg);
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
212 }
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
213 free(rtereg_conf.rules);
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
214 #ifndef HAVE_REG_STARTEND
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
215 free(buf);
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
216 #endif /* HAVE_REG_STARTEND */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
217
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
218 /* Done */
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
219 return ;
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
220 }
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
221
ecfa089bd29a Forgot new files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
222 EXTENSION_ENTRY("rt_ereg", rtereg_entry);
"Welcome to our mercurial repository"