Esempio n. 1
0
GSTATUS 
DDFSemOpen (
	PSEMAPHORE sem, 
	bool exclusive) 
{
    GSTATUS err = GSTAT_OK;
    STATUS	status;

    if ((status = CSp_semaphore(TRUE, &sem->semaphore)) == OK)
    {
	while (status == OK && 
	       ((exclusive == TRUE) ? sem->have != 0 : sem->have < 0))
	    status = CScnd_wait(&sem->cond, &sem->semaphore);

	if (status == OK) 
	{
	    if (exclusive == TRUE)
		sem->have--;
	    else
		sem->have++;
	    status = CSv_semaphore(&sem->semaphore);
	}
	else if (status != E_CS000F_REQUEST_ABORTED)
	{
	    CSv_semaphore(&sem->semaphore);
	    err = DDFStatusAlloc (E_DF0008_SEM_CANNOT_OPEN);
	}
    }
    return(err);
}
Esempio n. 2
0
/*
** Name: HandlerException
**
** Decription:
**      Function is is to catch unknown or new events.
**
** Inputs:
**      sess        ice session structure
**      line        pointer to the current line
**      linelen     length of the line
**
** Outputs:
**      pos         number of characters handled.
**
** Return:
**      GSTAT_OK    success
**      other       failure
**
** History:
**      23-Oct-98 (fanra01)
**          Created.
*/
static GSTATUS
HandlerException (WTS_SESSION* sess, char* line, i4  linelen, i4 * pos)
{
    PWTS_UPLOAD load= sess->load;

    load->state = US_END;

    return (DDFStatusAlloc(E_WS0088_WTS_INVALID_UPLOAD));
}
Esempio n. 3
0
GSTATUS 
DDFSemCreate (
	PSEMAPHORE sem, 
	char *name) 
{
    GSTATUS err = GSTAT_OK;
    STATUS	status;

    G_ASSERT(!sem, 1);

    status = CSw_semaphore(&(sem->semaphore), CS_SEM_SINGLE, name);
    if (status == OK)
	status = CScnd_init(&sem->cond);
    if (status == OK)
	status = CScnd_name(&sem->cond, "DDF R/W semaphore");
    sem->have = 0;
    if (status != OK) 
	err = DDFStatusAlloc (E_DF0007_SEM_CANNOT_CREATE);
    return(err);
}
Esempio n. 4
0
/*
** Name: WSMRequestUsrSession() - Retrieve a user session from the cookie
**
** Description:
**
** Inputs:
**	char*	: cookie
**
** Outputs:
**	USR_PSESSION*	: user session (NULL if doesn't exist)
**
** Returns:
**	GSTATUS	:	GSTAT_OK
**
** Exceptions:
**	None
**
** Side Effects:
**	None
**
** History:
**      04-Oct-2001 (fanra01)
**          Add a test for an invalid session or a session that is no longer
**          in the hash table and return an error.
*/
GSTATUS 
WSMRequestUsrSession (
    char         *cookie,
    USR_PSESSION *session)
{
    GSTATUS err = GSTAT_OK;
    u_i4    i = 0;
    USR_PSESSION tmp = NULL;

    if (cookie != NULL && cookie[0] != EOS)
    {
        err = DDFSemOpen(&usrSessSemaphore, TRUE);
        if (err == GSTAT_OK)
        {
            err = DDFgethash(
                    usr_sessions,
                    cookie,
                    STlength(cookie),
                    (PTR*) &tmp);
            /*
            ** If the object is not in the hash table, raise and error.
            */
            if (tmp == NULL)
            {
                err = DDFStatusAlloc( E_WS0011_WSS_NO_OPEN_SESSION );
            }
            if (tmp != NULL &&
                tmp->timeout_end < TMsecs())
                tmp = NULL;

            if (tmp != NULL)
                tmp->requested_counter++;

            CLEAR_STATUS(DDFSemClose(&usrSessSemaphore));
        }
    }

    *session = tmp;
    return(err);
}
Esempio n. 5
0
GSTATUS 
DDFSemClose (
	PSEMAPHORE sem) 
{
    GSTATUS err = GSTAT_OK;
    STATUS	status;

    G_ASSERT(!sem, E_DF0010_SEM_BAD_INIT);

    if ((status = CSp_semaphore(TRUE, &sem->semaphore)) == OK) 
    {
	if (sem->have < 0) 
	{
	    sem->have = 0;
	    /* when releaseing an exclusive - several shares may wake */
	    status = CScnd_broadcast(&sem->cond);
	} 
	else 
	{
	    sem->have--;
	    if (sem->have == 0) 
	    {
		/* when releaseing a share - at most one exclusive may wake */
		status = CScnd_signal(&sem->cond, (CS_SID)NULL);
	    }
	}
	if (status == OK) 
	{
	    if (CSv_semaphore(&sem->semaphore) != OK)
		err = DDFStatusAlloc (E_DF0009_SEM_CANNOT_CLOSE);
	} 
	else 
	{
	    CSv_semaphore(&sem->semaphore);
	}
    }
    return(err);
}
Esempio n. 6
0
/*
** Name: WMODocument() - insert, update, delete, select and retrieve documents
**
** Description:
**
** Inputs:
**	ACT_PSESSION	: active session
**	char*[]			: list of parameters
**
** Outputs:
**	bool*			: TRUE is there is something to print
**	PTR*			: cursor pointer (if NULL means no more information)
**
** Returns:
**	GSTATUS	:	GSTAT_OK
**
** Exceptions:
**	None
**
** Side Effects:
**	None
**
** History:
**      28-Apr-2000 (fanra01)
**          Add additional scheme parameter to WPSrequest.
**      30-Oct-2001 (fanra01)
**          Replace ambiguous profile error message with authorization
**          and permission messages.
*/
GSTATUS
WMODocument (
    ACT_PSESSION act_session,
    char* params[],
    bool* print,
    PTR*  user_info)
{
    GSTATUS        err = GSTAT_OK;
    u_i4            action;
    u_i4            unit_id = 0;
    u_i4            ext_loc = 0;
    i4        flag = 0;
    u_i4            owner = 0;
    u_i4            *pid = NULL;
    u_i4            *punit_id = NULL;
    i4        *pflag = NULL;
    u_i4            *powner = NULL;
    u_i4            *pext_loc = NULL;
    char            *ext_file;
    char            *ext_suffix;
    bool            accessible = TRUE;
    WPS_FILE    *cache = NULL;
    bool        status;

    *print = TRUE;
    if (*user_info == NULL)
    {
    G_ASSERT (params[0] == NULL || params[0][0] == EOS, E_WS0059_WSF_BAD_PARAM);

    if (act_session->user_session == NULL)
    {
        *print = FALSE;
        err = DDFStatusAlloc( E_WS0101_WSS_UNAUTHORIZED_USE );
        return(err);
    }

    if (err == GSTAT_OK)
        err = WMOTypeAction(params[0], &action);
    }
    else
    action = WSS_ACTION_TYPE_SEL;

    if (err == GSTAT_OK)
    if (action == WSS_ACTION_TYPE_SEL)
    {
        if (*user_info == NULL)
        {
        err = WCSOpenDocument(user_info);
        if (err == GSTAT_OK)
            err = GAlloc((PTR*)&params[1], NUM_MAX_INT_STR, FALSE);
        }

        if (err == GSTAT_OK)
        {
        err = WCSGetDocument(
                     user_info,
                     &pid,
                     &punit_id,
                     &params[4],
                     &params[5],
                     (u_i4**)&pflag,
                     &powner,
                     &pext_loc,
                     &params[12],
                     &params[13]);

        if (err != GSTAT_OK || *user_info == NULL)
        {
            CLEAR_STATUS (WCSCloseDocument(user_info));
            *print = FALSE;
        }
        else
        {
            err = WSSDocAccessibility(act_session->user_session, *pid, WSF_READ_RIGHT, &accessible);
            if (err == GSTAT_OK && accessible == TRUE)
            {
            WSF_CVNA(err, *pid, params[1]);
            unit_id = *punit_id;
            flag = *pflag;
            ext_loc= *pext_loc;
            }
            else
            *print = FALSE;
        }
        }
    }
    else
    {
        u_i4        id;

        switch(action)
        {
        case WSS_ACTION_TYPE_DEL:
        case WSS_ACTION_TYPE_RET:
        G_ASSERT (params[1] == NULL || CVan(params[1], (i4*)&id) != OK, E_WS0059_WSF_BAD_PARAM);
        if (action == WSS_ACTION_TYPE_DEL)
        {
            err = WSSDocAccessibility(act_session->user_session, id, WSF_DEL_RIGHT, &accessible);

            if (err == GSTAT_OK)
            if (accessible == TRUE)
                err = WCSDeleteDocument (id);
            else
                err = DDFStatusAlloc( E_WS0065_WSF_UNAUTH_ACCESS );
        }
        else
        {
            err = WSSDocAccessibility(act_session->user_session, id, WSF_READ_RIGHT, &accessible);
            if (err == GSTAT_OK && accessible == TRUE)
            {
            err = WCSRetrieveDocument (
                           id,
                           &punit_id,
                           &params[4],
                           &params[5],
                           (u_i4**)&pflag,
                           &powner,
                           &pext_loc,
                           &params[12],
                           &params[13]);

            if (err == GSTAT_OK && punit_id != NULL)
            {
                unit_id = *punit_id;
                flag = *pflag;
                ext_loc= *pext_loc;
                owner = *powner;

                if (err == GSTAT_OK)
                {
                err = WPSRequest(
                         act_session->user_session->name,
                         act_session->scheme,
                         act_session->host,
                         act_session->port,
                         NULL,
                         unit_id,
                         params[4],
                         params[5],
                         &cache,
                         &status);

                if (err == GSTAT_OK)
                {
                    if (status == WCS_ACT_LOAD)
                    {
                    if ((flag & WCS_EXTERNAL) == FALSE)
                        err = WCSExtractDocument (cache->file);

                    if (err == GSTAT_OK)
                        CLEAR_STATUS(WCSLoaded(cache->file, TRUE))
                        else
                            CLEAR_STATUS(WCSLoaded(cache->file, FALSE))
                        }

                    if (err == GSTAT_OK)
                    {
                    char *tmp = (cache->url == NULL) ? WSF_UNDEFINED : cache->url;
                    u_i4 length = STlength(tmp) + 1;
                    err = GAlloc((PTR*)&params[10], length, FALSE);
                    if (err == GSTAT_OK)
                        MECOPY_VAR_MACRO(tmp, length, params[10]);
                    }
                    CLEAR_STATUS(WPSRelease(&cache));
                }
                }
            }
            }
            else
Esempio n. 7
0
                    if (err == GSTAT_OK)
                    {
                    char *tmp = (cache->url == NULL) ? WSF_UNDEFINED : cache->url;
                    u_i4 length = STlength(tmp) + 1;
                    err = GAlloc((PTR*)&params[10], length, FALSE);
                    if (err == GSTAT_OK)
                        MECOPY_VAR_MACRO(tmp, length, params[10]);
                    }
                    CLEAR_STATUS(WPSRelease(&cache));
                }
                }
            }
            }
            else
            err = DDFStatusAlloc( E_WS0065_WSF_UNAUTH_ACCESS );
        }
        break;
        case WSS_ACTION_TYPE_INS:
        case WSS_ACTION_TYPE_UPD:
        {
            char *suffix;

            G_ASSERT (params[2] == NULL || CVan(params[2], (i4*)&unit_id) != OK, E_WS0059_WSF_BAD_PARAM);
            G_ASSERT (params[4] == NULL || params[4][0] == EOS, E_WS0059_WSF_BAD_PARAM);

            if (params[5] != NULL)
            suffix = params[5];
            else
            suffix = "";
Esempio n. 8
0
/*
** Name: ParserGetVariable() - 
**
** Description:
**
** Inputs:
**	PPARSER_IN		in 
**	PPARSER_OUT		out
**
** Outputs:
**
** Returns:
**	GSTATUS	:	GSTAT_OK
**
** Exceptions:
**	None
**
** Side Effects:
**	None
**
** History:
*/
GSTATUS ParserGetVariable (
	PPARSER_IN		in, 
	PPARSER_OUT		out)
{
	GSTATUS err = GSTAT_OK;	
	PVAR_PARSER_OUT pout;
	u_i4 length;
	char*	name = NULL;
	u_i4	nlen = 0;
	char*	value = NULL;
	u_i4	vlen = 0;
	char	nullval[] = "";

	pout = (PVAR_PARSER_OUT) out;

	if (pout->namePos == 0) 
	{
		err = DDFStatusAlloc(E_WS0012_WSS_VAR_BAD_NAME);
	} 
	else 
	{
		length = in->current - in->position;
    if (length > 0)
    {
      u_i4 size = ((((pout->valuePos + length) / 32) + 1) * 32);
      err = GAlloc(&pout->value, size, TRUE);
      if (err == GSTAT_OK)
      {
  		  MECOPY_VAR_MACRO(in->buffer + in->position, length, pout->value + pout->valuePos);
	  	  pout->valuePos += length;
      }
    }
		in->position = in->current+1;

		if (pout->namePos > 0 && pout->name[0] == VARIABLE_MARK)
			err = WSMGetVariable (
							pout->act_session, 
							pout->name + 1, 
							pout->namePos - 1, 
							&name, 
							WSM_SYSTEM | WSM_ACTIVE | WSM_USER);

		if (err == GSTAT_OK && name == NULL)
		{	
			name = pout->name;
			nlen = pout->namePos;
		}
		else
			nlen = STlength(name);

		if (pout->valuePos <= 0)
		{
			vlen = 1;
			value = nullval;
		}
		else
		{
			if (pout->value[0] == VARIABLE_MARK)
				err = WSMGetVariable (
							pout->act_session, 
							pout->value+ 1, 
							pout->valuePos - 1, 
							&value, 
							WSM_SYSTEM | WSM_ACTIVE | WSM_USER);

			if (err == GSTAT_OK && value == NULL)
			{
				value = pout->value;
				vlen = pout->valuePos;
			}
			else
				vlen = STlength(value);
		}
		err = WSMAddVariable (
					pout->act_session, 
					name, 
					nlen, 
					value, 
					vlen, 
					pout->type);
	}
  MEfree((PTR)pout->name);
	pout->name = NULL;
  MEfree((PTR)pout->value);
	pout->value = NULL;
	pout->namePos = 0;
	pout->valuePos = 0;
return(err); 
}
Esempio n. 9
0
/*
** Name: HandlerError
**
** Decription:
**      Function is catch all for states where events are unexpected.
**
** Inputs:
**      sess        ice session structure
**      line        pointer to the current line
**      linelen     length of the line
**
** Outputs:
**      pos         number of characters handled.
**
** Return:
**      GSTAT_OK    success
**      other       failure
**
** History:
**      23-Oct-98 (fanra01)
**          Created.
*/
static GSTATUS
HandlerError (WTS_SESSION* sess, char* line, i4  linelen, i4 * pos)
{
    return (DDFStatusAlloc(E_WS0088_WTS_INVALID_UPLOAD));
}