コード例 #1
0
ファイル: php_core_lib.cpp プロジェクト: geekt/amule
/*
 * String buffer: almost same as regular 'string' class, but,
 * without reallocation when full. Instead, new buffer is
 * allocated, and added to list
 */
CWriteStrBuffer::CWriteStrBuffer()
{
	m_alloc_size = 1024;
	m_total_length = 0;

	AllocBuf();
}
コード例 #2
0
ファイル: dvinit.c プロジェクト: OS2World/DRV-PPtP
int init_once(RP rp)
{
	switch (done_init) {
	case 2:	/* fatal error */
		return 2;
	case 0:	/* must init */
		Device_Help = rp->pk.init.devhlp;

		/* read cmd line params */
		read_args(rp->pk.init.args);

		done_init = 1;	

		/* allocate memory */
		buf1 = AllocBuf(32l * sizeof(struct tty));
		buf2 = AllocBuf(32l * sizeof(struct tty));

		if (!buf1 || !buf2)
		{
			/* fatal */
			rp->pk.initexit.cs = 0;
			rp->pk.initexit.ds = 0;
			done_init = 2;
			return 2;
		}

		DosPutMessage(1, sizeof(version_msg) - 1, version_msg);
		DosPutMessage(1, sizeof(once_msg) - 1, once_msg);
		if (dbgflag)
		{
			DosPutMessage(1, sizeof(dbg_msg) - 1, dbg_msg);
			int3();
		}

		/* fall thru */
	case 1: /* ok */
#define GETSEL(ptr) ((USHORT)(((ULONG)((void far*)ptr)>>16)&0xffff))
		SegLimit(GETSEL(DiscardProc),&rp->pk.initexit.cs);
		SegLimit(GETSEL(&DiscardData),&rp->pk.initexit.ds);
	}
	return 1;
}
コード例 #3
0
bool CBaseHttp::HandleResponse(CHttpResponse *pobjRes, HttpInfo *pInfo, bool bGetCookies)
{
	LogObject;
	bool bRet = false;
	if(pobjRes)
	{
		DWORD dwStatus = pobjRes->GetStatus();
		if(dwStatus >= 400)
		{
			char cl[8] = {0};
			sprintf(cl, "%d", dwStatus);
			string str = "Recv error =";
			str += cl;

			//LogOutError(str);
			if (dwStatus == STATUS_CODE_FORBIDDEN && (m_dwIgnoreFlag & IGNORE_FORBID))
			{  
				m_dwIgnoreFlag = IGNORE_NORMAL;  //reset
			}
			else
			{
				return bRet;
			}
		}

		DWORD dwLen = 0;
		pobjRes->GetContentLength(dwLen);
		if(dwLen < 1)
			dwLen = MAX_BUF_SIZE;
		else
			dwLen += 1;

		AllocBuf(dwLen);
		DWORD dwRead = 0;
		while(dwRead = pobjRes->ReadContent(m_httpData.pData + m_httpData.nDataLen, dwLen - m_httpData.nDataLen))  //sherrypan modify  
		{
			m_httpData.nDataLen += dwRead;
			if(m_httpData.nDataLen >= dwLen)
				break;
		}

		bRet = m_httpData.nDataLen > 0;

		if(bRet && bGetCookies)
		{
			//base_string::BAString strAUrl(pInfo->strUrl.c_str());
			HandleCookies(pInfo->strUrl.c_str());
		}
	}

	return bRet;
}
コード例 #4
0
ファイル: sguser.c プロジェクト: samprager/KC705_DDS
int myGetRxPkt(void * hndl, PktBuf * vaddr, unsigned int size, int numpkts, unsigned int privdata)
{
    unsigned char * bufVA;
    PktBuf * pbuf;
    int i;

    //printk(KERN_INFO "myGetRxPkt: Came with handle %p size %d privdata %x\n",
    //                        hndl, size, privdata);

    /* Check driver state */
    if(DriverState != REGISTERED)
    {
        printk("Driver does not seem to be ready\n");
        return 0;
    }

    /* Check handle value */
    if(hndl != handle[2])
    {
        printk("Came with wrong handle\n");
        return 0;
    }

    /* Check size value */
    if(size != BUFSIZE)
        printk("myGetRxPkt: Requested size %d does not match mine %d\n",
               size, (u32)BUFSIZE);

    spin_lock_bh(&RawLock);

    for(i=0; i<numpkts; i++)
    {
        pbuf = &(vaddr[i]);
        /* Allocate a buffer. DMA driver will map to PCI space. */
        bufVA = AllocBuf(&RxBufs);
        log_verbose(KERN_INFO "myGetRxPkt: The buffer after alloc is at address %x size %d\n",
                    (u32) bufVA, (u32) BUFSIZE);
        if (bufVA == NULL)
        {
            log_normal(KERN_ERR "RX: AllocBuf failed\n");
            break;
        }

        pbuf->pktBuf = bufVA;
        pbuf->bufInfo = bufVA;
        pbuf->size = BUFSIZE;
    }
    spin_unlock_bh(&RawLock);

    log_verbose(KERN_INFO "Requested %d, allocated %d buffers\n", numpkts, i);
    return i;
}
コード例 #5
0
bool INICOL::SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check)
  {
  if (!(To_Val = value)) {
    sprintf(g->Message, MSG(VALUE_ERROR), Name);
    return true;
  } else if (Buf_Type == value->GetType()) {
    // Values are of the (good) column type
    if (Buf_Type == TYPE_DATE) {
      // If any of the date values is formatted
      // output format must be set for the receiving table
      if (GetDomain() || ((DTVAL *)value)->IsFormatted())
        goto newval;          // This will make a new value;

    } else if (Buf_Type == TYPE_DOUBLE || Buf_Type == TYPE_DECIM)
      // Float values must be written with the correct (column) precision
      // Note: maybe this should be forced by ShowValue instead of this ?
      value->SetPrec(GetScale());

    Value = value;            // Directly access the external value
  } else {
    // Values are not of the (good) column type
    if (check) {
      sprintf(g->Message, MSG(TYPE_VALUE_ERR), Name,
              GetTypeName(Buf_Type), GetTypeName(value->GetType()));
      return true;
      } // endif check

 newval:
    if (InitValue(g))         // Allocate the matching value block
      return true;

  } // endif's Value, Buf_Type

  // Allocate the internal value buffer
  AllocBuf(g);

  // Because Colblk's have been made from a copy of the original TDB in
  // case of Update, we must reset them to point to the original one.
  if (To_Tdb->GetOrig())
    To_Tdb = (PTDB)To_Tdb->GetOrig();

  // Set the Column
  Status = (ok) ? BUF_EMPTY : BUF_NO;
  return false;
  } // end of SetBuffer
