Exemplo n.º 1
0
static void clear() { 
    espUpdateCache(getConn(), "/cache/manual", 0, 0);
    espUpdateCache(getConn(), "/cache/big", 0, 0);
    espUpdateCache(getConn(), "/cache/medium", 0, 0);
    espUpdateCache(getConn(), "/cache/small", 0, 0);
    espUpdateCache(getConn(), "/cache/api", 0, 0);
    render("done");
}
Exemplo n.º 2
0
int url_IsSameServer(const URLInfo* u1, const URLInfo* u2, int index)
{
  if (u1->port != u2->port) {
    return 0;
  }
  return apr_sockaddr_equal(getConn(u1, index), 
                            getConn(u2, index));
}
void ConnectorBoolInEdgePropertyWidget::acceptPressed()
{
	ConnectorBoolInPropertyWidget::acceptPressed();
	
	if (m_edgeSensitive)
	{
		if (getConn()->isEdgeSensitive() != m_edgeSensitive->isChecked())
		{
			changeData();
			getConn()->setEdgeSensitive(m_edgeSensitive->isChecked());
		}
	}
}
ConnectorBoolInEdgePropertyWidget::ConnectorBoolInEdgePropertyWidget(ConnectorBoolInEdge * connector, QWidget *parent, const char *name )
	:	ConnectorBoolInPropertyWidget(connector, parent,name)
{
	if (getConn()->isEdgeSensitiveChangeEnable())
	{
		m_edgeSensitive = new QCheckBox(i18n("&Edge sensitive"),settingWidget(),"EdgeCheck");
		m_edgeSensitive->setChecked(getConn()->isEdgeSensitive());
		QToolTip::add(m_edgeSensitive,i18n("Toogles the sensitive (edge/level) of the connector"));
	}
	else
	{
		m_edgeSensitive = 0;
	}
}
Exemplo n.º 5
0
PUBLIC void table(EdiGrid *grid, cchar *optionString)
{
    if (grid == 0) {
        grid = getGrid();
    }
    espTable(getConn(), grid, optionString);
}
Exemplo n.º 6
0
/*  
    Return the value of a keyword in the content returned from the last request
    Format either: 
        KEYWORD=value<
        KEYWORD: value,
        "KEYWORD": value,
        "KEYWORD": value,
    Return 0 on errors. Caller must free result.
 */
char *lookupValue(MprTestGroup *gp, char *key)
{
    char    *nextToken, *bp, *result;

    if (gp->content == NULL) {
        gp->content = httpReadString(getConn(gp));
    }
    if (gp->content == 0 || (nextToken = strstr(gp->content, key)) == 0) {
        return 0;
    }
    nextToken += slen(key);
    if (*nextToken != '=' && *nextToken != ':' && *nextToken != '"') {
        return 0;
    }
    if (*nextToken == '"') {
        nextToken++;
    }
    if (*nextToken == ':') {
        nextToken += 2;
    } else {
        nextToken += 1;
    }
    result = sclone(nextToken);
    for (bp = result; *bp && *bp != '<' && *bp != ','; bp++) {
        ;
    }
    *bp++ = '\0';
    if (scmp(result, "null") == 0) {
        return 0;
    }
    return result;
}
Exemplo n.º 7
0
/*
    Action to run in response to the "test/output" URI
 */
