Next is a simple example of configuration file for OpenSER that enables accounting of INVITEs and BYEs requests. In this example, the flag number 1 is used to mark the requests to be accounted.
Example 6. accounting config file
--- # # $Id$ # # OpenSER configuration file: accounting calls # # Details about this configuration script # - the accounting information is written to syslog file # - the number of the flag used to mark messages for accounting is 1 # - only the INVITEs and BYEs are accounted # # ----------- global configuration parameters ------------------------ check_via=no # (cmd. line: -v) dns=no # (cmd. line: -r) rev_dns=no # (cmd. line: -R) # ------------------ module loading ---------------------------------- mpath="/usr/local/lib/openser/modules" loadmodule "maxfwd.so" loadmodule "sl.so" loadmodule "rr.so" loadmodule "tm.so" loadmodule "acc.so" # ----------------- setting module-specific parameters --------------- # -- acc params -- # set the reporting log level modparam("acc", "log_level", 1) # number of the flag which will be used to mark messages for accounting modparam("acc", "log_flag", 1 ) # main routing block route{ # --- initial sanity checks --- if (!mf_process_maxfwd_header("10")) { sl_send_reply("483", "Too Many Hops"); return; }; if (msg:len >= 4096) { sl_send_reply("513", "Message too big"); return; }; # subsequent messages withing a dialog should take the # path determined by record-routing if (loose_route()) { # mark the BYEs -- they are requests within a dialog if(method=="BYE") setflag(1); t_relay(); return; }; # process the INVITEs if(method=="INVITE") { # mark the INVITEs for accounting setflag(1); # enforce record-routing so the BYEs will come through this server record_route(); }; # relay the requests if (!t_relay()) { sl_reply_error(); return; }; } ---
Flags may be used to optimize OpenSER's routing logic, avoiding duplicated rutines or executions of same security checks over database.
Example 7. optimization of config file
--- # # $Id$ # # OpenSER configuration file: using flags # # # ----------- global configuration parameters ------------------------ check_via=no # (cmd. line: -v) dns=no # (cmd. line: -r) rev_dns=no # (cmd. line: -R) # ------------------ module loading ---------------------------------- mpath="/usr/local/lib/openser/modules" loadmodule "maxfwd.so" loadmodule "sl.so" loadmodule "rr.so" loadmodule "tm.so" loadmodule "textops.so" loadmodule "group.so" loadmodule "registrar.so" loadmodule "usrloc.so" # ----------------- setting module-specific parameters --------------- # main routing block route{ # --- initial sanity checks --- if !mf_process_maxfwd_header("10")) { sl_send_reply("483", "Too Many Hops"); return; }; if(msg:len >= 4096) { sl_send_reply("513", "Message too big"); return; }; if(uri==myself) { if(method=="REGISTER") { save("location"); return; } if(method=="INVTE" && is_user_in("Request-URI", "voicemail")) setflag(11); if(!lookup("location")) { if(isflagset(11)) t_relay_to_udp("voicemail_ip","voicemail_ip"); else sl_send_reply("404", "Not Found"); return; } if(isflagset(11)) t_on_failure(1); }; # relay the requests if (!t_relay()) { sl_reply_error(); return; }; } failure_route[1] { revert_uri(); t_relay_to_udp("voicemail_ip","voicemail_ip"); } ---