Ejemplo n.º 1
0
/* ========================================================================= */
struct query *read_request(struct query *q, int s, struct iobuf *b)
{
   size_t offset; 
   ssize_t got;
   int recvmore;
   char uri[MAX_URI_LENGTH];
   int method;

   offset = 0;
   recvmore = 1;
   while ( recvmore )
   {
      got = recv(s, b->buf + offset, b->size - offset, 0);

      if ( got < 0 )
      {
         if ( errno != EINTR )
         {
            if ( q )
               q->parse_failure |= UP_DEAD_SOCKET;
            else
            {
               /* NOTE:
                    ParseURLString() will allocate and initialize q if it is NULL.
                    So... it is possible that q might be NULL here. If it is, then
                    allocate it so we can pass the specific error. */
               if ( NULL == (q = (struct query *)malloc(sizeof(struct query))) )
               {
                  error_msg("ERROR: Failed to allocate memory for a query.");
                  pthread_exit((void *)1);
               }

               q->parse_failure = UP_DEAD_SOCKET;
            }

            error_msg("ERROR: Dropped connection on recv() call.\n");
            return(q);
         }
      }
      else
      {
         offset += got;
         b->eod += got;
         
         if ( got == 0 )
         {
            /* This should never happen */
            if ( offset > 10 ) /* Arbitrary number *somewhat* large enough to hold a request */
            {
               if (( b->buf[offset - 4] == '\r' ) &&
                   ( b->buf[offset - 3] == '\n' ) &&
                   ( b->buf[offset - 2] == '\r' ) &&
                   ( b->buf[offset - 1] == '\n' ))
               {
                  recvmore = 0;

                  parse_status_line(&method, uri, b->buf);
               }
            } /* If some data ( > 10 ) */
         }
         else
         {
            if ( offset > 10 ) /* Arbitrary number *somewhat* large enough to hold a request */
            {
               if (( b->buf[offset - 4] == '\r' ) &&
                   ( b->buf[offset - 3] == '\n' ) &&
                   ( b->buf[offset - 2] == '\r' ) &&
                   ( b->buf[offset - 1] == '\n' ))
               {
                  recvmore = 0;

                  parse_status_line(&method, uri, b->buf);
               }

            } /* If some data ( > 10 ) */
         } /* if ( got == 0 ) else */
      } /* if ( got < 0 ) else */
   } /* while recvmore */


   b->buf[b->eod] = 0; /* Terminate for safety */





   /* STUB: Enable this to see the http request header
      




      DEBUG_STUB("%s", b->buf);




   */

   switch(method)
   {
   case METHOD_GET:
      q = ParseURLString(q, uri);
      q->method = METHOD_GET;
      break;
   case METHOD_HEAD:
      q = ParseURLString(q, uri);
      q->method = METHOD_HEAD;
      break;
   case METHOD_OPTIONS:
      q = ParseURLString(q, NULL);         /* This insures that q has been allocated */
      q->method = METHOD_OPTIONS;
      break;
   case METHOD_POST:
      q = ParseURLString(q, uri);
      q->method = METHOD_POST;
      break;
   default:
      error_msg("ERROR: Unsupported request method.\n");
      q = ParseURLString(q, NULL);         /* This insures that q has been allocated */
      q->parse_failure |= UP_BAD_METHOD;
      break;
   }

