Example #1
0
void gtk_data_init(SdlGoom *sg) {
  sdlGoom = sg;
  if (sdlGoom->config_win) {
    int i;
    GtkNotebook *notebook;
    owin = GTK_OBJECT(sdlGoom->config_win);
    notebook = GTK_NOTEBOOK(gtk_object_get_data (owin, "notebook1")); 
    addParams (notebook, &sdlGoom->screen);
    for (i = 0; i < sdlGoom->plugin->nbParams; ++i) {
      addParams (notebook, &sdlGoom->plugin->params[i]);
    }
  }
}
Example #2
0
AmSession* DSMFactory::onInvite(const AmSipRequest& req, const string& app_name,
				const map<string,string>& app_params)
{
  string start_diag;
  map<string, string> vars;

  if (app_name == MOD_NAME) {
    if (InboundStartDiag.empty()) {
      ERROR("no inbound calls allowed\n");
      throw AmSession::Exception(488, "Not Acceptable Here");
    }
    if (InboundStartDiag=="$(mon_select)") {
      runMonitorAppSelect(req, start_diag, vars);
    } else {
      start_diag = InboundStartDiag;
    }
  } else {
    start_diag = app_name;
  }

  DBG("start_diag = %s\n",start_diag.c_str());

  // determine run configuration for script
  DSMScriptConfig call_config;
  ScriptConfigs_mut.lock();
  map<string, DSMScriptConfig>::iterator sc=ScriptConfigs.find(start_diag);
  if (sc == ScriptConfigs.end()) 
    call_config = MainScriptConfig;
  else 
    call_config = sc->second;

  DSMCall* s = new DSMCall(call_config, &prompts, *call_config.diags, start_diag, NULL);

  ScriptConfigs_mut.unlock();

  prepareSession(s);
  addVariables(s, "config.", call_config.config_vars);

  if (call_config.SetParamVariables) 
    addParams(s, req.hdrs);

  if (!vars.empty())
    addVariables(s, "", vars);

  return s;
}
Example #3
0
 void MTD_FLASHMEM HTTPTemplateResponse::processFileRequest()
 {
     char const* mimetype;
     void const* data;
     uint16_t dataLength;
     if (m_filename && FlashFileSystem::find(m_filename, &mimetype, &data, &dataLength))
     {
         // found
         setStatus(STR_200_OK);
         addHeader(STR_Content_Type, FSTR("text/html"));
         
         // replace parameters
         ParameterReplacer replacer((char const*)data, (char const*)data + dataLength, &m_params);
         
         // is this a specialized file (contains {%..%} blocks)?
         if (replacer.getBlocks()->getItemsCount() > 0 && replacer.getTemplateFilename() != NULL)
         {
             // this is a specialized file, add blocks as parameters
             addParams(replacer.getBlocks());
             // load template file
             if (FlashFileSystem::find(replacer.getTemplateFilename(), &mimetype, &data, &dataLength))
             {
                 // replace parameters and blocks of template file
                 ParameterReplacer templateReplacer((char const*)data, (char const*)data + dataLength, &m_params);
                 // flush resulting content
                 addContent(templateReplacer.getResult());
                 return;
             }
         }
         else
         {
             // just flush this file (contains only {{...}} blocks)
             addContent(replacer.getResult());
             return;
         }
     }
     // not found
     setStatus(STR_404_Not_Fount);
 }
