Пример #1
0
wswcurl_req *wswcurl_create(wswcurl_cb_done callback, char *furl, ...)
{
    wswcurl_req req, *retreq = NULL;
    CURLcode res;
    char url[4 * 1024]; // 4kb url buffer?
    va_list arg;

    // Prepare url formatting with variable arguments
    va_start(arg, furl);
    vsnprintf(url, sizeof(url), furl, arg);
    va_end(arg);

    // Initialize structure
    memset(&req, 0, sizeof(req));

    if (! (req.curl = curl_easy_init())) {
        return NULL;
    }
    CURLSETOPT(req.curl, res, CURLOPT_URL, url);
    CURLSETOPT(req.curl, res, CURLOPT_WRITEFUNCTION, wswcurl_write);
    CURLSETOPT(req.curl, res, CURLOPT_NOPROGRESS, 1);
    CURLSETOPT(req.curl, res, CURLOPT_FOLLOWLOCATION, 1);
    CURLSETOPT(req.curl, res, CURLOPT_HEADERFUNCTION, wswcurl_readheader);

    // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    // TODO: Warsow specific stuff? Modify!!
    //CURLSETOPT(req.curl, res, CURLOPT_USERAGENT, "Warsow 0.5");
    //wswcurl_header(&req, "X-Warsow-Version", "0.5");
    // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    if (!req.curl) {
        return NULL;
    }
    req.url = WSTRDUP(url);
    req.callback_done = callback;
    req.filenum = -1;
    // Everything OK, allocate, copy, prepend to list and return
    retreq = WMALLOC(sizeof(req));
    memcpy(retreq, &req, sizeof(req));
    retreq->prev = NULL;
    retreq->next = http_requests;
    if (retreq->next) retreq->next->prev = retreq;
    http_requests = retreq;
    // Set the wswcurl_req as data
    CURLSETOPT(retreq->curl, res, CURLOPT_WRITEDATA, (void*)retreq);
    CURLSETOPT(retreq->curl, res, CURLOPT_WRITEHEADER, (void*)retreq);

    return retreq;
}
Пример #2
0
static int MemChecker_CreateMainMenu(MemChecker* pMe)
{
    IWindow *piWindow = NULL;
    IWidget *piWidget = NULL;
    AECHAR *pszText = NULL;

    IClassFactory_CreateInstance(pMe->m_pIClassFactory, XCLSID_Window, (void **)&piWindow);
    IWidget_SetName((IWidget*)piWindow, "Window1");
    IWindow_SetSize(piWindow, 240, 320);
    IDesktopWindow_AddWindow(pMe->m_pIDesktopWindow, piWindow);
    IWidget_Release((IWidget*)piWindow);

    ISHELL_LoadResStringEx(pMe->a.m_pIShell, MEMCHECKER_RES_FILE, IDS_BEGIN_WATCH, &pszText);
    piWidget = MemChecker_CreateButton(pMe, "Button1", 0, 0, 96, 84, pszText);
    if (NULL != piWidget)
    {
        Listener* pListener = MALLOCREC(Listener);
        Listener_Init(pListener, MemChecker_Button_Listener, pMe);
        IWidget_AddListener(piWidget, pListener);

        IWidget_SetID(piWidget, IDS_BEGIN_WATCH);
        IWindow_Insert(piWindow, piWidget, -1, NULL);
        RELEASEIF(piWidget);
    }

    ISHELL_LoadResStringEx(pMe->a.m_pIShell, MEMCHECKER_RES_FILE, IDS_RUN_AND_WATCH, &pszText);
    piWidget = MemChecker_CreateButton(pMe, "Button2", 72, 42, 96, 84, pszText);
    if (NULL != piWidget)
    {
        Listener* pListener = MALLOCREC(Listener);
        Listener_Init(pListener, MemChecker_Button_Listener, pMe);
        IWidget_AddListener(piWidget, pListener);

        IWidget_SetID(piWidget, IDS_RUN_AND_WATCH);
        IWindow_Insert(piWindow, piWidget, -1, NULL);
        RELEASEIF(piWidget);
    }

    ISHELL_LoadResStringEx(pMe->a.m_pIShell, MEMCHECKER_RES_FILE, IDS_ABOUT, &pszText);
    piWidget = MemChecker_CreateButton(pMe, "Button3", 144, 0, 96, 84, pszText);
    if (NULL != piWidget)
    {
        Listener* pListener = MALLOCREC(Listener);
        Listener_Init(pListener, MemChecker_Button_Listener, pMe);
        IWidget_AddListener(piWidget, pListener);

        IWidget_SetID(piWidget, IDS_ABOUT);
        IWindow_Insert(piWindow, piWidget, -1, NULL);
        RELEASEIF(piWidget);
    }

    piWidget = MemChecker_CreateButton(pMe, NULL, 0, 84, 96, 84, WSTRDUP(L"Unimplemented"));
    if (NULL != piWidget)
    {
        IWindow_Insert(piWindow, piWidget, -1, NULL);
        RELEASEIF(piWidget);
    }
    piWidget = MemChecker_CreateButton(pMe, NULL, 72, 126, 96, 84, WSTRDUP(L"Unimplemented"));
    if (NULL != piWidget)
    {
        IWindow_Insert(piWindow, piWidget, -1, NULL);
        RELEASEIF(piWidget);
    }
    piWidget = MemChecker_CreateButton(pMe, NULL, 144, 84, 96, 84, WSTRDUP(L"Unimplemented"));
    if (NULL != piWidget)
    {
        IWindow_Insert(piWindow, piWidget, -1, NULL);
        RELEASEIF(piWidget);
    }
    piWidget = MemChecker_CreateButton(pMe, NULL, 0, 168, 96, 84, WSTRDUP(L"Unimplemented"));
    if (NULL != piWidget)
    {
        IWindow_Insert(piWindow, piWidget, -1, NULL);
        RELEASEIF(piWidget);
    }
    piWidget = MemChecker_CreateButton(pMe, NULL, 72, 210, 96, 84, WSTRDUP(L"Unimplemented"));
    if (NULL != piWidget)
    {
        IWindow_Insert(piWindow, piWidget, -1, NULL);
        RELEASEIF(piWidget);
    }
    piWidget = MemChecker_CreateButton(pMe, NULL, 144, 168, 96, 84, WSTRDUP(L"Unimplemented"));
    if (NULL != piWidget)
    {
        IWindow_Insert(piWindow, piWidget, -1, NULL);
        RELEASEIF(piWidget);
    }

    IContainer_Invalidate((IContainer *)pMe->m_pIDesktopWindow, NULL, NULL);

    return SUCCESS;
}
Пример #3
0
void wswcurl_setfilename(wswcurl_req *req, char *filename)
{
    if (req->filename) WFREE(req->filename);
    if (filename) req->filename = WSTRDUP(filename);
}