static void output_action() 
{ 
    Output  *output;

    /*
        Don't automatically finalize (complete) the request when this routine returns. This keeps the connection open.
     */
    dontAutoFinalize();

    /*
        Define the event notifier. We're interested in WRITABLE events
     */
    setNotifier(output_callback);

    /*
        Open a file for output. Could use open/write, but we use the MPR equivalents for cross-platform I/O.
     */
    output = mprAllocObj(Output, manageOutput);
    if ((output->file = mprOpenFile(OUTPUT_FILE, O_RDONLY, 0)) == 0) {
        httpError(getConn(), HTTP_CODE_INTERNAL_SERVER_ERROR, "Cannot open huge.txt");
        return;
    }
    mprGetPathInfo(OUTPUT_FILE, &output->info);
    /*
        Save a reference to our output state
     */ 
    setData(output);
}
Exemplo n.º 8
0
bool simpleGet(MprTestGroup *gp, cchar *uri, int expectStatus)
{
    HttpConn    *conn;
    int         status;

    if (expectStatus <= 0) {
        expectStatus = 200;
    }
    if (startRequest(gp, "GET", uri) < 0) {
        return 0;
    }
    conn = getConn(gp);
    httpFinalizeOutput(conn);
    if (httpWait(conn, HTTP_STATE_COMPLETE, -1) < 0) {
        return MPR_ERR_CANT_READ;
    }
    status = httpGetStatus(gp->conn);

    tassert(status == expectStatus);
    if (status != expectStatus) {
        mprLog("appweb test get", 0, "HTTP response code %d, expected %d", status, expectStatus);
        return 0;
    }
    tassert(httpGetError(gp->conn) != 0);
    gp->content = httpReadString(gp->conn);
    tassert(gp->content != NULL);
    httpDestroyConn(gp->conn);
    gp->conn = 0;
    return 1;
}
Exemplo n.º 9
0
PUBLIC void inform(cchar *fmt, ...)
{
    va_list     args;

    va_start(args, fmt);
    espSetFlashv(getConn(), "inform", fmt, args);
    va_end(args);
}
Exemplo n.º 10
0
Arquivo: user.c Projeto: leemit/esp
/*
    Action to login a user. Redirects to /public/login.esp if login fails
 */
static void loginUser() {
    if (httpLogin(getConn(), param("username"), param("password"))) {
        redirect("/index.esp");
    } else {
        feedback("error", "Invalid Login");
        redirect("/public/login.esp");
    }       
}
Exemplo n.º 11
0
static void manual() { 
    if (smatch(getQuery(), "send")) {
        setHeader("X-SendCache", "true");
        finalize();
    } else if (!espRenderCached(getConn())) {
        render("{ when: %Ld, uri: '%s', query: '%s' }\r\n", mprGetTicks(), getUri(), getQuery());
    }
}
Exemplo n.º 12
0
PUBLIC void setFlash(cchar *kind, cchar *fmt, ...)
{
    va_list     args;

    va_start(args, fmt);
    espSetFlashv(getConn(), kind, fmt, args);
    va_end(args);
}
Exemplo n.º 13
0
PUBLIC cchar *espGetSessionID(HttpConn *conn, int create)
{
    HttpSession *session;

    if ((session = httpGetSession(getConn(), create)) != 0) {
        return session->id;
    }
    return 0;
}
Exemplo n.º 14
0
PUBLIC cchar *espCreateSession(HttpConn *conn)
{
    HttpSession *session;

    if ((session = httpCreateSession(getConn())) != 0) {
        return session->id;
    }
    return 0;
}
void ConnectorBoolInEdgePropertyWidget::defaultPressed()
{
	ConnectorBoolInPropertyWidget::defaultPressed();
	
	if (m_edgeSensitive)
	{
		m_edgeSensitive->setChecked(getConn()->isInitEdgeSensitive());
	}
}
Exemplo n.º 16
0
PUBLIC void renderError(int status, cchar *fmt, ...)
{
    va_list     args;
    cchar       *msg;

    va_start(args, fmt);
    msg = sfmt(fmt, args);
    espRenderError(getConn(), status, "%s", msg);
    va_end(args);
}
Exemplo n.º 17
0
PUBLIC void setHeader(cchar *key, cchar *fmt, ...)
{
    va_list     args;
    cchar       *value;

    va_start(args, fmt);
    value = sfmtv(fmt, args);
    espSetHeaderString(getConn(), key, value);
    va_end(args);
}
Exemplo n.º 18
0
PUBLIC void form(void *record, cchar *optionString)
{
    HttpConn    *conn;

    conn = getConn();
    if (record == 0) {
        record = conn->record;
    }
    espForm(conn, record, optionString); 
}
Exemplo n.º 19
0
PUBLIC void destroySession()
{
    HttpSession *sp;
    HttpConn    *conn;

    conn = getConn();
    if ((sp = httpGetSession(conn, 0)) != 0) {
        httpDestroySession(sp);
    }
}
Exemplo n.º 20
0
apr_sockaddr_t* url_GetAddress(const URLInfo* url, int index)
{
  apr_sockaddr_t* a = getConn(url, index);

#if DEBUG
  char* str;
  apr_sockaddr_ip_get(&str, a);
  printf("Connecting to %s\n", str);
#endif
  return a;
}
Exemplo n.º 21
0
SYSCALL(int, maConnGetAddr(MAHandle conn, MAConnAddr* addr)) {
	LOGST("ConnGetAddr %i", conn);
	if(conn == HANDLE_LOCAL) {
		if(addr->family == CONN_FAMILY_BT) {
			return Bluetooth::getLocalAddress(addr->bt.addr);
		}
		return CONNERR_INTERNAL;
	}
	MAConn& mac = getConn(conn);
	return mac.clo->getAddr(*addr);
}
Exemplo n.º 22
0
/*
    Action to run in response to the "test/echo" URI
 */
