Definition in file config.h.
#include "utils.h"
Go to the source code of this file.
Data Structures | |
| struct | peer_config |
| Peer configuration. More... | |
| struct | acceptor_config |
| Acceptor socket configuration. More... | |
| struct | app_config |
| Application configuration. More... | |
| struct | _routing_entry |
| Routing Table Entry. More... | |
| struct | _routing_realm |
| Routing Table realm. More... | |
| struct | routing_table |
| Routing Table configuration. More... | |
| struct | dp_config |
| Full Diameter Peer configuration. More... | |
Typedefs | |
| typedef _routing_entry | routing_entry |
| Routing Table Entry. | |
| typedef _routing_realm | routing_realm |
| Routing Table realm. | |
Enumerations | |
| enum | app_type { DP_AUTHORIZATION, DP_ACCOUNTING } |
Functions | |
| dp_config * | new_dp_config () |
| Create a new dp_config. | |
| routing_realm * | new_routing_realm () |
| Create a new dp_config. | |
| routing_entry * | new_routing_entry () |
| Create a new dp_config. | |
| void | free_dp_config (dp_config *x) |
| Frees the memory held by a dp_config. | |
| void | free_routing_realm (routing_realm *rr) |
| Free the space claimed by a routing realm. | |
| void | free_routing_entry (routing_entry *re) |
| Free the space claimed by a routing entry. | |
| void | log_dp_config (int level, dp_config *x) |
| Log the dp_config to output, for debug purposes. | |
| dp_config * | parse_dp_config (char *filename) |
| Parses a DiameterPeer configuration file. | |
| typedef struct _routing_entry routing_entry |
Routing Table Entry.
| typedef struct _routing_realm routing_realm |
Routing Table realm.
| enum app_type |
Definition at line 73 of file config.h.
00073 { 00074 DP_AUTHORIZATION, 00075 DP_ACCOUNTING 00076 } app_type;
| dp_config* new_dp_config | ( | ) | [inline] |
Create a new dp_config.
Definition at line 59 of file config.c.
References LOG_NO_MEM.
Referenced by parse_dp_config().
00060 { 00061 dp_config *x; 00062 x = shm_malloc(sizeof(dp_config)); 00063 if (!x) { 00064 LOG_NO_MEM("shm",sizeof(dp_config)); 00065 goto error; 00066 } 00067 memset(x,0,sizeof(dp_config)); 00068 return x; 00069 error: 00070 LOG(L_ERR,"ERROR:%s(): failed to create new dp_config.\n",__FUNCTION__); 00071 return 0; 00072 }
| routing_realm* new_routing_realm | ( | ) | [inline] |
Create a new dp_config.
Definition at line 77 of file config.c.
References LOG_NO_MEM.
Referenced by parse_dp_config().
00078 { 00079 routing_realm *x; 00080 x = shm_malloc(sizeof(routing_realm)); 00081 if (!x) { 00082 LOG_NO_MEM("shm",sizeof(routing_realm)); 00083 goto error; 00084 } 00085 memset(x,0,sizeof(routing_realm)); 00086 return x; 00087 error: 00088 LOG(L_ERR,"ERROR:%s(): failed to create new routing_realm.\n",__FUNCTION__); 00089 return 0; 00090 }
| routing_entry* new_routing_entry | ( | ) | [inline] |
Create a new dp_config.
Definition at line 95 of file config.c.
References LOG_NO_MEM.
Referenced by parse_dp_config().
00096 { 00097 routing_entry *x; 00098 x = shm_malloc(sizeof(routing_entry)); 00099 if (!x) { 00100 LOG_NO_MEM("shm",sizeof(routing_entry)); 00101 goto error; 00102 } 00103 memset(x,0,sizeof(routing_entry)); 00104 return x; 00105 error: 00106 LOG(L_ERR,"ERROR:%s(): failed to create new routing_entry.\n",__FUNCTION__); 00107 return 0; 00108 }
| void free_dp_config | ( | dp_config * | x | ) | [inline] |
Frees the memory held by a dp_config.
Definition at line 142 of file config.c.
References dp_config::acceptors, dp_config::acceptors_cnt, dp_config::applications, acceptor_config::bind, peer_config::fqdn, dp_config::fqdn, free_routing_entry(), free_routing_realm(), dp_config::identity, if, _routing_entry::next, _routing_realm::next, dp_config::peers, dp_config::peers_cnt, dp_config::product_name, dp_config::r_table, peer_config::realm, dp_config::realm, routing_table::realms, and routing_table::routes.
Referenced by diameter_peer_destroy(), diameter_peer_init(), and parse_dp_config().
00143 { 00144 int i; 00145 if (!x) return; 00146 if (x->fqdn.s) shm_free(x->fqdn.s); 00147 if (x->identity.s) shm_free(x->identity.s); 00148 if (x->realm.s) shm_free(x->realm.s); 00149 if (x->product_name.s) shm_free(x->product_name.s); 00150 if (x->peers) { 00151 for(i=0;i<x->peers_cnt;i++){ 00152 if (x->peers[i].fqdn.s) shm_free(x->peers[i].fqdn.s); 00153 if (x->peers[i].realm.s) shm_free(x->peers[i].realm.s); 00154 } 00155 shm_free(x->peers); 00156 } 00157 if (x->acceptors) { 00158 for(i=0;i<x->acceptors_cnt;i++){ 00159 if (x->acceptors[i].bind.s) shm_free(x->acceptors[i].bind.s); 00160 } 00161 shm_free(x->acceptors); 00162 } 00163 if (x->applications) shm_free(x->applications); 00164 00165 if (x->r_table) { 00166 routing_realm *rr,*rrn; 00167 routing_entry *re,*ren; 00168 for(rr=x->r_table->realms;rr;rr=rrn){ 00169 rrn = rr->next; 00170 free_routing_realm(rr); 00171 } 00172 for(re=x->r_table->routes;re;re=ren){ 00173 ren = re->next; 00174 free_routing_entry(re); 00175 } 00176 shm_free(x->r_table); 00177 } 00178 shm_free(x); 00179 }
| void free_routing_realm | ( | routing_realm * | rr | ) | [inline] |
Free the space claimed by a routing realm.
Definition at line 124 of file config.c.
References free_routing_entry(), _routing_entry::next, _routing_realm::realm, and _routing_realm::routes.
Referenced by free_dp_config().
00125 { 00126 routing_entry *re,*ren; 00127 if (!rr) return; 00128 if (rr->realm.s) shm_free(rr->realm.s); 00129 for(re=rr->routes;re;re=ren){ 00130 ren = re->next; 00131 free_routing_entry(re); 00132 } 00133 shm_free(rr); 00134 }
| void free_routing_entry | ( | routing_entry * | re | ) | [inline] |
Free the space claimed by a routing entry.
Definition at line 114 of file config.c.
References _routing_entry::fqdn.
Referenced by free_dp_config(), and free_routing_realm().
00115 { 00116 if (!re) return; 00117 if (re->fqdn.s) shm_free(re->fqdn.s); 00118 shm_free(re); 00119 }
| void log_dp_config | ( | int | level, | |
| dp_config * | x | |||
| ) | [inline] |
Log the dp_config to output, for debug purposes.
Definition at line 184 of file config.c.
References dp_config::accept_unknown_peers, dp_config::acceptors, dp_config::acceptors_cnt, dp_config::applications, dp_config::applications_cnt, acceptor_config::bind, DP_AUTHORIZATION, dp_config::drop_unknown_peers, peer_config::fqdn, dp_config::fqdn, app_config::id, if, _routing_realm::next, dp_config::peers, dp_config::peers_cnt, acceptor_config::port, peer_config::port, dp_config::product_name, dp_config::queue_length, dp_config::r_table, peer_config::realm, dp_config::realm, routing_table::realms, dp_config::tc, app_config::type, app_config::vendor, dp_config::vendor_id, and dp_config::workers.
Referenced by diameter_peer_init().
00185 { 00186 int i; 00187 LOG(level,"Diameter Peer Config:\n"); 00188 LOG(level,"\tFQDN : %.*s\n",x->fqdn.len,x->fqdn.s); 00189 LOG(level,"\tRealm : %.*s\n",x->realm.len,x->realm.s); 00190 LOG(level,"\tVendorID: %d\n",x->vendor_id); 00191 LOG(level,"\tProdName: %.*s\n",x->product_name.len,x->product_name.s); 00192 LOG(level,"\tAcceptUn: [%c]\n",x->accept_unknown_peers?'X':' '); 00193 LOG(level,"\tDropUnkn: [%c]\n",x->drop_unknown_peers?'X':' '); 00194 LOG(level,"\tTc : %d\n",x->tc); 00195 LOG(level,"\tWorkers : %d\n",x->workers); 00196 LOG(level,"\tQueueLen: %d\n",x->queue_length); 00197 LOG(level,"\tPeers : %d\n",x->peers_cnt); 00198 for(i=0;i<x->peers_cnt;i++) 00199 LOG(level,"\t\tFQDN: %.*s \t Realm: %.*s \t Port: %d\n", 00200 x->peers[i].fqdn.len,x->peers[i].fqdn.s, 00201 x->peers[i].realm.len,x->peers[i].realm.s, 00202 x->peers[i].port); 00203 LOG(level,"\tAcceptors : %d\n",x->acceptors_cnt); 00204 for(i=0;i<x->acceptors_cnt;i++) 00205 LOG(level,"\t\tPort: %d \t Bind: %.*s \n", 00206 x->acceptors[i].port, 00207 x->acceptors[i].bind.len,x->acceptors[i].bind.s); 00208 LOG(level,"\tApplications : %d\n",x->applications_cnt); 00209 for(i=0;i<x->applications_cnt;i++) 00210 LOG(level,"\t\t%s ID: %d \t Vendor: %d \n", 00211 (x->applications[i].type==DP_AUTHORIZATION)?"Auth":"Acct", 00212 x->applications[i].id, 00213 x->applications[i].vendor); 00214 if (x->r_table){ 00215 routing_realm *rr; 00216 routing_entry *re; 00217 LOG(level,"\tRouting Table : \n"); 00218 for(rr=x->r_table->realms;rr;rr=rr->next){ 00219 LOG(level,"\t\tRealm: %.*s\n", 00220 rr->realm.len,rr->realm.s); 00221 for(re=rr->routes;re;re=re->next) 00222 LOG(level,"\t\t\tRoute: [%4d] %.*s\n", 00223 re->metric,re->fqdn.len,re->fqdn.s); 00224 } 00225 for(re=x->r_table->routes;re;re=re->next) 00226 LOG(level,"\t\tDefaultRoute: [%4d] %.*s\n", 00227 re->metric,re->fqdn.len,re->fqdn.s); 00228 } 00229 00230 }
| dp_config* parse_dp_config | ( | char * | filename | ) |
Parses a DiameterPeer configuration file.
| filename | - path to the file |
Definition at line 118 of file configparser.c.
References dp_config::accept_unknown_peers, dp_config::acceptors, dp_config::acceptors_cnt, dp_config::applications, dp_config::applications_cnt, acceptor_config::bind, DP_ACCOUNTING, DP_AUTHORIZATION, dp_config::drop_unknown_peers, errno, dp_config::fqdn, peer_config::fqdn, _routing_entry::fqdn, free_dp_config(), app_config::id, dp_config::identity, LOG_NO_MEM, _routing_entry::metric, new_dp_config(), new_routing_entry(), new_routing_realm(), _routing_entry::next, _routing_realm::next, parser_destroy(), parser_init(), dp_config::peers, dp_config::peers_cnt, peer_config::port, acceptor_config::port, dp_config::product_name, dp_config::queue_length, quote_trim_dup(), dp_config::r_table, dp_config::realm, peer_config::realm, _routing_realm::realm, routing_table::realms, routing_table::routes, _routing_realm::routes, dp_config::tc, app_config::type, app_config::vendor, dp_config::vendor_id, and dp_config::workers.
Referenced by diameter_peer_init().
00119 { 00120 FILE *f=0; 00121 dp_config *x=0; 00122 xmlDocPtr doc=0; 00123 xmlNodePtr root=0,child=0,nephew=0; 00124 xmlChar *xc=0; 00125 int k; 00126 routing_entry *re,*rei; 00127 routing_realm *rr,*rri; 00128 00129 parser_init(); 00130 00131 if (!filename){ 00132 LOG(L_ERR,"ERROR:parse_dp_config(): filename parameter is null\n"); 00133 goto error; 00134 } 00135 f = fopen(filename,"r"); 00136 if (!f){ 00137 LOG(L_ERR,"ERROR:parse_dp_config(): Error opening <%s> file > %s\n",filename,strerror(errno)); 00138 goto error; 00139 } 00140 fclose(f); 00141 00142 00143 x = new_dp_config(); 00144 if (!f){ 00145 LOG(L_ERR,"ERROR:parse_dp_config(): Error opening <%s> file > %s\n",filename,strerror(errno)); 00146 goto error; 00147 } 00148 00149 doc = xmlParseFile(filename); 00150 if (!doc){ 00151 LOG(L_ERR,"ERR:parse_dp_config(): This is not a valid XML file <%s>\n", 00152 filename); 00153 goto error; 00154 } 00155 00156 root = xmlDocGetRootElement(doc); 00157 if (!root){ 00158 LOG(L_ERR,"ERR:parse_dp_config(): Empty XML <%s>\n",filename); 00159 goto error; 00160 } 00161 00162 k = xmlStrlen(root->name); 00163 if (k>12) k = 12; 00164 if (strncasecmp((char*)root->name,"DiameterPeer",k)!=0){ 00165 LOG(L_ERR,"ERR:parse_dp_config(): XML Root is not <DiameterPeer>\n"); 00166 goto error; 00167 } 00168 00169 xc = xmlGetProp(root,(xmlChar*)"FQDN"); 00170 quote_trim_dup(&(x->fqdn),(char*)xc); 00171 quote_trim_dup(&(x->identity),(char*)xc); 00172 00173 xc = xmlGetProp(root,(xmlChar*)"Realm"); 00174 quote_trim_dup(&(x->realm),(char*)xc); 00175 00176 xc = xmlGetProp(root,(xmlChar*)"Vendor_Id"); 00177 x->vendor_id = atoi((char*)xc); 00178 00179 xc = xmlGetProp(root,(xmlChar*)"Product_Name"); 00180 quote_trim_dup(&(x->product_name),(char*)xc); 00181 00182 xc = xmlGetProp(root,(xmlChar*)"AcceptUnknownPeers"); 00183 x->accept_unknown_peers = atoi((char*)xc); 00184 00185 xc = xmlGetProp(root,(xmlChar*)"DropUnknownOnDisconnect"); 00186 x->drop_unknown_peers = atoi((char*)xc); 00187 00188 xc = xmlGetProp(root,(xmlChar*)"Tc"); 00189 x->tc = atoi((char*)xc); 00190 00191 xc = xmlGetProp(root,(xmlChar*)"Workers"); 00192 x->workers = atoi((char*)xc); 00193 00194 xc = xmlGetProp(root,(xmlChar*)"QueueLength"); 00195 x->queue_length = atoi((char*)xc); 00196 00197 for(child = root->children; child; child = child->next) 00198 if (child->type == XML_ELEMENT_NODE) 00199 { 00200 if (xmlStrlen(child->name)==4 && strncasecmp((char*)child->name,"Peer",4)==0){ 00201 //PEER 00202 x->peers_cnt++; 00203 } 00204 else if (xmlStrlen(child->name)==8 && strncasecmp((char*)child->name,"Acceptor",8)==0){ 00205 //Acceptor 00206 x->acceptors_cnt++; 00207 } 00208 else if (xmlStrlen(child->name)==4 && (strncasecmp((char*)child->name,"Auth",4)==0|| 00209 strncasecmp((char*)child->name,"Acct",4)==0)){ 00210 //Application 00211 x->applications_cnt++; 00212 } 00213 } 00214 x->peers = shm_malloc(x->peers_cnt*sizeof(peer_config)); 00215 if (!x->peers){ 00216 LOG_NO_MEM("shm",x->peers_cnt*sizeof(peer_config)); 00217 goto error; 00218 } 00219 memset(x->peers,0,x->peers_cnt*sizeof(peer_config)); 00220 x->peers_cnt=0; 00221 x->acceptors = shm_malloc(x->acceptors_cnt*sizeof(acceptor_config)); 00222 if (!x->acceptors){ 00223 LOG_NO_MEM("shm",x->acceptors_cnt*sizeof(acceptor_config)); 00224 goto error; 00225 } 00226 memset(x->acceptors,0,x->acceptors_cnt*sizeof(acceptor_config)); 00227 x->acceptors_cnt=0; 00228 x->applications = shm_malloc(x->applications_cnt*sizeof(app_config)); 00229 if (!x->applications){ 00230 LOG_NO_MEM("shm",x->applications_cnt*sizeof(app_config)); 00231 goto error; 00232 } 00233 memset(x->applications,0,x->applications_cnt*sizeof(app_config)); 00234 x->applications_cnt=0; 00235 00236 for(child = root->children; child; child = child->next) 00237 if (child->type == XML_ELEMENT_NODE) 00238 { 00239 if (xmlStrlen(child->name)==4 && strncasecmp((char*)child->name,"Peer",4)==0){ 00240 //PEER 00241 xc = xmlGetProp(child,(xmlChar*)"FQDN"); 00242 quote_trim_dup(&(x->peers[x->peers_cnt].fqdn),(char*)xc); 00243 xc = xmlGetProp(child,(xmlChar*)"Realm"); 00244 quote_trim_dup(&(x->peers[x->peers_cnt].realm),(char*)xc); 00245 xc = xmlGetProp(child,(xmlChar*)"port"); 00246 x->peers[x->peers_cnt].port = atoi((char*)xc); 00247 x->peers_cnt++; 00248 } 00249 else if (xmlStrlen(child->name)==8 && strncasecmp((char*)child->name,"Acceptor",8)==0){ 00250 //Acceptor 00251 xc = xmlGetProp(child,(xmlChar*)"bind"); 00252 quote_trim_dup(&(x->acceptors[x->acceptors_cnt].bind),(char*)xc); 00253 xc = xmlGetProp(child,(xmlChar*)"port"); 00254 x->acceptors[x->acceptors_cnt].port = atoi((char*)xc); 00255 x->acceptors_cnt++; 00256 } 00257 else if (xmlStrlen(child->name)==4 && ((char*)strncasecmp((char*)child->name,"Auth",4)==0|| 00258 strncasecmp((char*)child->name,"Acct",4)==0)){ 00259 //Application 00260 xc = xmlGetProp(child,(xmlChar*)"id"); 00261 x->applications[x->applications_cnt].id = atoi((char*)xc); 00262 xc = xmlGetProp(child,(xmlChar*)"vendor"); 00263 x->applications[x->applications_cnt].vendor = atoi((char*)xc); 00264 if (child->name[1]=='u'||child->name[1]=='U') 00265 x->applications[x->applications_cnt].type = DP_AUTHORIZATION; 00266 else 00267 x->applications[x->applications_cnt].type = DP_ACCOUNTING; 00268 x->applications_cnt++; 00269 } 00270 else if (xmlStrlen(child->name)==12 && ((char*)strncasecmp((char*)child->name,"DefaultRoute",12)==0)){ 00271 if (!x->r_table) { 00272 x->r_table = shm_malloc(sizeof(routing_table)); 00273 memset(x->r_table,0,sizeof(routing_table)); 00274 } 00275 re = new_routing_entry(); 00276 if (re){ 00277 xc = xmlGetProp(child,(xmlChar*)"FQDN"); 00278 quote_trim_dup(&(re->fqdn),(char*)xc); 00279 xc = xmlGetProp(child,(xmlChar*)"metric"); 00280 re->metric = atoi((char*)xc); 00281 00282 /* add it the list in ascending order */ 00283 if (! x->r_table->routes || re->metric <= x->r_table->routes->metric){ 00284 re->next = x->r_table->routes; 00285 x->r_table->routes = re; 00286 }else{ 00287 for(rei=x->r_table->routes;rei;rei=rei->next) 00288 if (!rei->next){ 00289 rei->next = re; 00290 break; 00291 }else{ 00292 if (re->metric <= rei->next->metric){ 00293 re->next = rei->next; 00294 rei->next = re; 00295 break; 00296 } 00297 } 00298 } 00299 } 00300 } 00301 else if (xmlStrlen(child->name)==5 && ((char*)strncasecmp((char*)child->name,"Realm",5)==0)){ 00302 if (!x->r_table) { 00303 x->r_table = shm_malloc(sizeof(routing_table)); 00304 memset(x->r_table,0,sizeof(routing_table)); 00305 } 00306 rr = new_routing_realm(); 00307 if (rr){ 00308 xc = xmlGetProp(child,(xmlChar*)"name"); 00309 quote_trim_dup(&(rr->realm),(char*)xc); 00310 00311 if (!x->r_table->realms) { 00312 x->r_table->realms = rr; 00313 }else{ 00314 for(rri=x->r_table->realms;rri->next;rri=rri->next); 00315 rri->next = rr; 00316 } 00317 for(nephew = child->children; nephew; nephew = nephew->next) 00318 if (nephew->type == XML_ELEMENT_NODE){ 00319 if (xmlStrlen(nephew->name)==5 && ((char*)strncasecmp((char*)nephew->name,"Route",5)==0)) 00320 { 00321 re = new_routing_entry(); 00322 if (re) { 00323 xc = xmlGetProp(nephew,(xmlChar*)"FQDN"); 00324 quote_trim_dup(&(re->fqdn),(char*)xc); 00325 xc = xmlGetProp(nephew,(xmlChar*)"metric"); 00326 re->metric = atoi((char*)xc); 00327 00328 /* add it the list in ascending order */ 00329 if (! rr->routes || re->metric <= rr->routes->metric){ 00330 re->next = rr->routes; 00331 rr->routes = re; 00332 }else{ 00333 for(rei=rr->routes;rei;rei=rei->next) 00334 if (!rei->next){ 00335 rei->next = re; 00336 break; 00337 }else{ 00338 if (re->metric <= rei->next->metric){ 00339 re->next = rei->next; 00340 rei->next = re; 00341 break; 00342 } 00343 } 00344 } 00345 } 00346 } 00347 } 00348 } 00349 } 00350 } 00351 00352 if (doc) xmlFreeDoc(doc); 00353 parser_destroy(); 00354 return x; 00355 error: 00356 if (doc) xmlFreeDoc(doc); 00357 parser_destroy(); 00358 if (x) free_dp_config(x); 00359 return 0; 00360 }
1.5.2