3 from sip_to_pjsip
import convert
13 Write pjsip.sql file to disk 16 with open(filename,
'wt')
as fp:
20 print(
"Could not open file " + filename +
" for writing")
24 Parse command line options and apply them. If invalid input is given, 25 print usage information 35 usage =
"usage: %prog [options] [input-file [output-file]]\n\n" \
36 "Converts the chan_sip configuration input-file to mysql output-file.\n" \
37 "The input-file defaults to 'sip.conf'.\n" \
38 "The output-file defaults to 'pjsip.sql'." 39 parser = optparse.OptionParser(usage=usage)
40 parser.add_option(
'-u',
'--user', dest=
'user', default=
"root",
41 help=
'mysql username')
42 parser.add_option(
'-p',
'--password', dest=
'password', default=
"root",
43 help=
'mysql password')
44 parser.add_option(
'-H',
'--host', dest=
'host', default=
"127.0.0.1",
46 parser.add_option(
'-P',
'--port', dest=
'port', default=
"3306",
47 help=
'mysql port number')
48 parser.add_option(
'-D',
'--database', dest=
'database', default=
"asterisk",
49 help=
'mysql port number')
50 parser.add_option(
'-t',
'--table', dest=
'table', default=
"sippeers",
51 help=
'name of sip realtime peers table')
53 options, args = parser.parse_args()
56 password = options.password
59 database = options.database
62 sip_filename = args[0]
if len(args)
else 'sip.conf' 63 pjsip_filename = args[1]
if len(args) == 2
else 'pjsip.sql' 65 return sip_filename, pjsip_filename
67 if __name__ ==
"__main__":
70 sip_to_pjsip.sip = sip
71 sip.connect(user,password,host,port,database)
72 print(
'Please, report any issue at:')
73 print(
' https://issues.asterisk.org/')
74 print(
'Reading ' + sip_filename)
75 sip.read(sip_filename)
76 print(
'Converting to PJSIP realtime sql...')
77 pjsip, non_mappings =
convert(sip, pjsip_filename, dict(),
False)
78 print(
'Writing ' + pjsip_filename)
def write_pjsip(filename, pjsip, non_mappings)
def convert(sip, filename, non_mappings, include)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)