コード例 #1
0
ファイル: polls.cpp プロジェクト: LuckyGeck/EPoll
void TPolls::PollCreate(fastcgi::Request *request, fastcgi::HandlerContext *context) {
    std::string inputJson;
    request->requestBody().toString(inputJson);
    rapidjson::Document document;
    document.Parse(inputJson.c_str());
    if (!(document.HasMember("description") && document["description"].IsString() &&
          document.HasMember("options") && document["options"].IsArray() &&
          document["options"].Size() > 0))
    {
        request->setStatus(400);
        return;
    }
    TPollInfo pollInfo;
    pollInfo.PollId = GenerateGUID();
    pollInfo.Description = document["description"].GetString();
    pollInfo.Date = NTime::GetCurrectTime();
    const auto& opts = document["options"];
    for (size_t optionIdx = 0; optionIdx < opts.Size(); ++optionIdx) {
        const auto& curOption = opts[optionIdx];
        if (!curOption.IsString()) {
            request->setStatus(400);
            return;
        }
        pollInfo.Options.emplace_back(curOption.GetString());
    }
    Storage->CreatePoll(pollInfo);
    request->setStatus(201);
    request->setHeader("Location", "/polls/" + pollInfo.PollId);
}
コード例 #2
0
ファイル: SQLFunctions.cpp プロジェクト: Andrel322/gecko-dev
NS_IMETHODIMP
GenerateGUIDFunction::OnFunctionCall(mozIStorageValueArray *aArguments,
                                     nsIVariant **_result)
{
  nsAutoCString guid;
  nsresult rv = GenerateGUID(guid);
  NS_ENSURE_SUCCESS(rv, rv);

  NS_ADDREF(*_result = new mozilla::storage::UTF8TextVariant(guid));
  return NS_OK;
}
コード例 #3
0
//  ---------------------------------------------------------------------------
CUIBase* CUIWidgetManager::CreateWidget(
		CUIBase*		 pParent,
		CUI_WIDGETTYPE	 type, 
		CUIRECT*		 pRect, 
		CUIBase*		 pRelativeTo,
		uint32			 flags)
{
	
	CUIBase*	pWidget = NULL;
	CUIGUID		guid   = GenerateGUID();
	
	CUIRECT		rect;
	memcpy(&rect, pRect, sizeof(CUIRECT));

	if (!m_bInitted) {
		CUI_ERR("WidgetManager was never Initialized!\n");
		return NULL;
	}

	// what type of widget is the caller asking for?
	switch (type) {
		
		case CUIW_WINDOW:
			LT_MEM_TRACK_ALLOC(pWidget = new CUIWindow(guid, m_CurrentSkin, NULL),LT_MEM_TYPE_UI);
			break;
			
		case CUIW_STATICTEXT:
			LT_MEM_TRACK_ALLOC(pWidget = new CUIStaticText(guid),LT_MEM_TYPE_UI);
			break;
			
		case CUIW_STATICIMAGE:
			LT_MEM_TRACK_ALLOC(pWidget = new CUIStaticImage(guid),LT_MEM_TYPE_UI);
			break;
		
		case CUIW_BUTTON:	
			LT_MEM_TRACK_ALLOC(pWidget = new CUIButton(guid),LT_MEM_TYPE_UI);
			break;

		case CUIW_SLIDER:	
			LT_MEM_TRACK_ALLOC(pWidget = new CUISlider(guid),LT_MEM_TYPE_UI);
			break;

		case CUIW_PROGRESS:	
			LT_MEM_TRACK_ALLOC(pWidget = new CUIProgress(guid),LT_MEM_TYPE_UI);
			break;

		case CUIW_CHECK:	
			LT_MEM_TRACK_ALLOC(pWidget = new CUICheck(guid),LT_MEM_TYPE_UI);
			break;

		case CUIW_OPTION:	
			LT_MEM_TRACK_ALLOC(pWidget = new CUIOption(guid),LT_MEM_TYPE_UI);
			break;

		case CUIW_LIST:	
			LT_MEM_TRACK_ALLOC(pWidget = new CUIList(guid),LT_MEM_TYPE_UI);
			break;

		case CUIW_DROPDOWNLIST:	
			LT_MEM_TRACK_ALLOC(pWidget = new CUIDropDownList(guid),LT_MEM_TYPE_UI);
			break;
			
		default:
			CUI_ERR("CreateWidget got unknown CUI_WIDGETTYPE.\n");
	}
		
	if (!pWidget) {
		CUI_ERR("Could not allocate new widget\n");
		return NULL;
	}
	
		
	// SKINZ!!
	/*
	if (m_CurrentSkin) {
		
		
		switch (type) {

			case CUIW_WINDOW:
							
				break;

			case CUIW_STATICTEXT:
				
				break;

			case CUIW_CURSOR:
				
				break;

			case CUIW_BUTTON:	
				
				break;

		}
	}
	*/
	
	// set some common members
	
	// must set the parent first, because some members depend on it,
	// list position
	pWidget->SetParent(pParent);

	/*
	if (pParent) {
		// UI Widgets are initially positioned relatively to their parents
		CUIRECT ParentRect;
		pParent->GetRect(&ParentRect, CUIP_SCREEN);

		rect.x += ParentRect.x;
		rect.y += ParentRect.y;
	}
*/
	pWidget->SetRect(&rect, pRelativeTo, false); // shouldn't have children at this point!
	
	// add the widget to the GUID list
	m_pGUIDTree->Insert(guid, pWidget);

	// set the widget's flags
	pWidget->SetState(flags);

	// send the creation message
	CUIMessage* pMessage1;
	LT_MEM_TRACK_ALLOC(pMessage1 = new CUIMessage(CUIM_WIDGET_ON_CREATE, pWidget, pWidget, 0, 0),LT_MEM_TYPE_UI);
	this->EnqueueMessage(pMessage1);
	delete pMessage1;
	
	return pWidget;
}
コード例 #4
0
ファイル: Updater.cpp プロジェクト: desg/OBS
DWORD WINAPI CheckUpdateThread (VOID *arg)
{
    int responseCode;
    TCHAR extraHeaders[256];
    BYTE manifestHash[20];
    TCHAR manifestPath[MAX_PATH];

    tsprintf_s (manifestPath, _countof(manifestPath)-1, TEXT("%s\\updates\\packages.xconfig"), lpAppDataPath);

    if (!CryptAcquireContext(&hProvider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
    {
        Log (TEXT("Updater: CryptAcquireContext failed: %08x"), GetLastError());
        return 1;
    }

    extraHeaders[0] = 0;

    if (CalculateFileHash(manifestPath, manifestHash))
    {
        TCHAR hashString[41];

        HashToString(manifestHash, hashString);

        tsprintf_s (extraHeaders, _countof(extraHeaders)-1, TEXT("If-None-Match: %s"), hashString);
    }
    
    //this is an arbitrary random number that we use to count the number of unique OBS installations
    //and is not associated with any kind of identifiable information
    String strGUID = GlobalConfig->GetString(TEXT("General"), TEXT("InstallGUID"));
    if (strGUID.IsEmpty())
    {
        GenerateGUID(strGUID);

        if (strGUID.IsValid())
            GlobalConfig->SetString(TEXT("General"), TEXT("InstallGUID"), strGUID);
    }

    if (strGUID.IsValid())
    {
        if (extraHeaders[0])
            scat(extraHeaders, TEXT("\n"));

        scat(extraHeaders, TEXT("X-OBS-GUID: "));
        scat(extraHeaders, strGUID);
    }

    if (HTTPGetFile(TEXT("https://obsproject.com/update/packages.xconfig"), manifestPath, extraHeaders, &responseCode))
    {
        if (responseCode == 200 || responseCode == 304)
        {
            String updateInfo;
            BOOL updatesAvailable;

            updateInfo = Str("Updater.NewUpdates");

            if (ParseUpdateManifest(manifestPath, &updatesAvailable, updateInfo))
            {
                if (updatesAvailable)
                {
                    updateInfo << TEXT("\r\n") << Str("Updater.DownloadNow");

                    if (MessageBox (NULL, updateInfo.Array(), Str("Updater.UpdatesAvailable"), MB_ICONQUESTION|MB_YESNO) == IDYES)
                    {
                        if (App->IsRunning())
                        {
                            if (MessageBox (NULL, Str("Updater.RunningWarning"), NULL, MB_ICONEXCLAMATION|MB_YESNO) == IDNO)
                                goto abortUpdate;
                        }

                        TCHAR updateFilePath[MAX_PATH];
                        TCHAR cwd[MAX_PATH];

                        GetModuleFileName(NULL, cwd, _countof(cwd)-1);
                        TCHAR *p = srchr(cwd, '\\');
                        if (p)
                            *p = 0;

                        tsprintf_s (updateFilePath, _countof(updateFilePath)-1, TEXT("%s\\updates\\updater.exe"), lpAppDataPath);

                        //note, can't use CreateProcess to launch as admin.
                        SHELLEXECUTEINFO execInfo;

                        zero(&execInfo, sizeof(execInfo));

                        execInfo.cbSize = sizeof(execInfo);
                        execInfo.lpFile = updateFilePath;
#ifndef _WIN64
                        execInfo.lpParameters = TEXT("Win32");
#else
                        execInfo.lpParameters = TEXT("Win64");
#endif
                        execInfo.lpDirectory = cwd;
                        execInfo.nShow = SW_SHOWNORMAL;

                        if (!ShellExecuteEx (&execInfo))
                        {
                            AppWarning(TEXT("Can't launch updater '%s': %d"), updateFilePath, GetLastError());
                            goto abortUpdate;
                        }

                        //force OBS to perform another update check immediately after updating in case of issues
                        //with the new version
                        GlobalConfig->SetInt(TEXT("General"), TEXT("LastUpdateCheck"), 0);

                        //since we're in a separate thread we can't just PostQuitMessage ourselves
                        SendMessage(hwndMain, WM_CLOSE, 0, 0);
                    }
                }
            }
        }
    }

abortUpdate:

    CryptReleaseContext(hProvider, 0);

    return 0;
}