From 98bf08bdcf2edd9d397f32650a8bfe62186fbecf Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Sun, 9 Feb 2014 11:50:07 +0100 Subject: baresip 0.4.10 --- modules/account/account.c | 155 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 modules/account/account.c (limited to 'modules/account/account.c') diff --git a/modules/account/account.c b/modules/account/account.c new file mode 100644 index 0000000..03b6c12 --- /dev/null +++ b/modules/account/account.c @@ -0,0 +1,155 @@ +/** + * @file account/account.c Load SIP accounts from file + * + * Copyright (C) 2010 Creytiv.com + */ +#include +#include + + +static int account_write_template(const char *file) +{ + FILE *f = NULL; + const char *login, *pass, *domain; + + info("account: creating accounts template %s\n", file); + + f = fopen(file, "w"); + if (!f) + return errno; + + login = pass = sys_username(); + if (!login) { + login = "user"; + pass = "pass"; + } + + domain = net_domain(); + if (!domain) + domain = "domain"; + + (void)re_fprintf(f, + "#\n" + "# SIP accounts - one account per line\n" + "#\n" + "# Displayname ;addr-params\n" + "#\n" + "# uri-params:\n" + "# ;transport={udp,tcp,tls}\n" + "#\n" + "# addr-params:\n" + "# ;answermode={manual,early,auto}\n" + "# ;audio_codecs=speex/16000,pcma,...\n" + "# ;auth_user=username\n" + "# ;mediaenc={srtp,srtp-mand,srtp-mandf" + ",dtls_srtp,zrtp}\n" + "# ;medianat={stun,turn,ice}\n" + "# ;outbound=sip:primary.example.com\n" + "# ;outbound2=sip:secondary.example.com\n" + "# ;ptime={10,20,30,40,...}\n" + "# ;regint=3600\n" + "# ;regq=0.5\n" + "# ;rtpkeep={zero,stun,dyna,rtcp}\n" + "# ;sipnat={outbound}\n" + "# ;stunserver=stun:[user:pass]@host[:port]\n" + "# ;video_codecs=h264,h263,...\n" + "#\n" + "# Examples:\n" + "#\n" + "# \n" + "# \n" + "# \n" + "#\n" + "\n", login, pass, domain); + + if (f) + (void)fclose(f); + + return 0; +} + + +/** + * Add a User-Agent (UA) + * + * @param addr SIP Address string + * + * @return 0 if success, otherwise errorcode + */ +static int line_handler(const struct pl *addr) +{ + char buf[512]; + + (void)pl_strcpy(addr, buf, sizeof(buf)); + + return ua_alloc(NULL, buf); +} + + +/** + * Read the SIP accounts from the ~/.baresip/accounts file + * + * @return 0 if success, otherwise errorcode + */ +static int account_read_file(void) +{ + char path[256] = "", file[256] = ""; + uint32_t n; + int err; + + err = conf_path_get(path, sizeof(path)); + if (err) { + warning("account: conf_path_get (%m)\n", err); + return err; + } + + if (re_snprintf(file, sizeof(file), "%s/accounts", path) < 0) + return ENOMEM; + + if (!conf_fileexist(file)) { + + (void)fs_mkdir(path, 0700); + + err = account_write_template(file); + if (err) + return err; + } + + err = conf_parse(file, line_handler); + if (err) + return err; + + n = list_count(uag_list()); + info("Populated %u account%s\n", n, 1==n ? "" : "s"); + + if (list_isempty(uag_list())) { + warning("account: No SIP accounts found" + " -- check your config\n"); + return ENOENT; + } + + return 0; +} + + +static int module_init(void) +{ + return account_read_file(); +} + + +static int module_close(void) +{ + return 0; +} + + +const struct mod_export DECL_EXPORTS(account) = { + "account", + "application", + module_init, + module_close +}; -- cgit v1.2.3