Exemplo n.º 1
0
xstring inetAddrToString(sockaddr_in* sin)
{
	TCHAR buff[MAX_PATH] = {};
	DWORD buffLen = MAX_PATH;
	if (SOCKET_ERROR == WSAAddressToString(reinterpret_cast<sockaddr*>(sin), sizeof(sockaddr_in), nullptr, buff, &buffLen))
	{
		return xstring();
	}
	return xstring(buff);
}
Exemplo n.º 2
0
inline std::string xstring(const char* xstr, std::size_t n)
{
    std::string result;

    xstring(xstr, n, std::back_inserter(result));

    return result;
}
Exemplo n.º 3
0
xstring xformat(const wchar_t* fmt, ...)
{
	static const size_t kBuffSize = 4096 * 4096;
	std::vector<wchar_t> buff(kBuffSize, '\0');
	va_list v;
	va_start(v, fmt);
	_vsnwprintf_s(&buff[0], kBuffSize, _TRUNCATE, fmt, v);
	va_end(v);
	return xstring(&buff[0]);
}
Exemplo n.º 4
0
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
	WindowsInitialization();

	gen_tabs();								// initialize AES tables
	CheckSpecialArgs();						// handle commandline

	std::auto_ptr<document::Document>	doc(new document::Document);

	if(g_documentFilePath.empty())
	{
		// haven't got a filename, check for embedded data. If we've got embedded data,
		// make a temp copy of our exe, and launch that with "-edit". If no embedded data,
		// we'll end up with a blank note instead.

		FileEndData::FileEndData fed( xstring(g_moduleName), true );
		if(fed.HasData())
			return CopyAndSpawn() ? 0 : -1;
	} else
	{
		// We've got a filename from commandline, work with that file.
		if(!CheckAndLoadEmbeddedDocument(g_documentFilePath, doc))
		{
			util::error_box(strErrorLoad);
			return -1;
		}
	}

	// Now doc is either loaded from our own executable, or blank - start the editor.
	editor::Editor edit(doc);

	if(!g_documentFilePath.empty())
		edit.UpdateTitle(g_documentFilePath.c_str());

	MessageLoop(edit.GetHWND());

	if(g_editorMode)
	{
		// We were originally launched with "-edit" argument, which means we're running
		// from a temp file that should be erased. Launch original process to delete temp.
		//TODO: what if a nosy user is messing with commandline args?
		xstring args(_T("-erase:\""));
		args.append(g_moduleName);
		args.append(_T("\""));

		util::launch(g_documentFilePath, args, false);
	}

	return 0;
}
Exemplo n.º 5
0
static xstring
CreateGuid()
{
#if defined(UNICODE)
#define STR    RPC_WSTR
#else
#define STR    RPC_CSTR
#endif
    UUID    uuid;
    xstring result;
    if (UuidCreate(&uuid) == RPC_S_OK) {
        LPTSTR lpResult;
        UuidToString(&uuid, reinterpret_cast<STR *>(&lpResult));
        result = xstring(lpResult);
        RpcStringFree(reinterpret_cast<STR *>(&lpResult));
    }
    return result;
#undef STR
}
Exemplo n.º 6
0
bool CopyAndSpawn()
{
	FileEndData::FileEndData fed( xstring(g_moduleName), true );
	xstring		spawnedEditor;

	//TODO: make sure temp file doesn't already exist!
	spawnedEditor = util::get_temp_name(g_editorTempPath, _T("fSekrit"), _T("exe"));

	if(!util::file_copy_range(spawnedEditor.c_str(), g_moduleName, 0, fed.GetExeSize()) )
	{
		util::error_box(strErrorCopy);
		return false;
	}

	xstring parms(_T("-edit:\""));
	parms.append(g_moduleName);
	parms.append(_T("\""));

	util::launch(spawnedEditor, parms, false);

	return true;
}
Exemplo n.º 7
0
MRESULT LoadWizard::DlgProc(ULONG msg, MPARAM mp1, MPARAM mp2)
{
  switch (msg)
  {case WM_INITDLG:
    { MRESULT ret = IntrospectBase::DlgProc(msg, mp1, mp2);
      SetTitle(Title);
      if (Configuration.SourceServer)
      { ComboBox(+GetCtrl(CB_SERVER)).Text(Configuration.SourceServer);
        PostMsg(UM_CONNECT, 0, 0);
      }
      if (Configuration.Source)
        PMRASSERT(WinSetDlgItemText(GetHwnd(), CB_SINKSRC, Configuration.Source));
      if (Configuration.SourcePort)
        PMRASSERT(WinSetDlgItemText(GetHwnd(), CB_PORT, Configuration.SourcePort));
      // Init rate spin button
      { SpinButton sb(GetCtrl(SB_RATE));
        sb.SetArray(SamplingRates, sizeof SamplingRates/sizeof *SamplingRates);
        size_t pos;
        if ( !binary_search<const char,const int>(Configuration.SourceRate, pos, &SamplingRates[0], sizeof SamplingRates/sizeof *SamplingRates, &SamplingRateCmp)
          && ( pos == sizeof SamplingRates/sizeof *SamplingRates
            || (pos && 2*Configuration.SourceRate < atoi(SamplingRates[pos]) + atoi(SamplingRates[pos-1])) ))
          --pos;
        sb.Value(pos);
      }
      WinCheckButton(GetHwnd(), Configuration.SourceChannels == 1 ? RB_MONO : RB_STEREO, TRUE);
      return ret;
    }

   case WM_COMMAND:
    DEBUGLOG(("LoadWizard::DlgProc:WM_COMMAND(%i,%i, %p)\n", SHORT1FROMMP(mp1), SHORT2FROMMP(mp1), mp2));
    switch (SHORT1FROMMP(mp1))
    {case DID_OK:
      { Configuration.SourceServer = WinQueryDlgItemXText(GetHwnd(), CB_SERVER);
        const xstring& source = WinQueryDlgItemXText(GetHwnd(), CB_SINKSRC);
        Configuration.Source = source.length() && !source.startsWithI("default") ? source : xstring();
        const xstring& port = WinQueryDlgItemXText(GetHwnd(), CB_PORT);
        Configuration.SourcePort = port.length() && !port.startsWithI("default") ? port : xstring();
        Configuration.SourceRate = atoi(SamplingRates[SpinButton(GetCtrl(SB_RATE)).Value()]);
        Configuration.SourceChannels = WinQueryButtonCheckstate(GetHwnd(), RB_MONO) ? 1 : 2;
      }
      break;
    }
    break;

   case UM_DISCOVER_SERVER:
    { DEBUGLOG(("LoadWizard::DlgProc:UM_DISCOVER_SERVER\n"));
      try
      { Context.GetServerInfo(ServerInfoOp);
        Sources.clear();
        Context.GetSourceInfo(SourceInfoOp);
      } catch (const PAException& ex)
      { WinSetDlgItemText(GetHwnd(), ST_STATUS, ex.GetMessage());
      }
      return 0;
    }

   case UM_UPDATE_SERVER:
    { int error = LONGFROMMP(mp1);
      DEBUGLOG(("LoadWizard::DlgProc:UM_UPDATE_SERVER %i\n", error));
      if (error)
      { WinSetDlgItemText(GetHwnd(), ST_STATUS, PAConnectException(Context.GetContext(), error).GetMessage());
        return 0;
      }
      WinSetDlgItemText(GetHwnd(), ST_STATUS, "Success");
      ComboBox cb(GetCtrl(CB_SINKSRC));
      // save old value
      const xstring& oldsink = cb.Text();
      // delete old list
      cb.DeleteAll();
      SelectedSource = -1;
      // insert new list and restore old value if reasonable.
      xstring def;
      def.sprintf("default (%s)", Server.default_sink_name.cdata());
      cb.InsertItem(def);
      if (Sources.size() != 0)
      { int defsink = -1;
        for (unsigned i = 0; i < Sources.size(); ++i)
        { PASourceInfo& source = *Sources[i];
          cb.InsertItem(source.name);
          if (SelectedSource < 0 && source.name.compareToI(oldsink) == 0)
            SelectedSource = i;
          if (defsink < 0 && source.name.compareToI(Server.default_sink_name) == 0)
            defsink = i;
        }
        cb.Select(SelectedSource+1);
        if (SelectedSource < 0)
          SelectedSource = defsink;
      }
    }
   case UM_UPDATE_PORT:
    { DEBUGLOG(("LoadWizard::DlgProc:UM_UPDATE_PORT %i\n", SelectedSource));
      ComboBox cb(GetCtrl(CB_PORT));
      // save old value
      const xstring& oldport = cb.Text();
      // delete old list
      cb.DeleteAll();
      // insert new list and restore old value if reasonable.
      xstring def;
      int selected = -1;
      if ((unsigned)SelectedSource < Sources.size())
      { PASourceInfo& source = *Sources[SelectedSource];
        if (source.active_port)
          def.sprintf("default (%s)", source.active_port->name.cdata());
        for (unsigned i = 0; i < source.ports.size(); ++i)
        { PAPortInfo& port = source.ports[i];
          cb.InsertItem(port.name);
          if (selected < 0 && port.name.compareToI(oldport) == 0)
            selected = i;
        }
      }
      cb.InsertItem(def ? def.cdata() : "default", 0);
      cb.Select(selected+1);
      return 0;
    }
  }
  return IntrospectBase::DlgProc(msg, mp1, mp2);
}
Exemplo n.º 8
0
MRESULT ConfigDialog::DlgProc(ULONG msg, MPARAM mp1, MPARAM mp2)
{
  switch (msg)
  {case WM_INITDLG:
    { MRESULT ret = IntrospectBase::DlgProc(msg, mp1, mp2);
      if (Configuration.Sink)
        PMRASSERT(WinSetDlgItemText(GetHwnd(), CB_SINKSRC, Configuration.Sink));
      if (Configuration.SinkPort)
        PMRASSERT(WinSetDlgItemText(GetHwnd(), CB_PORT, Configuration.SinkPort));
      // Set current value
      if (Configuration.SinkServer)
      { ComboBox(+GetCtrl(CB_SERVER)).Text(Configuration.SinkServer);
        PostMsg(UM_CONNECT, 0, 0);
      }
      SpinButton sb(GetCtrl(SB_MINLATENCY));
      sb.SetLimits(0, 5000, 4);
      sb.Value(Configuration.SinkMinLatency);
      sb = SpinButton(GetCtrl(SB_MAXLATENCY));
      sb.SetLimits(100, 10000, 4);
      sb.Value(Configuration.SinkMaxLatency);
      return ret;
    }

   case WM_COMMAND:
    DEBUGLOG(("ConfigDialog::DlgProc:WM_COMMAND(%i,%i, %p)\n", SHORT1FROMMP(mp1), SHORT2FROMMP(mp1), mp2));
    switch (SHORT1FROMMP(mp1))
    {case DID_OK:
      { Configuration.SinkServer = WinQueryDlgItemXText(GetHwnd(), CB_SERVER);
        const xstring& sink = WinQueryDlgItemXText(GetHwnd(), CB_SINKSRC);
        Configuration.Sink = sink.length() && !sink.startsWithI("default") ? sink : xstring();
        const xstring& port = WinQueryDlgItemXText(GetHwnd(), CB_PORT);
        Configuration.SinkPort = port.length() && !port.startsWithI("default") ? port : xstring();
        Configuration.SinkMinLatency = SpinButton(GetCtrl(SB_MINLATENCY)).Value();
        Configuration.SinkMaxLatency = SpinButton(GetCtrl(SB_MAXLATENCY)).Value();
      }
      break;
    }
    break;

   case UM_DISCOVER_SERVER:
    { DEBUGLOG(("ConfigDialog::DlgProc:UM_DISCOVER_SERVER\n"));
      try
      { Context.GetServerInfo(ServerInfoOp);
        Sinks.clear();
        Context.GetSinkInfo(SinkInfoOp);
      } catch (const PAException& ex)
      { WinSetDlgItemText(GetHwnd(), ST_STATUS, ex.GetMessage());
      }
      return 0;
    }

   case UM_UPDATE_SERVER:
    { int error = LONGFROMMP(mp1);
      DEBUGLOG(("ConfigDialog::DlgProc:UM_UPDATE_SERVER %i\n", error));
      if (error)
      { WinSetDlgItemText(GetHwnd(), ST_STATUS, PAConnectException(Context.GetContext(), error).GetMessage());
        return 0;
      }
      WinSetDlgItemText(GetHwnd(), ST_STATUS, "Success");
      ComboBox cb(GetCtrl(CB_SINKSRC));
      // save old value
      const xstring& oldsink = cb.Text();
      // delete old list
      cb.DeleteAll();
      SelectedSink = -1;
      // insert new list and restore old value if reasonable.
      xstring def;
      def.sprintf("default (%s)", Server.default_sink_name.cdata());
      cb.InsertItem(def);
      if (Sinks.size() != 0)
      { int defsink = -1;
        for (unsigned i = 0; i < Sinks.size(); ++i)
        { PASinkInfo& sink = *Sinks[i];
          cb.InsertItem(sink.name);
          if (SelectedSink < 0 && sink.name.compareToI(oldsink) == 0)
            SelectedSink = i;
          if (defsink < 0 && sink.name.compareToI(Server.default_sink_name) == 0)
            defsink = i;
        }
        cb.Select(SelectedSink+1);
        if (SelectedSink < 0)
          SelectedSink = defsink;
      }
    }
   case UM_UPDATE_PORT:
    { DEBUGLOG(("ConfigDialog::DlgProc:UM_UPDATE_PORT %i\n", SelectedSink));
      ComboBox cb(GetCtrl(CB_PORT));
      // save old value
      const xstring& oldport = cb.Text();
      // delete old list
      cb.DeleteAll();
      // insert new list and restore old value if reasonable.
      xstring def;
      int selected = -1;
      if ((unsigned)SelectedSink < Sinks.size())
      { PASinkInfo& sink = *Sinks[SelectedSink];
        if (sink.active_port)
          def.sprintf("default (%s)", sink.active_port->name.cdata());
        for (unsigned i = 0; i < sink.ports.size(); ++i)
        { PAPortInfo& port = sink.ports[i];
          cb.InsertItem(port.name);
          if (selected < 0 && port.name.compareToI(oldport) == 0)
            selected = i;
        }
      }
      cb.InsertItem(def ? def.cdata() : "default", 0);
      cb.Select(selected+1);
      return 0;
    }
  }
  return IntrospectBase::DlgProc(msg, mp1, mp2);
}
Exemplo n.º 9
0
 */