   return(q);
}
Ejemplo n.º 2
0
BOOL CBCGPODBCGridCtrl::SetFieldData (	CDBVariant& varValue,
										CBCGPGridRow* pRow, 
										int nColumn, int /*nRow*/)
{
	ASSERT_VALID (pRow);

	CString strDBString;
	BOOL bIsText = FALSE;

	switch (varValue.m_dwType)
	{
	case DBVT_BOOL:
		pRow->ReplaceItem (nColumn, new CBCGPGridCheckItem ((varValue.m_boolVal & 1) != 0), FALSE, TRUE);
		break;

	case DBVT_UCHAR:
		pRow->GetItem (nColumn)->SetValue (varValue.m_chVal, FALSE);
		break;

	case DBVT_SHORT:
		pRow->GetItem (nColumn)->SetValue (varValue.m_iVal, FALSE);
		break;

	case DBVT_SINGLE:
		pRow->GetItem (nColumn)->SetValue (varValue.m_fltVal, FALSE);
		break;

	case DBVT_DOUBLE:
		pRow->GetItem (nColumn)->SetValue (varValue.m_dblVal, FALSE);
		break;

#ifndef _BCGPGRID_STANDALONE
	case DBVT_DATE:
		{
			TIMESTAMP_STRUCT* pTS = varValue.m_pdate;
			ASSERT (pTS != NULL);

			COleDateTime date (pTS->year, pTS->month, pTS->day,
				pTS->hour, pTS->minute, pTS->second);
			pRow->ReplaceItem (nColumn, new CBCGPGridDateTimeItem (date), FALSE, TRUE);
		}
		break;
#endif
	case DBVT_NULL:
		{
			//--------------------------------------------------------------
			// Check the field type: if it's a string, pass an empty string:
			//--------------------------------------------------------------
			CODBCFieldInfo fieldinfo;
			m_pRecordSet->GetODBCFieldInfo ((short) nColumn, fieldinfo);

			switch (fieldinfo.m_nSQLType)
			{
			case SQL_VARCHAR:
			case SQL_LONGVARCHAR:
			case SQL_WCHAR:
			case SQL_WVARCHAR:
			case SQL_WLONGVARCHAR:
				pRow->GetItem (nColumn)->SetValue (_T(""), FALSE);
				break;
			}
		}
		break;

#if _MSC_VER >= 1300
	case DBVT_ASTRING:
		strDBString = *varValue.m_pstringA;
		bIsText = TRUE;
		break;

	case DBVT_WSTRING:
		strDBString = *varValue.m_pstringW;
		bIsText = TRUE;
		break;
#endif

	case DBVT_STRING:
		strDBString = *varValue.m_pstring;
		bIsText = TRUE;
		break;

	case DBVT_LONG:
		pRow->GetItem (nColumn)->SetValue (varValue.m_lVal, FALSE);
		break;					
	}

	if (bIsText)
	{
		CString strTextToDisplay;
		CString strURL;

		if (ParseURLString (strDBString, strTextToDisplay, strURL))
		{
			pRow->ReplaceItem (nColumn, new CBCGPGridURLItem (strTextToDisplay, strURL), FALSE, TRUE);
		}
		else
		{
			pRow->GetItem (nColumn)->SetValue ((LPCTSTR) strDBString, FALSE);
		}
	}

	return TRUE;
}
//***************************************************************************
BOOL CBCGPDAOGridCtrl::OnAddData (CBCGPGridRow* pRow, 
								   int nColumn, int /*nRow*/)
{
	try
	{
		ASSERT_VALID (pRow);
		ASSERT_VALID (m_pRecordSet);
		ASSERT (!m_pRecordSet->IsEOF ());
		ASSERT (!m_pRecordSet->IsBOF ());

		COleVariant varValue;
		m_pRecordSet->GetFieldValue ((short) nColumn, varValue);

		if (varValue.vt == VT_BOOL)
		{
			pRow->ReplaceItem (nColumn, new CBCGPGridCheckItem (varValue.bVal != 0), FALSE, TRUE);
		}
#ifndef _BCGPGRID_STANDALONE
		else if (varValue.vt == VT_DATE)
		{
			pRow->ReplaceItem (nColumn, new CBCGPGridDateTimeItem (varValue.date), FALSE, TRUE);
		}
#endif
		else if (varValue.vt == VT_BSTR)
		{
			CString str = (LPCTSTR) V_BSTRT(&varValue);

			CString strTextToDisplay;
			CString strURL;

			if (ParseURLString (str, strTextToDisplay, strURL))
			{
				pRow->ReplaceItem (nColumn, new CBCGPGridURLItem (strTextToDisplay, strURL), FALSE, TRUE);
			}
			else
			{
				pRow->GetItem (nColumn)->SetValue ((LPCTSTR) str, FALSE);
			}
		}
		else if (varValue.vt == VT_NULL || varValue.vt == VT_EMPTY)
		{
			//--------------------------------------------------------------
			// Check the field type: if it's a string, pass an empty string:
			//--------------------------------------------------------------
			CDaoFieldInfo info;
			m_pRecordSet->GetFieldInfo (nColumn, info);

			switch (info.m_nType)
			{
			case dbText:
			case dbMemo:
				pRow->GetItem (nColumn)->SetValue (_T(""), FALSE);
			}
		}
		else
		{
			pRow->GetItem (nColumn)->SetValue (varValue, FALSE);
		}
	}
	catch (CDaoException* pEx)
	{
		OnDaoException (pEx);
		pEx->Delete ();
	}

	return TRUE;
}