FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

GitHub Viewer

/* cppagi.cpp Robert Oliveira, 2005.02.03 olivecoder@gmail.com */ #include #include #include #include #include #include #include "cppagi.h" agi::agi() { char line[256]; int max=200; AGI_LOG("agi constructor", AGI_INFO); setlinebuf(stdout); setlinebuf(stderr); while ( cin && max-- ) { cin.getline(line,sizeof(line)-1); if ( strlen(line)==0 ) break; environment.push_back(line); } hangup_detected=false; clear(); } agi::~agi() { AGI_LOG("agi destructor", AGI_INFO); } char char_toupper(char c) { return std::toupper(c); } string agi::upper(const string &s) { string result=s; transform(result.begin(), result.end(), result.begin(), char_toupper); return result; } void agi::log(const string& message, int verbosity, const string &file, const string &function, int line ) { string where, msg; #ifdef DEBUG char strline[16]; snprintf(strline,sizeof(strline),"%d",line); where = file + ", "; where += function + "("; where += strline; where += ")\t"; msg = where + message; #else msg = message; #endif verbose(agi::ltime() + " " + msg, verbosity); } agi_error agi::error( const string& msg, const string& file, const string& function, int line) { agi_error newError(*this, msg, file, function, line); return newError; } string agi::getEnv(const string &varname) { vector::iterator i; string uppervarname; size_t p; uppervarname = upper(varname); for( i=environment.begin(); i!=environment.end(); i++ ) { p = i->find(':',0); if ( p!=string::npos && p!=0 ) { if ( upper(i->substr(0,p))==uppervarname ) { p++; p++; if ( p < i->size() ) { return i->substr( p, i->size() - p ); } } } } AGI_LOG("variable \""+varname+"\" not found!",AGI_WARNING); return ""; } string agi::ltime(time_t t) { tm *ptm; char strtime[64]; if (t==0) t=time(NULL); ptm=localtime(&t); snprintf(strtime,sizeof(strtime),"%02d.%02d.%02d %02d:%02d:%02d", ptm->tm_year-100,ptm->tm_mon,ptm->tm_mday, ptm->tm_hour,ptm->tm_min,ptm->tm_sec); return string(strtime); } void agi::clear(void) { code=AGI_CODEOK; result=0; dtmf_buffer=""; } int agi::exec(const string &command) { execCommand = command; cout

Back | FazBrowse Home | New Git URL