#include "config.h"
#include "system.h"

#define err_type_invalid        1
#define err_only_cr             2
#define err_type_not_found      3
#define err_headers_invalid     4
#define err_data_len_invalid    5
#define err_needless_data       6


string_t protocol_err_info[] = {
    string_null,
    xstring("Type is invalid."),
    xstring("Only \"\r\", \"\n\" not found."),
    xstring("Type not found."),
    xstring("Headers are invalid."),
    xstring("Data len is invalid."),
    xstring("Data is needless.")
};

int protocol_init(tcp_request_t *r)
{
    protocol_t *pro;

    pro = pcalloc(r->pool, sizeof(protocol_t));
    if (pro == NULL) {
        return PROTOCOL_ERROR;
    }
Exemplo n.º 10
0
xstring stringset_base::erase(const xstring& item)
{ size_t pos;
  if (locate(item, pos))
    return xstring().fromCstr((const char*)vector_base::erase(pos));
  return xstring();
}
Exemplo n.º 11
0
xstring stringset_base::find(const xstring& item) const
{ size_t pos;
  if (locate(item, pos))
    return (xstring&)vector_base::at(pos);
  return xstring();
}
Exemplo n.º 12
0
static const char* DLLENTRY xstring_create(const char* cstr)
{ return xstring(cstr).toCstr();
}
Exemplo n.º 13
0
inline std::string xstring(const std::string& xstr)
    { return xstring(xstr.c_str(), xstr.size()); }
Exemplo n.º 14
0
inline void xstring(const char* xstr, O output)
    { xstring(xstr, std::strlen(xstr), output); }