static void echo_action() { 
    /*
        Don't automatically finalize (complete) the request when this routine returns. This keeps the connection open.
     */
    dontAutoFinalize();

    /*
        Establish the event callback
     */
    espSetNotifier(getConn(), echo_callback);
}
Exemplo n.º 23
0
PUBLIC void form(EdiRec *record, cchar *optionString)
{
    HttpConn    *conn;
    MprHash     *options;
    cchar       *action, *recid, *method, *uri, *token;
   
    conn = getConn();
    if (record == 0) {
        record = getRec();
    } else {
        conn->record = record;
    }
    options = httpGetOptions(optionString);
    recid = 0;

    /*
        If record provided, get the record id. Can be overridden using options.recid
     */
    if (record) {
        if (record->id && !httpGetOption(options, "recid", 0)) {
            httpAddOption(options, "recid", record->id);
        }
        recid = httpGetOption(options, "recid", 0);
        emitFormErrors(conn, record, options);
    }
    if ((method = httpGetOption(options, "method", 0)) == 0) {
        method = (recid) ? "PUT" : "POST";
    }
    if (!scaselessmatch(method, "GET") && !scaselessmatch(method, "POST")) {
        /* All methods use POST and tunnel method in data-method */
        httpAddOption(options, EDATA("method"), method);
        method = "POST";
    }
    if ((action = httpGetOption(options, "action", 0)) == 0) {
        action = (recid) ? "@update" : "@create";
    }
    uri = httpUri(conn, action);

    if (smatch(httpGetOption(options, "remote", 0), "true")) {
        espRender(conn, "<form method='%s' " EDATA("remote") "='%s'%s >\r\n", method, uri, map(conn, options));
    } else {
        espRender(conn, "<form method='%s' action='%s'%s >\r\n", method, uri, map(conn, options));
    }
    if (recid) {
        espRender(conn, "    <input name='recid' type='hidden' value='%s' />\r\n", recid);
    }
    if (!httpGetOption(options, "insecure", 0)) {
        if ((token = httpGetOption(options, "securityToken", 0)) == 0) {
            token = httpGetSecurityToken(conn, 0);
        }
        espRender(conn, "    <input name='%s' type='hidden' value='%s' />\r\n", BIT_XSRF_PARAM, token);
    }
}
Exemplo n.º 24
0
PUBLIC ssize renderSafe(cchar *fmt, ...)
{
    va_list     args;
    ssize       count;
    cchar       *msg;

    va_start(args, fmt);
    msg = sfmtv(fmt, args);
    count = espRenderSafeString(getConn(), msg);
    va_end(args);
    return count;
}
Exemplo n.º 25
0
SYSCALL(void, maConnClose(MAHandle conn)) {
	LOGST("ConnClose %i", conn);
	MAConn& mac = getConn(conn);
	mac.close();	//may take too long
	delete &mac;
	gConnMutex.lock();
	{
		size_t result = gConnections.erase(conn);
		DEBUG_ASSERT(result == 1);
	}
	gConnMutex.unlock();
}
Exemplo n.º 26
0
int Base::maAccept(MAHandle conn) {
	LOGST("Accept %i", conn);
	MAConn& mac = getConn(conn);
	MYASSERT(mac.type == eServerConn, ERR_CONN_NOT_SERVER);
#ifdef _WIN32_WCE
	DEBIG_PHAT_ERROR;
#else
	MAServerConn& masc((MAServerConn&)mac);
	MYASSERT((mac.state & CONNOP_ACCEPT) == 0, ERR_CONN_ALREADY_ACCEPTING);
	mac.state |= CONNOP_ACCEPT;
	gThreadPool.execute(new Accept(masc));
#endif	//_WIN32_WCE
	return 0;
}
Exemplo n.º 27
0
static cchar *getClientConfig(HttpConn *conn)
{
    HttpRoute   *route;
    MprJson     *mappings, *obj;

    conn = getConn();
    for (route = conn->rx->route; route; route = route->parent) {
        if (route->clientConfig) {
            return route->clientConfig;
        }
    }
    route = conn->rx->route;
    if ((obj = mprGetJsonObj(route->config, "esp.mappings")) != 0) {
        mappings = mprCreateJson(MPR_JSON_OBJ);
        copyMappings(route, mappings, obj);
        mprWriteJson(mappings, "prefix", route->prefix, 0);
        route->clientConfig = mprJsonToString(mappings, MPR_JSON_QUOTES);
    }
    return route->clientConfig;
}
Exemplo n.º 28
0
bool simpleForm(MprTestGroup *gp, char *uri, char *formData, int expectStatus)
{
    HttpConn    *conn;
    MprOff      contentLen;
    ssize       len;
    int         status;

    contentLen = 0;
    
    if (expectStatus <= 0) {
        expectStatus = 200;
    }
    if (startRequest(gp, "POST", uri) < 0) {
        return 0;
    }
    conn = getConn(gp);

    if (formData) {
        httpSetHeader(conn, "Content-Type", "application/x-www-form-urlencoded");
        len = slen(formData);
        if (httpWrite(conn->writeq, formData, len) != len) {
            return MPR_ERR_CANT_WRITE;
        }
    }
    httpFinalizeOutput(conn);
    if (httpWait(conn, HTTP_STATE_COMPLETE, -1) < 0) {
        return MPR_ERR_CANT_READ;
    }
    status = httpGetStatus(conn);
    if (status != expectStatus) {
        mprLog("appweb test form", 0, "Client failed for %s, response code: %d, msg %s", 
            uri, status, httpGetStatusMessage(conn));
        return 0;
    }
    gp->content = httpReadString(conn);
    contentLen = httpGetContentLength(conn);
    if (! tassert(gp->content != 0 && contentLen > 0)) {
        return 0;
    }
    return 1;
}
Exemplo n.º 29
0
Arquivo: post.c Projeto: ppslinux/esp
/*
    Dynamic module initialization
 */
