0

I am using Python KEMI Interpreter and trying to perform a simple SIP registration. But an error occurs, there is an error in the log: ERROR: register [api.c:44]: regapi_save(): usrloc domain [location] not found.

If I use Kamailio native language, registration is successful.

Here is my kamailio.cfg

#!KAMAILIO

debug=2
log_stderror=yes
fork=yes
children=2

memdbg=5
memlog=5

#!define DBURL "mysql://kamailio:xxxxxxxxx@localhost/kamailio"

loadmodule "auth.so"
loadmodule "auth_db.so"
loadmodule "db_mysql.so"
loadmodule "debugger.so"
loadmodule "tm.so"
loadmodule "tmx.so"
loadmodule "pv.so"
loadmodule "textops.so"
loadmodule "sl.so"
loadmodule "usrloc.so"
loadmodule "registrar.so"
loadmodule "ctl.so"
loadmodule "kex.so"
loadmodule "jsonrpcs.so"
loadmodule "nathelper.so"
loadmodule "siputils.so"
loadmodule "rr.so"
loadmodule "xlog.so"
loadmodule "maxfwd.so"
loadmodule "pv_headers.so"
loadmodule "acc.so"
loadmodule "kemix.so"
loadmodule "regex.so"
loadmodule "sanity.so"
loadmodule "path.so"

modparam("xlog", "force_color", 1)
modparam("xlog", "prefix", "-xlog: ")

loadmodule "app_python3.so"
modparam("app_python3", "load", "/etc/kamailio/kemi.py")
cfgengine "python"          

modparam("auth_db", "db_url", DBURL);

modparam("usrloc", "db_url", DBURL);
modparam("usrloc", "db_mode", 1);

// request_route {
//         if (is_method("REGISTER")) {
//                 route(AUTH);
//         }
// }

// route[AUTH] {
//             xlog("L_INFO", "\nfd =  $fd\nru = $ru\nuri = $var(uri)\n");
//             if (!auth_check("$fd", "subscriber", "1")) {
//                     force_rport();
//                     auth_challenge("$fd", "1");
//                     exit;
//             }
//             force_rport();
//             save("location");
//             exit;
// }

Here is a part of my kemi.py

def mod_init():
    KSR.info("===== from Python mod init\n")
    return kamailio()

# -- {start defining kamailio class}
class kamailio:

    # to handle loading of the class
    def __init__(self):
        KSR.info('===== kamailio.__init__\n')
        self.db = DataBase()

    # executed when kamailio child processes are initialized
    # for handling child processes
    def child_init(self, rank):
        KSR.info('===== kamailio.child_init(%d)\n' % rank)
        return 0

    # SIP request routing
    # -- equivalent of request_route{}
    # to handle the initial requests
    def ksr_request_route(self, msg):
        if KSR.is_method("REGISTER"):
            fd = KSR.pv.get("$fd")
            KSR.info("\nfd = %s" % fd+"\n")

            is_registered = KSR.auth_db.auth_check(fd, "subscriber", 1)
            if is_registered < 0:
                KSR.force_rport()
                auth_challenge = KSR.auth.auth_challenge(fd, 1)
                exit()
                
            KSR.force_rport()
            if not KSR.registrar.save("location", 0x01):
                KSR.sl.sl_reply_error()
            return 1
Adriaan
  • 17,741
  • 7
  • 42
  • 75
KPA
  • 1
  • 1
    Welcome to Stack Overflow! Please remember that Stack Overflow is not your favourite Python forum, but rather a question and answer site for all programming related questions. Thus, always include the tag of the language you are programming in, that way other users familiar with that language can more easily find your question. Take the [tour] and read up on [ask] to get more information on how this site works, then [edit] the question with the relevant tags. – Adriaan Apr 18 '23 at 11:12
  • Also note that [posts on Stack Overflow have to be in English](/help/non-english-questions). Bilingual posts aren't allowed either. Keep content in English here, or, if you feel more comfortable writing in Russian, try [ru.so]. – Adriaan Apr 18 '23 at 11:12

0 Answers0