00001 #include "../include/plugins/AsteriskPlugin.h"
00002 #include "../include/generic.h"
00003 #include "../include/Configuration.h"
00004 #include <fstream>
00005
00006 namespace plugins
00007 {
00008
00009 AsteriskPlugin::AsteriskPlugin()
00010 {
00011 pluginName = "Asterisk Plugin";
00012 pluginVersion = "1.0";
00013 }
00014
00015 void AsteriskPlugin::LoadConf(string cfile)
00016 {
00017
00018 const char* s[] = {"asterisk"};
00019 const char* v[] = {"ast_pid", "ast_log_path"};
00020 vector<string> sections(s, s + sizeof(s) / sizeof(const char*));
00021 vector<string> vars(v, v + sizeof(v) / sizeof(const char*));
00022
00023 dbg->Prntdbg(CODEAT, 20, "Loading configuration from file: " + cfile);
00024 Configuration astcfg(cfile, dbg, sections, vars);
00025 getAstPID(astcfg.GetValue("ast_pid"));
00026
00027 }
00028
00029 bool AsteriskPlugin::getAstPID(string pidfile)
00030 {
00031 dbg->Prntdbg(CODEAT, 20, "Checking Asterisk PID");
00032 int pl;
00033 char * filecont;
00034
00035
00036 ifstream is;
00037
00038 is.open (pidfile.c_str(), ios::binary );
00039
00040 if (is.fail())
00041 {
00042 dbg->Prnterr(CODEAT, "File " + pidfile + " not exist. Is Asterisk running?");
00043 return false;
00044 }
00045
00046
00047 is.seekg (0, ios::end);
00048 pl = is.tellg();
00049 is.seekg (0, ios::beg);
00050
00051
00052 try {
00053 filecont = new char [pl];
00054 }
00055 catch (std::bad_alloc&)
00056 {
00057 dbg->Prnterr(CODEAT, "Error allocating memory");
00058 return false;
00059 }
00060
00061
00062 is.read (filecont, pl);
00063 is.close();
00064 astpid = filecont;
00065
00066
00067 delete[] filecont;
00068
00069 return true;
00070 }
00071
00072 AsteriskPlugin::~AsteriskPlugin()
00073 {
00074 }
00075
00076 }