コード例 #6
0
// Open wave output file, 
// fname is file name, channels number of outputs
// This is only designed for chnls = 1 or 2
int WaveFile::OpenWaveFile(const char *fname, int chnls)
{
	wfp.FileClose();
	if (AllocBuf(synthParams.isampleRate * bufSecs * chnls, chnls))
		return -3;

	SetupWH(chnls);
	sampleTotal = 0;

	if (wfp.FileOpen(fname))
		return -1;

	if (wfp.FileWrite(&wh, sizeof(wh)) != sizeof(wh))
	{
		wfp.FileClose();
		return -2;
	}

	sampleOOR = 0;
	return 0;
}
コード例 #7
0
ファイル: php_core_lib.cpp プロジェクト: geekt/amule
void CWriteStrBuffer::Write(const char *s, int len)
{
	if ( len == -1 ) {
		len = strlen(s);
	}
	m_total_length += len;

	while ( len ) {
		if ( (len + 1) <= m_curr_buf_left ) {
			strncpy(m_buf_ptr, s, len);
			m_buf_ptr += len;
			m_curr_buf_left -= len;
			len = 0;
		} else {
			memcpy(m_buf_ptr, s, m_curr_buf_left);
			int rem_len = len - m_curr_buf_left;
			s += m_curr_buf_left;

			len = rem_len;
			m_buf_list.push_back(m_curr_buf);
			AllocBuf();
		}
	}
}
コード例 #8
0
bool CBaseHttp::HttpsPostA(HttpInfo &info, bool bGetCookies/* = false*/, int nTryCount/* = 5)*/)
{
	URL_COMPONENTSA crackedURL;

	char szHostName[128] = {0};
	char szUrlPath[256] = {0};

	string strUrl = info.strUrl.c_str();
	bool nRet = false;

	string postData = "";
	vector<HttpParam>::iterator iter = info.vecParam.begin();
	while(iter != info.vecParam.end())
	{
		postData += iter->strName;
		postData += "=";
		postData += iter->strValue;
		postData += "&";
		iter++;
	}
	string strPostData = postData.c_str();

	ZeroMemory(&crackedURL, sizeof (crackedURL));
	crackedURL.dwStructSize = sizeof (crackedURL);
	crackedURL.lpszHostName = szHostName;
	crackedURL.dwHostNameLength = (sizeof(szHostName)/sizeof(char))-1;
	crackedURL.lpszUrlPath = szUrlPath; 
	crackedURL.dwUrlPathLength = (sizeof(szUrlPath)/sizeof(char))-1;

	::InternetCrackUrlA(strUrl.c_str(), (DWORD)strUrl.length(), 0, &crackedURL);

	DWORD dwFlags = 0;
	::InternetGetConnectedState(&dwFlags, 0);

	const char *pstrAgent = "NetWorld User Agent v1.0";
	HINTERNET hHttpOpen = NULL;
	HINTERNET hHttpConn = NULL;

	if(!(dwFlags & INTERNET_CONNECTION_PROXY))
	{
		hHttpOpen = ::InternetOpenA(pstrAgent, INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY, NULL, NULL, 0);
	}
	else
	{
		hHttpOpen = ::InternetOpenA(pstrAgent, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
	}

	if(hHttpOpen == NULL)
	{
		//SetLastError("HTTP初始化失败");
		return false;
	}

	//建立HTTP连接
	hHttpConn = ::InternetConnectA(hHttpOpen, crackedURL.lpszHostName, crackedURL.nPort, 
		NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);

	if(hHttpConn == NULL)
	{
		//SetLastError("HTTP连接失败,请检查网络连接");
		::InternetCloseHandle(hHttpOpen);
		return false;
	}

	//创建一个URL请求
	HINTERNET hHttpReq = ::HttpOpenRequestA(hHttpConn, "POST", crackedURL.lpszUrlPath, NULL, "", NULL, INTERNET_FLAG_SECURE, 0);

	if(hHttpReq == NULL)
	{
		//SetLastError("HTTP创建URL请求失败,请检查网络连接");
		::InternetCloseHandle(hHttpOpen);
		::InternetCloseHandle(hHttpConn);
		return false;
	}

	string strHeader = "Content-type: application/x-www-form-urlencoded\r\n";

	if (!::HttpAddRequestHeadersA(hHttpReq, strHeader.c_str(), strHeader.length(), HTTP_ADDREQ_FLAG_ADD))
	{
		goto _exit;
	}

	DWORD dwContLen = 0;
	DWORD dwLen = 0;
	BOOL  bResult = FALSE;
	DWORD nBytesGet = 0;
	DWORD dwRetCode = 0;
	DWORD dwSizeOfRq = sizeof(DWORD);
	char szLen[64] = {0};
	dwSizeOfRq = sizeof(szLen)/sizeof(char);
	//const char * strPostData = postData.c_str();

	//const char *pHeader = L"GET / HTTP/1.1 \nAccept: */* \nAccept-Language: zh-cn \nAccept-Encoding: gzip, deflate \nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) \n";

	if (::HttpSendRequestA(hHttpReq, 0, 0, (void *)strPostData.c_str(), strPostData.length()) && 
		::HttpQueryInfoA(hHttpReq, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &dwRetCode, &dwSizeOfRq, NULL) && 
		dwRetCode < 400)
	{
		::HttpQueryInfoA(hHttpReq, HTTP_QUERY_CONTENT_LENGTH, &szLen, &dwSizeOfRq, NULL);
		DWORD dwRet = ::GetLastError();
		if(strlen(szLen) < 1)
			dwContLen = MAX_BUF_SIZE;
		else
			dwContLen = atoi(szLen);

		if(dwContLen < 1)
			goto _exit;

		AllocBuf(dwContLen+1);

		m_httpData.nDataLen = 0;
		while(TRUE)
		{
			if (!::InternetReadFile(hHttpReq, m_httpData.pData, dwContLen, &dwLen))
			{
				break;
			}

			m_httpData.nDataLen += dwLen;
			if(m_httpData.nDataLen >= dwContLen || dwLen == 0)
			{
				nRet = true;
				break;
			}
		}

		/*if(bGetCookies)
		{
		DWORD dwCookieSize = 0;
		base_help::BAString strCookie(strUrl.c_str());
		::InternetGetCookieA(strCookie.c_str(), "", NULL, &dwCookieSize);
		if(dwCookieSize > 0)
		{
		char *pCookies = new char[dwCookieSize+1];
		memset(pCookies, 0, dwCookieSize+1);
		::InternetGetCookieA(strCookie.c_str(), "", pCookies, &dwCookieSize);
		m_Cookies.SetCookies(_Bstring(pCookies));
		delete[] pCookies;
		}
		}*/
	}

_exit:
	::InternetCloseHandle(hHttpReq);
	::InternetCloseHandle(hHttpConn);
	::InternetCloseHandle(hHttpOpen);

	return true;
}
コード例 #9
0
ファイル: sguser.c プロジェクト: samprager/KC705_DDS
static int DmaSetupTransmit(void * hndl, int num)
{
    int i, result;
    static int pktsize=0;
    int total, bufsize, fragment;
    int bufindex;
    unsigned char * bufVA;
    PktBuf * pbuf;
    int origseqno;
    //static unsigned short lastno=0;

    log_verbose("Reached DmaSetupTransmit with handle %p, num %d\n", hndl, num);

    /* Check driver state */
    if(DriverState != REGISTERED)
    {
        printk("Driver does not seem to be ready\n");
        return 0;
    }

    /* Check handle value */
    if(hndl != handle[0])
    {
        printk("Came with wrong handle\n");
        return 0;
    }

    /* Check number of packets */
    if(!num)
    {
        printk("Came with 0 packets for sending\n");
        return 0;
    }

    /* Hold the spinlock only when calling the buffer management APIs. */
    spin_lock_bh(&RawLock);
    origseqno = TxSeqNo;
    for(i=0, bufindex=0; i<num; i++)            /* Total packets loop */
    {
        //printk("i %d bufindex %d\n", i, bufindex);

        /* Fix the packet size to be the maximum entered in GUI */
        pktsize = RawMaxPktSize;

        //printk("pktsize is %d\n", pktsize);

        total = 0;
        fragment = 0;
        while(total < pktsize)      /* Packet fragments loop */
        {
            //printk("Buf loop total %d bufindex %d\n", total, bufindex);

            pbuf = &(pkts[bufindex]);

            /* Allocate a buffer. DMA driver will map to PCI space. */
            bufVA = AllocBuf(&TxBufs);

            log_verbose(KERN_INFO "TX: The buffer after alloc is at address %x size %d\n",
                        (u32) bufVA, (u32) BUFSIZE);
            if (bufVA == NULL)
            {
                //printk("TX: AllocBuf failed\n");
                //printk("[%d]", (num-i-1));
                break;
            }
            pbuf->pktBuf = bufVA;
            pbuf->bufInfo = bufVA;
            bufsize = ((total + BUFSIZE) > pktsize) ?
                      (pktsize - total) : BUFSIZE ;
            total += bufsize;

            //printk("bufsize %d total %d\n", bufsize, total);

            log_verbose(KERN_INFO "Calling FormatBuffer pktsize %d bufsize %d fragment %d\n",
                        pktsize, bufsize, fragment);
            FormatBuffer(bufVA, pktsize, bufsize, fragment);

            pbuf->size = bufsize;
            pbuf->userInfo = TxSeqNo;
            pbuf->flags = PKT_ALL;
            if(!fragment)
                pbuf->flags |= PKT_SOP;
            if(total == pktsize)
            {
                pbuf->flags |= PKT_EOP;
                pbuf->size = bufsize;
            }

            //printk("flags %x\n", pbuf->flags);
            //printk("TxSeqNo %u\n", TxSeqNo);

            bufindex++;
            fragment++;
        }
        if(total < pktsize)
        {
            /* There must have been some error in the middle of the packet */

            if(fragment)
            {
                /* First, adjust the number of buffers to queue up or else
                 * partial packets will get transmitted, which will cause a
                 * problem later.
                 */
                bufindex -= fragment;

                /* Now, free any unused buffers from the partial packet, so
                 * that buffers are not lost.
                 */
                log_normal(KERN_ERR "Tried to send pkt of size %d, only %d fragments possible\n",
                           pktsize, fragment);
                FreeUnusedBuf(&TxBufs, fragment);
            }
            break;
        }


        /* Increment packet sequence number */
        //if(lastno != TxSeqNo) printk(" %u-%u.", lastno, TxSeqNo);
        TxSeqNo++;
        //lastno = TxSeqNo;
    }
    spin_unlock_bh(&RawLock);

    //printk("[p%d-%d-%d] ", num, i, bufindex);

    if(i == 0)
        /* No buffers available */
        return 0;

    log_verbose("%s: Sending packet length %d seqno %d\n",
                MYNAME, pktsize, TxSeqNo);
    result = DmaSendPkt(hndl, pkts, bufindex);
    TxBufCnt += result;
    if(result != bufindex)
    {
        log_normal(KERN_ERR "Tried to send %d pkts in %d buffers, sent only %d\n",
                   num, bufindex, result);
        //printk("[s%d-%d,%d-%d]", bufindex, result, TxSeqNo, origseqno);
        if(result) TxSeqNo = pkts[result].userInfo;
        else TxSeqNo = origseqno;
        //printk("-%u-", TxSeqNo);
        //lastno = TxSeqNo;

        spin_lock_bh(&RawLock);
        FreeUnusedBuf(&TxBufs, (bufindex-result));
        spin_unlock_bh(&RawLock);
        return 0;
    }
    else return 1;
}
コード例 #10
0
ファイル: tmisc.cpp プロジェクト: nianhuaxpj/ipmsg
/*=========================================================================
  クラス : VBuf
  概  要 : 仮想メモリ管理クラス
  説  明 : 
  注  意 : 
=========================================================================*/
VBuf::VBuf(int _size, int _max_size, VBuf *_borrowBuf)
{
	Init();

	if (_size || _max_size) AllocBuf(_size, _max_size, _borrowBuf);
}