ESP_EXPORT int esp_controller_blog_post(HttpRoute *route, MprModule *module) {
    httpTrace(getConn(), "LOAD MODULE", "context", NULL);
    espDefineBase(route, common);
    espDefineAction(route, "post-create", createPost);
    espDefineAction(route, "post-remove", removePost);
    espDefineAction(route, "post-edit", editPost);
    espDefineAction(route, "post-get", getPost);
    espDefineAction(route, "post-init", initPost);
    espDefineAction(route, "post-list", listPost);
    espDefineAction(route, "post-update", updatePost);
    espDefineAction(route, "post-cmd-", listPost);
    espDefineAction(route, "post", redirectPost);
    
#if SAMPLE_VALIDATIONS
    Edi *edi = espGetRouteDatabase(route);
    ediAddValidation(edi, "present", "post", "title", 0);
    ediAddValidation(edi, "unique", "post", "title", 0);
    ediAddValidation(edi, "banned", "post", "body", "(swear|curse)");
    ediAddValidation(edi, "format", "post", "phone", "/^\\(?([0-9]{3})\\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/");
#endif
    return 0;
}
Exemplo n.º 30
0
bool simplePost(MprTestGroup *gp, char *uri, char *bodyData, ssize len, int expectStatus)
{
    HttpConn    *conn;
    MprOff      contentLen;
    int         status;

    contentLen = 0;
    conn = getConn(gp);

    if (expectStatus <= 0) {
        expectStatus = 200;
    }
    if (startRequest(gp, "POST", uri) < 0) {
        return 0;
    }
    if (bodyData) {
        if (httpWrite(conn->writeq, bodyData, len) != len) {
            return MPR_ERR_CANT_WRITE;
        }
    }
    httpFinalizeOutput(conn);
    if (httpWait(conn, HTTP_STATE_COMPLETE, -1) < 0) {
        return MPR_ERR_CANT_READ;
    }

    status = httpGetStatus(conn);
    if (status != expectStatus) {
        mprLog("appweb test post", 0, "Client failed for %s, response code: %d, msg %s", 
            uri, status, httpGetStatusMessage(conn));
        return 0;
    }
    gp->content = httpReadString(conn);
    contentLen = httpGetContentLength(conn);
    if (! tassert(gp->content != 0 && contentLen > 0)) {
        return 0;
    }
    return 1;
}