bool HTTPServerRequest::parse()
{
	// TODO: doing it this way is very hacky as it means we lose blank lines (end of header, etc)...
	std::vector<std::string> lines;
	split(m_request, lines);
	
	if (lines.empty())
		return false;
	
	// first line should contain main request
	const std::string &line = lines[0];
	
	if (line.find("HTTP/") == -1)
		return false;
	
	if (line.substr(0, 3) != "GET")
	{
		if (line.substr(0, 4) != "POST")
			return false;
		
		m_post = true;
	}
	
	int pathStart = m_post ? 5 : 4;
	
	int pathEnd = line.rfind(" "); // should be the space before the HTTP version
	
	if (pathEnd == -1)
		return false;
	
	const std::string path = line.substr(pathStart, pathEnd - pathStart);
	
	int nQuestionMark = path.find("?");
	if (nQuestionMark == -1)
	{
		m_path = path;
	}
	else
	{
		m_path = path.substr(0, nQuestionMark);
		
		// if POST has this on the end, ignore the URL params
		if (!m_post)
		{
			std::string params = path.substr(nQuestionMark + 1);
		
			addParams(params);
		}
	}
	
	// now try and find an authentication line...
	std::vector<std::string>::const_iterator itLine = lines.begin();
	++ itLine; // skip the first line which we've processed already
	for (; itLine != lines.end(); ++itLine)
	{
		const std::string& otherLine = *itLine;
		
		if (otherLine.compare(0, 14, "Authorization:") == 0)
		{
			std::string authorizationString = otherLine.substr(15);
			
			size_t sepPos = authorizationString.find(" ");
			if (sepPos == std::string::npos)
			{
				m_authenticationHeaderType = eAuthMalformed;
				break;
			}
			
			std::string authenticationType = authorizationString.substr(0, sepPos);
			
			if (authenticationType != "Basic")
			{
				m_authenticationHeaderType = eAuthUnknown;
				break;
			}
			
			m_authenticationHeaderType = eAuthBasic;
			
			std::string authorizationToken = authorizationString.substr(sepPos + 1);
			
			// remove any trailing "\r" char
			if (authorizationToken[authorizationToken.size() - 1] == '\r')
			{
				authorizationToken = authorizationToken.substr(0, authorizationToken.size() - 1);
			}
			
			authorizationToken = base64Decode(authorizationToken);
			
			if (m_authenticationHeaderType == eAuthBasic)
			{
				size_t passSep = authorizationToken.find(":");
				if (passSep == std::string::npos)
				{
					m_authenticationHeaderType = eAuthMalformed;
					break;
				}
				
				std::string authUser = authorizationToken.substr(0, passSep);
				std::string authPass = authorizationToken.substr(passSep + 1);
				
				m_authUsername = authUser;
				m_authPassword = authPass;
			}
			
			break;
		}
	}
	
	// TODO: this is crap - we should check for the double CR and use that to detect the end of the header...
	//       or as a hacky stop-gap to be more robust (and detect missing POST data), match the line
	//       by the Content-Length....
	if (m_post && lines.size() > 1)
	{
		// hopefully, last line of HTTP request should be the POST params
		
		const std::string& params = lines.back();

		// Note: Sometimes we don't seem to have any POST data...
		// WebKit in embedded mode (Web (Epiphany 3.8.2?) on Raspberry Pi) appears to have this bug:
		// WebKit BZ: 145410 - which strips off POST data when submitting it.
		// Firefox and Chrome (Linux, OS X and Pi) work fine as does Safari on OS X.
		
		addParams(params);
	}
	
	return true;
}
Example #5
0
// outgoing call
AmSession* DSMFactory::onInvite(const AmSipRequest& req,
				AmArg& session_params) 
{

  string start_diag;

  if (req.cmd == MOD_NAME) {
    if (OutboundStartDiag.empty()) {
      ERROR("no outbound calls allowed\n");
    throw AmSession::Exception(488, "Not Acceptable Here");
    }
  } else {
    start_diag = req.cmd;
  }

  UACAuthCred* cred = NULL;
  map<string, string> vars;
  // Creds
  if (session_params.getType() == AmArg::AObject) {
    ArgObject* cred_obj = session_params.asObject();
    if (cred_obj)
      cred = dynamic_cast<UACAuthCred*>(cred_obj);
  } else if (session_params.getType() == AmArg::Array) {
    DBG("session params is array - size %d\n", session_params.size());
    // Creds
    if (session_params.get(0).getType() == AmArg::AObject) {
      ArgObject* cred_obj = session_params.get(0).asObject();
      if (cred_obj)
	cred = dynamic_cast<UACAuthCred*>(cred_obj);
    }
    // Creds + vars
    if (session_params.size()>1 && 
	session_params.get(1).getType() == AmArg::Struct) {
      AmArg2DSMStrMap(session_params.get(1), vars);
    }
  } else if (session_params.getType() == AmArg::Struct) {
    // vars
    AmArg2DSMStrMap(session_params, vars);
  }

  DSMScriptConfig call_config;
  ScriptConfigs_mut.lock();
  map<string, DSMScriptConfig>::iterator sc=ScriptConfigs.find(start_diag);
  if (sc == ScriptConfigs.end())
    call_config = MainScriptConfig;
  else 
    call_config = sc->second;

  DSMCall* s = new DSMCall(call_config, &prompts, *call_config.diags, start_diag, cred); 

  ScriptConfigs_mut.unlock();

  prepareSession(s);  

  addVariables(s, "config.", call_config.config_vars);
  if (!vars.empty())
    addVariables(s, "", vars);

  if (call_config.SetParamVariables) 
    addParams(s, req.hdrs); 

  if (NULL == cred) {
    WARN("discarding unknown session parameters.\n");
  } else {
    AmSessionEventHandlerFactory* uac_auth_f = 
      AmPlugIn::instance()->getFactory4Seh("uac_auth");
    if (uac_auth_f != NULL) {
      DBG("UAC Auth enabled for new DSM session.\n");
      AmSessionEventHandler* h = uac_auth_f->getHandler(s);
      if (h != NULL )
	s->addHandler(h);
    } else {
      ERROR("uac_auth interface not accessible. "
	    "Load uac_auth for authenticated dialout.\n");
    }		
  }

  return s;
}
Example #6
0
AmSession* DSMFactory::onInvite(const AmSipRequest& req)
{
  string start_diag;
  map<string, string> vars;

  if (req.cmd == MOD_NAME) {
    if (InboundStartDiag.empty()) {
      ERROR("no inbound calls allowed\n");
      throw AmSession::Exception(488, "Not Acceptable Here");
    }
    if (InboundStartDiag=="$(mon_select)") {
#ifdef USE_MONITORING

      if (NULL == MONITORING_GLOBAL_INTERFACE) {
	ERROR("using $(mon_select) but monitoring not loaded\n");
	throw AmSession::Exception(488, "Not Acceptable Here");
      }

      AmArg di_args, ret;
      if (MonSelectCaller != MonSelect_NONE) {
	AmUriParser from_parser;
	if (MonSelectCaller == MonSelect_FROM)
	  from_parser.uri = req.from_uri;
	else {
	  size_t end;
	  string pai = getHeader(req.hdrs, SIP_HDR_P_ASSERTED_IDENTITY);
	  if (!from_parser.parse_contact(pai, 0, end)) {
	    ERROR("Failed to parse "SIP_HDR_P_ASSERTED_IDENTITY " '%s'\n",
		  pai.c_str());
	    throw AmSession::Exception(488, "Not Acceptable Here");
	  }
	}

	if (!from_parser.parse_uri()) {
	  DBG("failed to parse caller uri '%s'\n", from_parser.uri.c_str());
	  throw AmSession::Exception(488, "Not Acceptable Here");
	}
	
	AmArg caller_filter;
	caller_filter.push("caller");
	caller_filter.push(from_parser.uri_user);
	DBG(" && looking for caller=='%s'\n", from_parser.uri_user.c_str());
	di_args.push(caller_filter);
      }


      if (MonSelectCallee != MonSelect_NONE) {
	AmArg callee_filter;
	callee_filter.push("callee");
	if (MonSelectCallee == MonSelect_RURI)
	  callee_filter.push(req.user);
	else {
	  AmUriParser to_parser;
	  size_t end;
	  if (!to_parser.parse_contact(req.to, 0, end)) {
	    ERROR("Failed to parse To '%s'\n", req.to.c_str());
	    throw AmSession::Exception(488, "Not Acceptable Here");
	  }
	  if (!to_parser.parse_uri()) {
	    DBG("failed to parse callee uri '%s'\n", to_parser.uri.c_str());
	    throw AmSession::Exception(488, "Not Acceptable Here");
	  }
	  callee_filter.push(to_parser.uri_user);
	}
	  
	DBG(" && looking for callee=='%s'\n", req.user.c_str());
	di_args.push(callee_filter);	
      }
      MONITORING_GLOBAL_INTERFACE->invoke("listByFilter",di_args,ret);
      
      if ((ret.getType()!=AmArg::Array)||
	  !ret.size()) {
	INFO("call info not found. caller uri %s, r-uri %s\n", 
	     req.from_uri.c_str(), req.r_uri.c_str());
	throw AmSession::Exception(488, "Not Acceptable Here");
      }

      AmArg sess_id, sess_params;
      if (ret.size()>1) {
	DBG("multiple call info found - picking the first one\n");
      }
      const char* session_id = ret.get(0).asCStr();
      sess_id.push(session_id);
      MONITORING_GLOBAL_INTERFACE->invoke("get",sess_id,sess_params);
      
      if ((sess_params.getType()!=AmArg::Array)||
	  !sess_params.size() ||
	  sess_params.get(0).getType() != AmArg::Struct) {
	INFO("call parameters not found. caller uri %s, r-uri %s, id %s\n", 
	     req.from_uri.c_str(), req.r_uri.c_str(), ret.get(0).asCStr());
	throw AmSession::Exception(488, "Not Acceptable Here");
      }

      AmArg& sess_dict = sess_params.get(0);
      if (sess_dict.hasMember("app")) {
	start_diag = sess_dict["app"].asCStr();
	DBG("selected application '%s' for session\n", start_diag.c_str());
      } else {
	ERROR("selected session params don't contain 'app'\n");
	throw AmSession::Exception(488, "Not Acceptable Here");
      }
      AmArg2DSMStrMap(sess_dict["appParams"], vars);
      vars["mon_session_record"] = session_id;
	
#else
      ERROR("using $(mon_select) for dsm application, "
	    "but compiled without monitoring support!\n");
      throw AmSession::Exception(488, "Not Acceptable Here");
#endif
    } else {
      start_diag = InboundStartDiag;
    }
  } else {
    start_diag = req.cmd;
  }

  // determine run configuration for script
  DSMScriptConfig call_config;
  ScriptConfigs_mut.lock();
  map<string, DSMScriptConfig>::iterator sc=ScriptConfigs.find(start_diag);
  if (sc == ScriptConfigs.end()) 
    call_config = MainScriptConfig;
  else 
    call_config = sc->second;

  DSMCall* s = new DSMCall(call_config, &prompts, *call_config.diags, start_diag, NULL);

  ScriptConfigs_mut.unlock();

  prepareSession(s);
  addVariables(s, "config.", call_config.config_vars);

  if (call_config.SetParamVariables) 
    addParams(s, req.hdrs);

  if (!vars.empty())
    addVariables(s, "", vars);

  return s;
}
actualParamsNode::actualParamsNode(ExpressionASTNode *param) {
	actualParams = new deque<ExpressionASTNode*>();
	addParams(param);
}
Example #8
0
// outgoing call
AmSession* DSMFactory::onInvite(const AmSipRequest& req, const string& app_name,
				AmArg& session_params) 
{

  string start_diag;

  if (app_name == MOD_NAME) {
    if (OutboundStartDiag.empty()) {
      ERROR("no outbound calls allowed\n");
      throw AmSession::Exception(488, "Not Acceptable Here");
    }
  } else {
    start_diag = app_name;
  }

  UACAuthCred* cred = NULL;
  map<string, string> vars;
  // Creds
  if (session_params.getType() == AmArg::AObject) {
    AmObject* cred_obj = session_params.asObject();
    if (cred_obj)
      cred = dynamic_cast<UACAuthCred*>(cred_obj);
  } else if (session_params.getType() == AmArg::Array) {
    DBG("session params is array - size %zd\n", session_params.size());
    // Creds
    cred = AmUACAuth::unpackCredentials(session_params.get(0));
    // Creds + vars
    if (session_params.size()>1 && 
	session_params.get(1).getType() == AmArg::Struct) {
      AmArg2DSMStrMap(session_params.get(1), vars);
    }
  } else if (session_params.getType() == AmArg::Struct) {
    // vars
    AmArg2DSMStrMap(session_params, vars);
  }

  DSMScriptConfig call_config;
  ScriptConfigs_mut.lock();
  map<string, DSMScriptConfig>::iterator sc=ScriptConfigs.find(start_diag);
  if (sc == ScriptConfigs.end())
    call_config = MainScriptConfig;
  else 
    call_config = sc->second;

  DSMCall* s = new DSMCall(call_config, &prompts, *call_config.diags, start_diag, cred); 

  ScriptConfigs_mut.unlock();

  prepareSession(s);  

  addVariables(s, "config.", call_config.config_vars);
  if (!vars.empty())
    addVariables(s, "", vars);

  if (call_config.SetParamVariables) 
    addParams(s, req.hdrs); 

  if (NULL == cred) {
    DBG("outgoing DSM call will not be authenticated.\n");
  } else {
    AmUACAuth::enable(s);
  }

  return s;
}