Example #1
0
void dswapVector3(sparseVector *sparse1, sparseVector *sparse2, int indexStart, int indexEnd)
{

  REAL *dense1, *dense2;

  if(indexStart<=0)
    indexStart = 1;
  if(indexEnd<=0)
    indexEnd = MAX(lastIndex(sparse1), lastIndex(sparse2));

  if(indexStart <= firstIndex(sparse1) && indexStart <= firstIndex(sparse2) && 
     indexEnd >= lastIndex(sparse1) && indexEnd >= lastIndex(sparse2)) {
    swapVector(sparse1, sparse2);
  }
  else {

    CALLOC(dense1, (indexEnd+1));
    CALLOC(dense2, (indexEnd+1));
    getVector(sparse1, dense1, indexStart, indexEnd, TRUE);
    getVector(sparse2, dense2, indexStart, indexEnd, TRUE);
    clearVector(sparse1, indexStart, indexEnd);
    clearVector(sparse2, indexStart, indexEnd);
    putVector(sparse1, dense2, indexStart, indexEnd);
    putVector(sparse2, dense1, indexStart, indexEnd);
    MEMFREE(dense1);
    MEMFREE(dense2);
  }
}
Example #2
0
VOID
PARSEROBJ_Delete(
    PPARSEROBJ  pParserObj
    )

/*++

Routine Description:

    Delete a parser object

Arguments:

    pParserObj - Pointer to parser object to be deleted

Return Value:

    NONE

--*/

{
    ASSERT(pParserObj != NULL);

    // Free the buffer which is used to hold the value
    // field from a PPD entry.

    MEMFREE(pParserObj->value.pBuffer);

    // Free the parser object itself.

    MEMFREE(pParserObj);
}
Example #3
0
void freeVector(sparseVector *sparse)
{
	if(sparse != NULL) {
    MEMFREE(sparse->value);
    MEMFREE(sparse->index);
    MEMFREE(sparse);
  }
}
Example #4
0
NPError OIPF_NPP_Destroy(NPP instance, NPSavedData **save)
{
    TRACEINFO;
    HBBTVPluginData* pdata = (HBBTVPluginData*)instance->pdata;
    if (pdata)
    {
        sBrowserFuncs->releaseobject(pdata->obj);
        MEMFREE(pdata->type);
        MEMFREE(pdata);
    }
    return NPERR_NO_ERROR;
}
Example #5
0
//This function gets HWND of the window, the number, and the message.
void StartSmsSend(HWND hWndDlg,SIZE_T dwModuleIndex,LPWSTR lpwszPhone,SIZE_T dwPhoneSize,LPWSTR lpwszMessage,SIZE_T dwMessageSize)
{
	if (ssSMSSettings.ppaSMSAccounts && dwModuleIndex!=-1 && dwModuleIndex<ssSMSSettings.dwSMSAccountsCount)
	{
		LPSTR lpszMessageUTF;
		LPWSTR lpwszMessageXMLEncoded;
		SIZE_T dwMessageUTFBuffSize,dwMessageXMLEncodedSize,dwBuffSize;
		DBEVENTINFO *pdbei;

		dwMessageXMLEncodedSize=((dwMessageSize+MAX_PATH)*sizeof(WCHAR)*6);
		lpwszMessageXMLEncoded=(LPWSTR)MEMALLOC(dwMessageXMLEncodedSize);
		if (lpwszMessageXMLEncoded)
		{
			EncodeXML(lpwszMessage,dwMessageSize,lpwszMessageXMLEncoded,(dwMessageXMLEncodedSize/sizeof(WCHAR)),&dwMessageXMLEncodedSize);

			dwMessageUTFBuffSize=(dwMessageXMLEncodedSize+MAX_PATH);
			lpszMessageUTF=(LPSTR)MEMALLOC(dwMessageUTFBuffSize);
			if (lpszMessageUTF)
			{
				dwBuffSize=(dwPhoneSize+MAX_PATH+WideCharToMultiByte(CP_UTF8,0,lpwszMessage,dwMessageSize,lpszMessageUTF,dwMessageUTFBuffSize,NULL,NULL));
				pdbei=(DBEVENTINFO*)MEMALLOC((sizeof(DBEVENTINFO)+dwBuffSize));
				if (pdbei)
				{
					char szPhone[MAX_PHONE_LEN];
					LPSTR lpszBuff=(LPSTR)(pdbei+1);
					HANDLE hProcess;

					WideCharToMultiByte(CP_UTF8,0,lpwszPhone,dwPhoneSize,szPhone,MAX_PHONE_LEN,NULL,NULL);
					dwPhoneSize=CopyNumberA(szPhone,szPhone,dwPhoneSize);

					pdbei->timestamp=time(NULL);
					pdbei->flags=(DBEF_SENT|DBEF_UTF);
					pdbei->eventType=ICQEVENTTYPE_SMS;
					pdbei->cbBlob=(mir_snprintf(lpszBuff,dwBuffSize,"SMS To: +%s\r\n%s",szPhone,lpszMessageUTF)+4);
					pdbei->pBlob=(PBYTE)lpszBuff;
					SendSMSWindowDbeiSet(hWndDlg,pdbei);

					char *szProto = ssSMSSettings.ppaSMSAccounts[dwModuleIndex]->szModuleName;
					if ( ProtoServiceExists(szProto, MS_ICQ_SENDSMS)) {
						WideCharToMultiByte(CP_UTF8,0,lpwszMessageXMLEncoded,dwMessageXMLEncodedSize,lpszMessageUTF,dwMessageUTFBuffSize,NULL,NULL);
						hProcess = (HANDLE)ProtoCallService(szProto, MS_ICQ_SENDSMS, (WPARAM)szPhone,(LPARAM)lpszMessageUTF);
						SendSMSWindowHProcessSet(hWndDlg,hProcess);
					}
					else MEMFREE(pdbei);
				}
				MEMFREE(lpszMessageUTF);
			}
			MEMFREE(lpwszMessageXMLEncoded);
		}
	}
}
Example #6
0
VOID
FILEOBJ_Delete(
    PFILEOBJ    pFileObj
    )

/*++

Routine Description:

    Delete a file object returned by FILEOBJ_Create

Arguments:

    pFileObj - Pointer to the file object to be deleted

Return Value:

    NONE

--*/

{
    ASSERT(pFileObj != NULL);

    // Unload the file from memory

    FREEMODULE(pFileObj->hModule);

    // Free the file buffer

    MEMFREE(pFileObj);
}
Example #7
0
DWORD MraSendQueueFree(HANDLE hSendQueueHandle,DWORD dwCMDNum)
{
	DWORD dwRetErrorCode;

	if (hSendQueueHandle)
	{
		MRA_SEND_QUEUE *pmrasqSendQueue=(MRA_SEND_QUEUE*)hSendQueueHandle;
		MRA_SEND_QUEUE_ITEM *pmrasqiSendQueueItem;
		LIST_MT_ITERATOR lmtiIterator;

		dwRetErrorCode=ERROR_NOT_FOUND;
		ListMTLock(&pmrasqSendQueue->lmtListMT);
		ListMTIteratorMoveFirst(&pmrasqSendQueue->lmtListMT,&lmtiIterator);
		do
		{// цикл
			if (ListMTIteratorGet(&lmtiIterator,NULL,(LPVOID*)&pmrasqiSendQueueItem)==NO_ERROR)
			if (pmrasqiSendQueueItem->dwCMDNum==dwCMDNum)
			{
				ListMTItemDelete(&pmrasqSendQueue->lmtListMT,&pmrasqiSendQueueItem->lmtListMTItem);
				//MEMFREE(pmrasqiSendQueueItem->lpbData);
				MEMFREE(pmrasqiSendQueueItem);
				dwRetErrorCode=NO_ERROR;
				break;
			}
		}while(ListMTIteratorMoveNext(&lmtiIterator));
		ListMTUnLock(&pmrasqSendQueue->lmtListMT);
	}else{
		dwRetErrorCode=ERROR_INVALID_HANDLE;
	}
return(dwRetErrorCode);
}
Example #8
0
void dswapVector1(sparseVector *sparse, REAL *dense, int indexStart, int indexEnd)
{
  int i, d, n;
  REAL *x;

  if(indexStart <= 0)
    indexStart = 1;
  n = lastIndex(sparse);
  if(indexEnd <= 0) 
    indexEnd = n;
  CALLOC(x, (MAX(indexEnd,n)+1));

  getVector(sparse, x, indexStart, n, FALSE);
  d = getDiagonalIndex(sparse);
  clearVector(sparse, indexStart, n);
  for(i = indexStart; i<=indexEnd; i++) {
    if(dense[i] != 0)
      putItem(sparse, i, dense[i]);
  }
  for(i = indexEnd+1; i<=n; i++) {
    if(x[i] != 0)
      putItem(sparse, i, x[i]);
  }
  MEMCOPY(&dense[indexStart], &x[indexStart], (indexEnd-indexStart+1));

#ifdef DEBUG_SPARSELIB
  verifyVector(sparse);
#endif
  
  MEMFREE(x);
}
Example #9
0
  void        APPLICATION_Deallocate(NPObject* obj)
{
    TRACEINFO;
    NPObj_Application* applicationobj = (NPObj_Application*)obj;
    sBrowserFuncs->releaseobject(applicationobj->privateData);
    MEMFREE(applicationobj);
    return;
}
Example #10
0
  void        OAM_Deallocate(NPObject* obj)
{
    TRACEINFO;
    NPObj_OAM* oamobj = (NPObj_OAM*)obj;
    sBrowserFuncs->releaseobject(oamobj->ownerApplication);    
    MEMFREE(oamobj);
    return;
}
Example #11
0
PFILEOBJ
FILEOBJ_Create(
    PCWSTR  pwstrFilename,
    WORD   *pwChecksum
    )

/*++

Routine Description:

    Create a file object

Arguments:

    pwstrFilename - Pointer to fully qualified Unicode filename
    pwChecksum - Pointer to a 16-bit crc checksum variable

Return Value:

    Pointer to newly created file object
    NULL if an error occured

--*/

{
    PFILEOBJ    pFileObj;

    // Allocate space for a file object

    pFileObj = (PFILEOBJ) MEMALLOC(sizeof(FILEOBJ));

    if (pFileObj != NULL) {

        // Save the pointer to checksum variable

        pFileObj->pwChecksum = pwChecksum;

        // Map the file into memory

        if (! MAPFILE(
                pwstrFilename,
                &pFileObj->hModule,
                (PBYTE*) &pFileObj->pNextChar,
                &pFileObj->cbAvailable))
        {
            DBGERRMSG("MAPFILE");
            MEMFREE(pFileObj);
            pFileObj = NULL;
        }
    } else {

        // Failed to allocate memory

        DBGERRMSG("MEMALLOC");
    }

    return pFileObj;
}
Example #12
0
void do_flag(dbref executor, dbref caller, dbref enactor, int eval, int key, int nargs,
             UTF8 *flag1, UTF8 *flag2, const UTF8 *cargs[], int ncargs)
{
    UNUSED_PARAMETER(caller);
    UNUSED_PARAMETER(enactor);
    UNUSED_PARAMETER(eval);
    UNUSED_PARAMETER(cargs);
    UNUSED_PARAMETER(ncargs);

    if (key & FLAG_REMOVE)
    {
        if (nargs == 2)
        {
            notify(executor, T("Extra argument ignored."));
        }
        int nAlias;
        bool bValidAlias;
        UTF8 *pCheckedAlias = MakeCanonicalFlagName(flag1, &nAlias, &bValidAlias);
        if (bValidAlias)
        {
            FLAGNAMEENT *lookup;
            lookup = (FLAGNAMEENT *)hashfindLEN(pCheckedAlias, nAlias, &mudstate.flags_htab);
            if (lookup)
            {
                if (  lookup->flagname != lookup->pOrigName
                   && mux_stricmp(lookup->flagname, pCheckedAlias) == 0)
                {
                    MEMFREE(lookup->flagname);
                    lookup->flagname = (UTF8 *)lookup->pOrigName;
                    hashdeleteLEN(pCheckedAlias, nAlias, &mudstate.flags_htab);
                    notify(executor, tprintf(T("Flag name \xE2\x80\x98%s\xE2\x80\x99 removed from the hash table."), pCheckedAlias));
                }
                else
                {
                    notify(executor, T("Error: You can\xE2\x80\x99t remove the present flag name from the hash table."));
                }
            }
        }
    }
    else
    {
        if (nargs < 2)
        {
            notify(executor, T("You must specify a flag and a name."));
            return;
        }
        if (flag_rename(flag1, flag2))
        {
            notify(executor, T("Flag name changed."));
        }
        else
        {
            notify(executor, T("Error: Bad flagname given or flag not found."));
        }
    }
}
Example #13
0
File: start.c Project: Ttech/naev
/**
 * @brief Cleans up after the module start data.
 */
void start_cleanup (void)
{
   MEMFREE( start_data.name );
   MEMFREE( start_data.ship );
   MEMFREE( start_data.system );
   MEMFREE( start_data.mission );
   MEMFREE( start_data.event );
   MEMFREE( start_data.tutsys );
   MEMFREE( start_data.tutmisn );
   MEMFREE( start_data.tutevt );
   memset( &start_data, 0, sizeof(start_data) );
}
Example #14
0
// NFY_DRAIN or NFY_NFYALL
//
static int CallBack_NotifySemaphoreDrainOrAll(PTASK_RECORD p)
{
    if (p->fpTask == Task_SemaphoreTimeout)
    {
        // This represents a semaphore.
        //
        BQUE *point = (BQUE *)(p->arg_voidptr);
        if (  point->sem == Notify_Sem
           && (  point->attr == Notify_Attr
              || !Notify_Attr))
        {
            Notify_Num_Done++;
            if (Notify_Key == NFY_DRAIN)
            {
                // Discard the command
                //
                giveto(point->executor, mudconf.waitcost);
                a_Queue(Owner(point->executor), -1);

                for (int i = 0; i < MAX_GLOBAL_REGS; i++)
                {
                    if (point->scr[i])
                    {
                        RegRelease(point->scr[i]);
                        point->scr[i] = NULL;
                    }
                }

                MEMFREE(point->text);
                point->text = NULL;
                free_qentry(point);

                return IU_REMOVE_TASK;
            }
            else
            {
                // Allow the command to run. The priority may have been
                // PRIORITY_SUSPEND, so we need to change it.
                //
                if (isPlayer(point->enactor))
                {
                    p->iPriority = PRIORITY_PLAYER;
                }
                else
                {
                    p->iPriority = PRIORITY_OBJECT;
                }
                p->ltaWhen.GetUTC();
                p->fpTask = Task_RunQueueEntry;
                return IU_UPDATE_TASK;
            }
        }
    }
    return IU_NEXT_TASK;
}
Example #15
0
void MraSendQueueDestroy(HANDLE hSendQueueHandle)
{
	if (hSendQueueHandle)
	{
		MRA_SEND_QUEUE *pmrasqSendQueue=(MRA_SEND_QUEUE*)hSendQueueHandle;
		MRA_SEND_QUEUE_ITEM *pmrasqiSendQueueItem;

		ListMTLock(&pmrasqSendQueue->lmtListMT);
		while(ListMTItemGetFirst(&pmrasqSendQueue->lmtListMT,NULL,(LPVOID*)&pmrasqiSendQueueItem)==NO_ERROR)
		{
			ListMTItemDelete(&pmrasqSendQueue->lmtListMT,&pmrasqiSendQueueItem->lmtListMTItem);
			//MEMFREE(pmrasqiSendQueueItem->lpbData);
			MEMFREE(pmrasqiSendQueueItem);
		}
		ListMTUnLock(&pmrasqSendQueue->lmtListMT);

		ListMTDestroy(&pmrasqSendQueue->lmtListMT);
		MEMFREE(pmrasqSendQueue);
	}
}
Example #16
0
static int CallBack_HaltQueue(PTASK_RECORD p)
{
    if (  p->fpTask == Task_RunQueueEntry
#ifdef QUERY_SLAVE
       || p->fpTask == Task_SQLTimeout
#endif // QUERY_SLAVE
       || p->fpTask == Task_SemaphoreTimeout)
    {
        // This is a @wait, timed Semaphore Task, or timed SQL Query.
        //
        BQUE *point = (BQUE *)(p->arg_voidptr);
        if (que_want(point, Halt_Player_Target, Halt_Object_Target))
        {
            // Accounting for pennies and queue quota.
            //
            dbref dbOwner = point->executor;
            if (!isPlayer(dbOwner))
            {
                dbOwner = Owner(dbOwner);
            }
            if (dbOwner != Halt_Player_Run)
            {
                if (Halt_Player_Run != NOTHING)
                {
                    giveto(Halt_Player_Run, mudconf.waitcost * Halt_Entries_Run);
                    a_Queue(Halt_Player_Run, -Halt_Entries_Run);
                }
                Halt_Player_Run = dbOwner;
                Halt_Entries_Run = 0;
            }
            Halt_Entries++;
            Halt_Entries_Run++;
            if (p->fpTask == Task_SemaphoreTimeout)
            {
                add_to(point->sem, -1, point->attr);
            }

            for (int i = 0; i < MAX_GLOBAL_REGS; i++)
            {
                if (point->scr[i])
                {
                    RegRelease(point->scr[i]);
                    point->scr[i] = NULL;
                }
            }

            MEMFREE(point->text);
            point->text = NULL;
            free_qentry(point);
            return IU_REMOVE_TASK;
        }
    }
    return IU_NEXT_TASK;
}
Example #17
0
void mem_pool::pool_free( void* ptr, size_t bytes )
{
    if( ptr )
        pool_dealloc( ptr, bytes );

    if( bytes <= MEMORY_POOL_MAX )
    {
        int i;
        size_t index = LIST_INDEX( bytes );
        size_t blk_count = BLOCK_COUNT( index );
        mempage_t *erase = NULL, *prev = NULL, *curr = pool[index].first;

        if( pool_lock )
            pool_lock( index );

        while( curr )
        {
            if( curr->count != blk_count ) /* 判断是否是空闲页 */
            {
                prev = curr;
                curr = curr->next;
            }
            else
            {
                /* 从页面缓存中退出 */
                for( i = 0; i < MEMORY_POOL_BUFFER; ++i )
                {
                    if( pool[index].buffer[i] == curr )
                    {
                        pool[index].buffer[i] = NULL;
                        break;
                    }
                }

                if( prev )
                    prev->next = curr->next; /* 空闲页不在链首 */
                else
                    pool[index].first = curr->next; /* 空闲页在链首 */

                /* 将空闲页释放 */
                erase = curr;
                curr = curr->next;
                MEMFREE( erase );
                --( pool[index].useable );
            } /* end if */
        } /* end while */

        if( pool_unlock )
            pool_unlock( index );
    }
}
Example #18
0
// do_flag: Rename flags or remove flag aliases.
// Based on RhostMUSH code.
//
static bool flag_rename(UTF8 *alias, UTF8 *newname)
{
    int nAlias;
    bool bValidAlias;
    UTF8 *pCheckedAlias = MakeCanonicalFlagName(alias, &nAlias, &bValidAlias);
    if (!bValidAlias)
    {
        return false;
    }
    UTF8 *pAlias = alloc_sbuf("flag_rename.old");
    memcpy(pAlias, pCheckedAlias, nAlias+1);

    int nNewName;
    bool bValidNewName;
    UTF8 *pCheckedNewName = MakeCanonicalFlagName(newname, &nNewName, &bValidNewName);
    if (!bValidNewName)
    {
        free_sbuf(pAlias);
        return false;
    }
    UTF8 *pNewName = alloc_sbuf("flag_rename.new");
    memcpy(pNewName, pCheckedNewName, nNewName+1);

    FLAGNAMEENT *flag1;
    flag1 = (FLAGNAMEENT *)hashfindLEN(pAlias, nAlias, &mudstate.flags_htab);
    if (flag1 != NULL)
    {
        FLAGNAMEENT *flag2;
        flag2 = (FLAGNAMEENT *)hashfindLEN(pNewName, nNewName, &mudstate.flags_htab);
        if (flag2 == NULL)
        {
            hashaddLEN(pNewName, nNewName, flag1, &mudstate.flags_htab);

            if (flag1->flagname != flag1->pOrigName)
            {
                MEMFREE(flag1->flagname);
            }
            flag1->flagname = StringCloneLen(pNewName, nNewName);

            free_sbuf(pAlias);
            free_sbuf(pNewName);
            return true;
        }
    }
    free_sbuf(pAlias);
    free_sbuf(pNewName);
    return false;
}
Example #19
0
void helpindex_clean(int iHelpfile)
{
    CHashTable *htab = mudstate.aHelpDesc[iHelpfile].ht;
    if (NULL == htab)
    {
        return;
    }

    struct help_entry *htab_entry;
    for (htab_entry = (struct help_entry *)hash_firstentry(htab);
         htab_entry;
         htab_entry = (struct help_entry *)hash_nextentry(htab))
    {
        if (htab_entry->key)
        {
            MEMFREE(htab_entry->key);
            htab_entry->key = NULL;
        }
        delete htab_entry;
        htab_entry = NULL;
    }
    delete mudstate.aHelpDesc[iHelpfile].ht;
    mudstate.aHelpDesc[iHelpfile].ht = NULL;
}
Example #20
0
void do_plusemail(dbref executor, dbref cause, dbref enactor, int eval, int key,
                 int nargs, UTF8 *arg1, UTF8 *arg2, const UTF8 *cargs[], int ncargs)
{
    UNUSED_PARAMETER(cause);
    UNUSED_PARAMETER(enactor);
    UNUSED_PARAMETER(eval);
    UNUSED_PARAMETER(key);
    UNUSED_PARAMETER(nargs);
    UNUSED_PARAMETER(cargs);
    UNUSED_PARAMETER(ncargs);

    UTF8 inputline[LBUF_SIZE];

    if ('\0' == mudconf.mail_server[0])
    {
        notify(executor, T("@email: Not configured"));
        return;
    }

    if (!arg1 || !*arg1)
    {
        notify(executor, T("@email: I don\xE2\x80\x99t know who you want to e-mail!"));
        return;
    }

    if (!arg2 || !*arg2)
    {
        notify(executor, T("@email: Not sending an empty e-mail!"));
        return;
    }

    UTF8 *addy = alloc_lbuf("mod_email_do_email.headers");
    UTF8 *bp = addy;
    safe_str(arg1, addy, &bp);
    *bp = '\0';

    UTF8 *subject = (UTF8 *)strchr((char *)addy, '/');
    if (subject)
    {
        *subject = '\0';
        subject++;
    }
    else
    {
        subject = mudconf.mail_subject;
    }

    UTF8 *pMailServer = ConvertCRLFtoSpace(mudconf.mail_server);
    SOCKET mailsock = INVALID_SOCKET;
    int result = mod_email_sock_open(pMailServer, 25, &mailsock);

    if (-1 == result)
    {
        notify(executor, tprintf(T("@email: Unable to resolve hostname %s!"),
            pMailServer));
        free_lbuf(addy);
        return;
    }
    else if (-2 == result)
    {
        // Periodically, we get a failed connect, for reasons which elude me.
        // In almost every case, an immediate retry works.  Therefore, we give
        // it one more shot, before we give up.
        //
        result = mod_email_sock_open(pMailServer, 25, &mailsock);
        if (0 != result)
        {
            notify(executor, T("@email: Unable to connect to mailserver, aborting!"));
            free_lbuf(addy);
            return;
        }
    }

    UTF8 *body = alloc_lbuf("mod_email_do_email.body");
    UTF8 *bodyptr = body;
    mux_exec(arg2, LBUF_SIZE-1, body, &bodyptr, executor, executor, executor,
        EV_TOP | EV_STRIP_CURLY | EV_FCHECK | EV_EVAL, NULL, 0);
    *bodyptr = '\0';

    do
    {
        result = mod_email_sock_readline(mailsock, inputline, LBUF_SIZE - 1);
    } while (  0 == result
            || (  3 < result
               && '-' == inputline[3]));

    if (-1 == result)
    {
        mod_email_sock_close(mailsock);
        notify(executor, T("@email: Connection to mailserver lost."));
        free_lbuf(body);
        free_lbuf(addy);
        return;
    }

    if ('2' != inputline[0])
    {
        mod_email_sock_close(mailsock);
        notify(executor, tprintf(T("@email: Invalid mailserver greeting (%s)"),
            inputline));
    }

    mod_email_sock_printf(mailsock, T("EHLO %s\r\n"), ConvertCRLFtoSpace(mudconf.mail_ehlo));

    do
    {
        result = mod_email_sock_readline(mailsock, inputline, LBUF_SIZE - 1);
    } while (  0 == result
            || (  3 < result
               && '-' == inputline[3]));

    if (-1 == result)
    {
        mod_email_sock_close(mailsock);
        notify(executor, T("@email: Connection to mailserver lost."));
        free_lbuf(body);
        free_lbuf(addy);
        return;
    }

    if ('2' != inputline[0])
    {
        notify(executor, tprintf(T("@email: Error response on EHLO (%s)"),
            inputline));
    }

    mod_email_sock_printf(mailsock, T("MAIL FROM:<%s>\r\n"), ConvertCRLFtoSpace(mudconf.mail_sendaddr));

    do
    {
        result = mod_email_sock_readline(mailsock, inputline, LBUF_SIZE - 1);
    } while (  0 == result
            || (  3 < result
               && '-' == inputline[3]));

    if (-1 == result)
    {
        mod_email_sock_close(mailsock);
        notify(executor, T("@email: Connection to mailserver lost."));
        free_lbuf(body);
        free_lbuf(addy);
        return;
    }

    if ('2' != inputline[0])
    {
        notify(executor, tprintf(T("@email: Error response on MAIL FROM (%s)"),
            inputline));
    }

    mod_email_sock_printf(mailsock, T("RCPT TO:<%s>\r\n"), ConvertCRLFtoSpace(addy));

    do
    {
        result = mod_email_sock_readline(mailsock, inputline, LBUF_SIZE - 1);
    } while (  0 == result
            || (  3 < result
               && '-' == inputline[3]));

    if (-1 == result)
    {
        mod_email_sock_close(mailsock);
        notify(executor, T("@email: Connection to mailserver lost."));
        free_lbuf(body);
        free_lbuf(addy);
        return;
    }

    if ('2' != inputline[0])
    {
        notify(executor, tprintf(T("@email: Error response on RCPT TO (%s)"),
            inputline));
        free_lbuf(body);
        free_lbuf(addy);
        return;
    }

    mod_email_sock_printf(mailsock, T("DATA\r\n"));

    do
    {
        result = mod_email_sock_readline(mailsock, inputline, LBUF_SIZE - 1);
    } while (  0 == result
            || (  3 < result
               && '-' == inputline[3]));

    if (-1 == result)
    {
        mod_email_sock_close(mailsock);
        notify(executor, T("@email: Connection to mailserver lost."));
        free_lbuf(body);
        free_lbuf(addy);
        return;
    }

    if ('3' != inputline[0])
    {
        notify(executor, tprintf(T("@email: Error response on DATA (%s)"),
            inputline));
        free_lbuf(body);
        free_lbuf(addy);
        return;
    }

    UTF8 *pSendName = StringClone(ConvertCRLFtoSpace(mudconf.mail_sendname));
    mod_email_sock_printf(mailsock, T("From: %s <%s>\r\n"),  pSendName, ConvertCRLFtoSpace(mudconf.mail_sendaddr));
    MEMFREE(pSendName);

    mod_email_sock_printf(mailsock, T("To: %s\r\n"), ConvertCRLFtoSpace(addy));
    mod_email_sock_printf(mailsock, T("X-Mailer: TinyMUX %s\r\n"), mudstate.short_ver);
    mod_email_sock_printf(mailsock, T("Subject: %s\r\n\r\n"), ConvertCRLFtoSpace(subject));

    // The body is encoded to include the CRLF.CRLF at the end.
    //
    mod_email_sock_printf(mailsock, T("%s"), EncodeBody(body));

    do
    {
        result = mod_email_sock_readline(mailsock, inputline, LBUF_SIZE - 1);

        // Remove trailing CR and LF characters.
        //
        while (  0 < result
              && (  '\n' == inputline[result-1]
                 || '\r' == inputline[result-1]))
        {
            result--;
            inputline[result] = '\0';
        }
    } while (  0 == result
            || (  3 < result
               && '-' == inputline[3]));

    if (-1 == result)
    {
        mod_email_sock_close(mailsock);
        notify(executor, T("@email: Connection to mailserver lost."));
        free_lbuf(body);
        free_lbuf(addy);
        return;
    }

    if ('2' != inputline[0])
    {
        notify(executor, tprintf(T("@email: Message rejected (%s)"), inputline));
    }
    else
    {
        notify(executor, tprintf(T("@email: Mail sent to %s (%s)"), ConvertCRLFtoSpace(addy), &inputline[4]));
    }

    mod_email_sock_printf(mailsock, T("QUIT\n"));
    mod_email_sock_close(mailsock);

    free_lbuf(body);
    free_lbuf(addy);
}
static QTNode *
findeq(QTNode * node, QTNode * ex, MemoryType memtype, QTNode * subs, bool *isfind)
{

	if ((node->sign & ex->sign) != ex->sign || node->valnode->type != ex->valnode->type || node->valnode->val != ex->valnode->val)
		return node;

	if (node->flags & QTN_NOCHANGE)
		return node;

	if (node->valnode->type == OPR)
	{
		if (node->nchild == ex->nchild)
		{
			if (QTNEq(node, ex))
			{
				QTNFree(node);
				if (subs)
				{
					node = QTNCopy(subs, memtype);
					node->flags |= QTN_NOCHANGE;
				}
				else
					node = NULL;
				*isfind = true;
			}
		}
		else if (node->nchild > ex->nchild)
		{
			int		   *counters = (int *) palloc(sizeof(int) * node->nchild);
			int			i;
			QTNode	   *tnode = (QTNode *) MEMALLOC(memtype, sizeof(QTNode));

			memset(tnode, 0, sizeof(QTNode));
			tnode->child = (QTNode **) MEMALLOC(memtype, sizeof(QTNode *) * ex->nchild);
			tnode->nchild = ex->nchild;
			tnode->valnode = (ITEM *) MEMALLOC(memtype, sizeof(ITEM));
			*(tnode->valnode) = *(ex->valnode);

			for (i = 0; i < ex->nchild; i++)
				counters[i] = i;

			do
			{
				tnode->sign = 0;
				for (i = 0; i < ex->nchild; i++)
				{
					tnode->child[i] = node->child[counters[i]];
					tnode->sign |= tnode->child[i]->sign;
				}

				if (QTNEq(tnode, ex))
				{
					int			j = 0;

					MEMFREE(memtype, tnode->valnode);
					MEMFREE(memtype, tnode->child);
					MEMFREE(memtype, tnode);
					if (subs)
					{
						tnode = QTNCopy(subs, memtype);
						tnode->flags = QTN_NOCHANGE | QTN_NEEDFREE;
					}
					else
						tnode = NULL;

					node->child[counters[0]] = tnode;

					for (i = 1; i < ex->nchild; i++)
						node->child[counters[i]] = NULL;
					for (i = 0; i < node->nchild; i++)
					{
						if (node->child[i])
						{
							node->child[j] = node->child[i];
							j++;
						}
					}

					node->nchild = j;

					*isfind = true;

					break;
				}
			} while (addone(counters, ex->nchild - 1, node->nchild));
			if (tnode && (tnode->flags & QTN_NOCHANGE) == 0)
			{
				MEMFREE(memtype, tnode->valnode);
				MEMFREE(memtype, tnode->child);
				MEMFREE(memtype, tnode);
			}
			else
				QTNSort(node);
			pfree(counters);
		}
	}
	else if (QTNEq(node, ex))
	{
		QTNFree(node);
		if (subs)
		{
			node = QTNCopy(subs, memtype);
			node->flags |= QTN_NOCHANGE;
		}
		else
		{
			node = NULL;
		}
		*isfind = true;
	}

	return node;
}
Example #22
0
void freeMatrix(sparseMatrix *matrix)
{
  resizeMatrix(matrix, 0);
  MEMFREE(matrix);
}
Example #23
0
PPDERROR
PARSEROBJ_ParseValue(
    PPARSEROBJ  pParserObj,
    PFILEOBJ    pFileObj,
    PSTR        pCh
    )

/*++

Routine Description:

    Parse the entry value.

Arguments:

    pParserObj - pointer to the parser object
    pFileObj - pointer to input file object
    pCh - placeholder for returning the entry value terminating character

Return Value:

    PPDERR_NONE - entry value was parsed successfully
    PPDERR_xxx - an error occured

--*/

{
    PPDERROR    err;
    BOOL        bQuoted;
    PBUFOBJ     pBufObj = & pParserObj->value;

    // Skip over any leading spaces

    do {
        err = FILEOBJ_GetChar(pFileObj, pCh);
        if (err != PPDERR_NONE)
            return err;
    } while (IsSpace(*pCh));

    // Check to see if the first character is a '"'.
    // If it's a '"', then parse a quoted value (which
    // can span multiple lines) until the matching quote
    // is found. If the first character is not a quote,
    // the parse a normal string value until a newline
    // is found.

    if (*pCh == QUOTE_CHAR) {
        bQuoted = TRUE;
        pParserObj->valueType = QUOTED_VALUE;
        err = FILEOBJ_GetChar(pFileObj, pCh);
    } else {
        bQuoted = FALSE;
        pParserObj->valueType = STRING_VALUE;
    }

    for ( ; ; ) {

        // Read characters from the file until one of the
        // following condition is true:
        //  an error occured
        //  found a '"' when parsing a quoted value
        //  found a newline or '/' when parsing a normal value

        if ((err != PPDERR_NONE) ||
            (bQuoted && *pCh == QUOTE_CHAR) ||
            (!bQuoted && (IsNewline(*pCh) || *pCh == XLATION_CHAR)))
        {
            break;
        }

        // Add the character to the buffer

        if (BUFOBJ_AddChar(pBufObj, *pCh) != PPDERR_NONE) {

            PSTR    pNewBuffer;

            // The value string is longer than what our
            // buffer can hold. Expand the buffer by
            // DefaultValueLen.

            pNewBuffer = (PSTR)
                MEMALLOC(pBufObj->maxlen + 1 + DefaultValueLen);

            if (pNewBuffer == NULL) {

                DBGERRMSG("MEMALLOC");
                return PPDERR_MEM;
            } else {

                memset(pNewBuffer, 0, pBufObj->maxlen + 1 + DefaultValueLen);
            }

            // Copy over the previous buffer contents

            memcpy(pNewBuffer, pBufObj->pBuffer, pBufObj->curlen);

            // Free the previous buffer

            MEMFREE(pBufObj->pBuffer);

            // Switch to the new buffer and update the buffer length.

            pBufObj->pBuffer = pNewBuffer;
            pBufObj->maxlen += DefaultValueLen;

            // Try adding the character to the buffer again.

            err = BUFOBJ_AddChar(pBufObj, *pCh);
            ASSERT(err == PPDERR_NONE);
        }

        // Read the next character from the file

        err = FILEOBJ_GetChar(pFileObj, pCh);
    }

    // Null-terminate the value string

    pBufObj->pBuffer[pBufObj->curlen] = '\0';

    // Skip the remaining characters on the line
    // (which should be a translation string).

    if (err == PPDERR_NONE && ! IsNewline(*pCh))
        err = PARSEROBJ_SkipLine(pParserObj, pFileObj);

    // Handle symbol value

    if (pParserObj->valueType == STRING_VALUE && *(pBufObj->pBuffer) == SYMBOL_CHAR)
        pParserObj->valueType = SYMBOL_VALUE;
    
    return err;
}
Example #24
0
PPARSEROBJ
PARSEROBJ_Create(
    VOID
    )

/*++

Routine Description:

    Create a parser object

Arguments:

    NONE

Return Value:

    Pointer to newly recreated parser object
    NULL if an error occured

--*/

{
    PPARSEROBJ  pParserObj;

    // Allocate memory space and initialize its content to zero

    pParserObj = (PPARSEROBJ) MEMALLOC(sizeof(PARSEROBJ));

    if (pParserObj == NULL) {

        DBGERRMSG("MEMALLOC");

    } else {

        PSTR    pBuffer;

        // Allocate memory to for holding the value.
        // Since the value can be very long, we start out
        // from a default sized buffer. When we run
        // out of room during parsing, we will grow
        // the buffer through GlobalReAlloc.

        pBuffer = (PSTR) MEMALLOC(DefaultValueLen+1);

        if (pBuffer == NULL) {

            DBGERRMSG("MEMALLOC");
            MEMFREE(pParserObj);
            pParserObj = NULL;
        } else {

            memset(pParserObj, 0, sizeof(PARSEROBJ));
            memset(pBuffer, 0, DefaultValueLen+1);

            // Initialize the buffer objects.

            BUFOBJ_Initialize(
                & pParserObj->keyword,
                pParserObj->mainKeyword,
                MaxKeywordLen);

            BUFOBJ_Initialize(
                & pParserObj->option,
                pParserObj->optionKeyword,
                MaxKeywordLen);

            BUFOBJ_Initialize(
                & pParserObj->xlation,
                pParserObj->translation,
                MaxXlationLen);

            BUFOBJ_Initialize(
                & pParserObj->value,
                pBuffer,
                DefaultValueLen);
        }
    }

    return pParserObj;
}
Example #25
0
//Handles new SMS messages added to the database
int handleNewMessage(WPARAM hContact, LPARAM hDbEvent)
{
	char szServiceFunction[MAX_PATH], *pszServiceFunctionName;
	TCHAR szToolTip[MAX_PATH];
	DBEVENTINFO dbei = { sizeof(dbei) };

	if ((dbei.cbBlob = db_event_getBlobSize(hDbEvent)) == -1)
		return 0;

	dbei.pBlob = (PBYTE)MEMALLOC(dbei.cbBlob);
	if (!dbei.pBlob)
		return 0;
	memcpy(szServiceFunction, PROTOCOL_NAMEA, PROTOCOL_NAME_SIZE);
	pszServiceFunctionName = szServiceFunction + PROTOCOL_NAME_LEN;

	if (db_event_get(hDbEvent, &dbei) == 0)
	if ((dbei.flags & DBEF_SENT) == 0)
	if (dbei.eventType == ICQEVENTTYPE_SMS) {
		if (dbei.cbBlob > MIN_SMS_DBEVENT_LEN) {
			SkinPlaySound("RecvSMSMsg");
			if (DB_SMS_GetByte(NULL, "AutoPopup", 0)) {
				if (RecvSMSWindowAdd(hContact, ICQEVENTTYPE_SMS, NULL, 0, (LPSTR)dbei.pBlob, dbei.cbBlob))
					db_event_markRead(hContact, hDbEvent);
			}
			else {
				memcpy(pszServiceFunctionName, SMS_READ, sizeof(SMS_READ));
				mir_sntprintf(szToolTip, TranslateT("SMS Message from %s"), pcli->pfnGetContactDisplayName(hContact, 0));

				CLISTEVENT cle = {};
				cle.flags = CLEF_TCHAR;
				cle.hContact = hContact;
				cle.hDbEvent = hDbEvent;
				cle.hIcon = Skin_LoadIcon(SKINICON_OTHER_SMS);
				cle.pszService = szServiceFunction;
				cle.ptszTooltip = szToolTip;
				pcli->pfnAddEvent(&cle);
			}
		}
	}
	else if (dbei.eventType == ICQEVENTTYPE_SMSCONFIRMATION) {
		SkinPlaySound("RecvSMSConfirmation");
		if (DB_SMS_GetByte(NULL, "AutoPopup", 0)) {
			if (RecvSMSWindowAdd(hContact, ICQEVENTTYPE_SMSCONFIRMATION, NULL, 0, (LPSTR)dbei.pBlob, dbei.cbBlob))
				db_event_delete(hContact, hDbEvent);
		}
		else {
			UINT iIcon;
			if (GetDataFromMessage((LPSTR)dbei.pBlob, dbei.cbBlob, NULL, NULL, 0, NULL, &iIcon)) {
				memcpy(pszServiceFunctionName, SMS_READ_ACK, sizeof(SMS_READ_ACK));
				mir_sntprintf(szToolTip, TranslateT("SMS Confirmation from %s"), pcli->pfnGetContactDisplayName(hContact, 0));

				CLISTEVENT cle = {};
				cle.flags = CLEF_TCHAR;
				cle.hContact = hContact;
				cle.hDbEvent = hDbEvent;
				cle.hIcon = (HICON)LoadImage(ssSMSSettings.hInstance, MAKEINTRESOURCE(iIcon), IMAGE_ICON, 0, 0, LR_SHARED);
				cle.pszService = szServiceFunction;
				cle.ptszTooltip = szToolTip;
				pcli->pfnAddEvent(&cle);
			}
		}
	}
	MEMFREE(dbei.pBlob);
	return 0;
}
Example #26
0
// This Task assumes that pEntry is already unlinked from any lists it may
// have been related to.
//
static void Task_RunQueueEntry(void *pEntry, int iUnused)
{
    UNUSED_PARAMETER(iUnused);

    BQUE *point = (BQUE *)pEntry;
    dbref executor = point->executor;

    if (  Good_obj(executor)
       && !Going(executor))
    {
        giveto(executor, mudconf.waitcost);
        mudstate.curr_enactor = point->enactor;
        mudstate.curr_executor = executor;
        a_Queue(Owner(executor), -1);
        point->executor = NOTHING;
        if (!Halted(executor))
        {
            // Load scratch args.
            //
            for (int i = 0; i < MAX_GLOBAL_REGS; i++)
            {
                if (mudstate.global_regs[i])
                {
                    RegRelease(mudstate.global_regs[i]);
                    mudstate.global_regs[i] = NULL;
                }
                mudstate.global_regs[i] = point->scr[i];
                point->scr[i] = NULL;
            }

            char *command = point->comm;

            mux_assert(!mudstate.inpipe);
            mux_assert(mudstate.pipe_nest_lev == 0);
            mux_assert(mudstate.poutobj == NOTHING);
            mux_assert(!mudstate.pout);

            break_called = false;
            while (  command
                  && !break_called)
            {
                mux_assert(!mudstate.poutnew);
                mux_assert(!mudstate.poutbufc);

                char *cp = parse_to(&command, ';', 0);

                if (  cp
                   && *cp)
                {
                    // Will command be piped?
                    //
                    if (  command
                       && *command == '|'
                       && mudstate.pipe_nest_lev < mudconf.ntfy_nest_lim)
                    {
                        command++;
                        mudstate.pipe_nest_lev++;
                        mudstate.inpipe = true;

                        mudstate.poutnew  = alloc_lbuf("process_command.pipe");
                        mudstate.poutbufc = mudstate.poutnew;
                        mudstate.poutobj  = executor;
                    }
                    else
                    {
                        mudstate.inpipe = false;
                        mudstate.poutobj = NOTHING;
                    }

                    CLinearTimeAbsolute ltaBegin;
                    ltaBegin.GetUTC();
                    MuxAlarm.Set(mudconf.max_cmdsecs);
                    CLinearTimeDelta ltdUsageBegin = GetProcessorUsage();

                    char *log_cmdbuf = process_command(executor, point->caller,
                        point->enactor, point->eval, false, cp, point->env,
                        point->nargs);

                    CLinearTimeAbsolute ltaEnd;
                    ltaEnd.GetUTC();
                    if (MuxAlarm.bAlarmed)
                    {
                        notify(executor, "GAME: Expensive activity abbreviated.");
                        s_Flags(point->enactor, FLAG_WORD1, Flags(point->enactor) | HALT);
                        s_Flags(point->executor, FLAG_WORD1, Flags(point->executor) | HALT);
                        halt_que(point->enactor, NOTHING);
                        halt_que(executor, NOTHING);
                    }
                    MuxAlarm.Clear();

                    CLinearTimeDelta ltdUsageEnd = GetProcessorUsage();
                    CLinearTimeDelta ltd = ltdUsageEnd - ltdUsageBegin;
                    db[executor].cpu_time_used += ltd;

                    ltd = ltaEnd - ltaBegin;
                    if (ltd > mudconf.rpt_cmdsecs)
                    {
                        STARTLOG(LOG_PROBLEMS, "CMD", "CPU");
                        log_name_and_loc(executor);
                        char *logbuf = alloc_lbuf("do_top.LOG.cpu");
                        mux_sprintf(logbuf, LBUF_SIZE, " queued command taking %s secs (enactor #%d): ",
                            ltd.ReturnSecondsString(4), point->enactor);
                        log_text(logbuf);
                        free_lbuf(logbuf);
                        log_text(log_cmdbuf);
                        ENDLOG;
                    }
                }

                // Transition %| value.
                //
                if (mudstate.pout)
                {
                    free_lbuf(mudstate.pout);
                    mudstate.pout = NULL;
                }
                if (mudstate.poutnew)
                {
                    *mudstate.poutbufc = '\0';
                    mudstate.pout = mudstate.poutnew;
                    mudstate.poutnew  = NULL;
                    mudstate.poutbufc = NULL;
                }
            }

            // Clean up %| value.
            //
            if (mudstate.pout)
            {
                free_lbuf(mudstate.pout);
                mudstate.pout = NULL;
            }
            mudstate.pipe_nest_lev = 0;
            mudstate.inpipe = false;
            mudstate.poutobj = NOTHING;
        }
    }

    for (int i = 0; i < MAX_GLOBAL_REGS; i++)
    {
        if (point->scr[i])
        {
            RegRelease(point->scr[i]);
            point->scr[i] = NULL;
        }

        if (mudstate.global_regs[i])
        {
            RegRelease(mudstate.global_regs[i]);
            mudstate.global_regs[i] = NULL;
        }
    }

    MEMFREE(point->text);
    point->text = NULL;
    free_qentry(point);
}
Example #27
0
  void        ODWLDMAN_Deallocate(NPObject* obj)
{
    TRACEINFO;
    MEMFREE(obj);
    return;
}
Example #28
0
static void helpindex_read(int iHelpfile)
{
    helpindex_clean(iHelpfile);

    mudstate.aHelpDesc[iHelpfile].ht = new CHashTable;
    CHashTable *htab = mudstate.aHelpDesc[iHelpfile].ht;

    UTF8 szTextFilename[SBUF_SIZE+8];
    mux_sprintf(szTextFilename, sizeof(szTextFilename), T("%s.txt"),
        mudstate.aHelpDesc[iHelpfile].pBaseFilename);

    FILE *fp;
    if (!mux_fopen(&fp, szTextFilename, T("rb")))
    {
        STARTLOG(LOG_PROBLEMS, "HLP", "RINDX");
        UTF8 *p = alloc_lbuf("helpindex_read.LOG");
        mux_sprintf(p, LBUF_SIZE, T("Can\xE2\x80\x99t open %s for reading."), szTextFilename);
        log_text(p);
        free_lbuf(p);
        ENDLOG;
        return;
    }
    DebugTotalFiles++;

    size_t pos   = 0;
    size_t nTopicOriginal = 0;
    UTF8   topic[TOPIC_NAME_LEN+1];

    HelpIndex_Start(fp);
    while (HelpIndex_Read(&pos, &nTopicOriginal, topic))
    {
        // Convert the entry to all lowercase letters and add all leftmost
        // substrings.
        //
        // Topic names which appear earlier in the help file have priority
        // over topics names which appear later in the help file.  That is,
        // we do not associate prefixes with this topic if they have already
        // been used on a previous topic.
        //
        size_t nCased;
        UTF8  *pCased = mux_strlwr(topic, nCased);

        bool bOriginal = true; // First is the longest.

        for (size_t nTopic = nCased; 0 < nTopic; nTopic--)
        {
            // Avoid adding any entries with a trailing space.
            //
            if (mux_isspace(pCased[nTopic-1]))
            {
                continue;
            }

            struct help_entry *htab_entry =
              (struct help_entry *)hashfindLEN(pCased, nTopic, htab);

            if (htab_entry)
            {
                if (!bOriginal)
                {
                    continue;
                }

                hashdeleteLEN(pCased, nTopic, htab);

                if (htab_entry->key)
                {
                    MEMFREE(htab_entry->key);
                    htab_entry->key = NULL;
                    Log.tinyprintf(T("helpindex_read: duplicate %s entries for %s" ENDLINE),
                        szTextFilename, pCased);
                }
                delete htab_entry;
                htab_entry = NULL;
            }

            try
            {
                htab_entry = new struct help_entry;
            }
            catch (...)
            {
                ; // Nothing.
            }

            if (htab_entry)
            {
                htab_entry->pos = pos;
                htab_entry->key = bOriginal ? StringCloneLen(pCased, nTopic) : NULL;
                bOriginal = false;

                hashaddLEN(pCased, nTopic, htab_entry, htab);
            }
        }
    }
    HelpIndex_End();

    if (fclose(fp) == 0)
    {
        DebugTotalFiles--;
    }
    hashreset(htab);
}
Example #29
0
// This function handles the ACK received from that hooked.
int handleAckSMS(WPARAM wParam, LPARAM lParam)
{
	if (!lParam)
		return 0;
	if (((ACKDATA*)lParam)->type != ICQACKTYPE_SMS)
		return 0;

	char szPhone[MAX_PHONE_LEN] = { 0 };
	TCHAR tszPhone[MAX_PHONE_LEN] = { 0 };
	LPSTR lpszXML = (LPSTR)((ACKDATA*)lParam)->lParam, lpszData, lpszPhone;
	size_t dwXMLSize = 0, dwDataSize, dwPhoneSize;
	ACKDATA *ack = ((ACKDATA*)lParam);

	if (lpszXML)
		dwXMLSize = mir_strlen(lpszXML);

	if (GetXMLFieldEx(lpszXML, dwXMLSize, &lpszData, &dwDataSize, "sms_message", "text", NULL)) {
		if (GetXMLFieldEx(lpszXML, dwXMLSize, &lpszPhone, &dwPhoneSize, "sms_message", "sender", NULL)) {
			LPSTR lpszMessageUTF;
			size_t dwBuffLen, dwMessageXMLEncodedSize, dwMessageXMLDecodedSize;
			DBEVENTINFO dbei = { sizeof(dbei) };

			dwBuffLen = (dwDataSize + MAX_PATH);
			dbei.pBlob = (LPBYTE)MEMALLOC((dwBuffLen + dwPhoneSize));
			LPWSTR lpwszMessageXMLEncoded = (LPWSTR)MEMALLOC((dwBuffLen*sizeof(WCHAR)));
			LPWSTR lpwszMessageXMLDecoded = (LPWSTR)MEMALLOC((dwBuffLen*sizeof(WCHAR)));
			if (dbei.pBlob && lpwszMessageXMLEncoded && lpwszMessageXMLDecoded) {
				dwMessageXMLEncodedSize = MultiByteToWideChar(CP_UTF8, 0, lpszData, (int)dwDataSize, lpwszMessageXMLEncoded, (int)dwBuffLen);
				DecodeXML(lpwszMessageXMLEncoded, dwMessageXMLEncodedSize, lpwszMessageXMLDecoded, dwBuffLen, &dwMessageXMLDecodedSize);
				lpszMessageUTF = (LPSTR)lpwszMessageXMLEncoded;
				WideCharToMultiByte(CP_UTF8, 0, lpwszMessageXMLDecoded, (int)dwMessageXMLDecodedSize, lpszMessageUTF, (int)dwBuffLen, NULL, NULL);

				dwPhoneSize = CopyNumberA(szPhone, lpszPhone, dwPhoneSize);
				dwPhoneSize = MultiByteToWideChar(CP_UTF8, 0, szPhone, (int)dwPhoneSize, tszPhone, MAX_PHONE_LEN);
				MCONTACT hContact = HContactFromPhone(tszPhone, dwPhoneSize);

				dbei.szModule = GetModuleName(hContact);
				dbei.timestamp = time(NULL);
				dbei.flags = DBEF_UTF;
				dbei.eventType = ICQEVENTTYPE_SMS;
				dbei.cbBlob = (mir_snprintf((LPSTR)dbei.pBlob, ((dwBuffLen + dwPhoneSize)), "SMS From: +%s\r\n%s", szPhone, lpszMessageUTF) + sizeof(DWORD));
				//dbei.pBlob=(LPBYTE)lpszBuff;
				(*((DWORD*)(dbei.pBlob + (dbei.cbBlob - sizeof(DWORD))))) = 0;
				MEVENT hResult = db_event_add(hContact, &dbei);
				if (hContact == NULL) {
					if (RecvSMSWindowAdd(NULL, ICQEVENTTYPE_SMS, tszPhone, dwPhoneSize, (LPSTR)dbei.pBlob, dbei.cbBlob)) {
						db_event_markRead(hContact, hResult);
						SkinPlaySound("RecvSMSMsg");
					}
				}
			}
			MEMFREE(lpwszMessageXMLDecoded);
			MEMFREE(lpwszMessageXMLEncoded);
			MEMFREE(dbei.pBlob);
		}
	}
	else
		if (GetXMLFieldEx(lpszXML, dwXMLSize, &lpszData, &dwDataSize, "sms_delivery_receipt", "delivered", NULL)) {
			if (GetXMLFieldEx(lpszXML, dwXMLSize, &lpszPhone, &dwPhoneSize, "sms_delivery_receipt", "destination", NULL)) {
				dwPhoneSize = CopyNumberA(szPhone, lpszPhone, dwPhoneSize);
				dwPhoneSize = MultiByteToWideChar(CP_UTF8, 0, szPhone, (int)dwPhoneSize, tszPhone, MAX_PHONE_LEN);
				MCONTACT hContact = HContactFromPhone(tszPhone, dwPhoneSize);

				DBEVENTINFO dbei = { 0 };
				dbei.cbSize = sizeof(dbei);
				dbei.szModule = GetModuleName(hContact);
				dbei.timestamp = time(NULL);
				dbei.flags = DBEF_UTF;
				dbei.eventType = ICQEVENTTYPE_SMSCONFIRMATION;
				if (CompareStringA(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, lpszData, (int)dwDataSize, "yes", 3) == CSTR_EQUAL) {
					dbei.cbBlob = (MAX_PHONE_LEN + MAX_PATH);
					dbei.pBlob = (PBYTE)MEMALLOC(dbei.cbBlob);
					if (dbei.pBlob) dbei.cbBlob = (mir_snprintf((LPSTR)dbei.pBlob, dbei.cbBlob, "SMS Confirmation From: +%s\r\nSMS was sent succesfully", szPhone) + 4);
				}
				else {
					if (GetXMLFieldEx(lpszXML, dwXMLSize, &lpszData, &dwDataSize, "sms_delivery_receipt", "error", "params", "param", NULL) == FALSE) {
						lpszData = "";
						dwDataSize = 0;
					}
					dbei.cbBlob = (int)(MAX_PHONE_LEN + MAX_PATH + dwDataSize);
					dbei.pBlob = (PBYTE)MEMALLOC(dbei.cbBlob);
					if (dbei.pBlob) {
						dbei.cbBlob = mir_snprintf((LPSTR)dbei.pBlob, dbei.cbBlob, "SMS Confirmation From: +%s\r\nSMS was not sent succesfully: ", szPhone);
						memcpy((dbei.pBlob + dbei.cbBlob), lpszData, dwDataSize);
						dbei.cbBlob += (int)(dwDataSize + sizeof(DWORD));
						(*((DWORD*)(dbei.pBlob + (dbei.cbBlob - sizeof(DWORD))))) = 0;
					}
				}

				if (dbei.pBlob) {
					if (hContact)
						db_event_add(hContact, &dbei);
					else
						RecvSMSWindowAdd(NULL, ICQEVENTTYPE_SMSCONFIRMATION, tszPhone, dwPhoneSize, (LPSTR)dbei.pBlob, dbei.cbBlob);

					MEMFREE(dbei.pBlob);
				}
			}
		}
		else
			if ((ack->result == ACKRESULT_FAILED) || GetXMLFieldEx(lpszXML, dwXMLSize, &lpszData, &dwDataSize, "sms_response", "deliverable", NULL)) {
				HWND hWndDlg = SendSMSWindowHwndByHProcessGet(ack->hProcess);
				if (hWndDlg) {
					char szNetwork[MAX_PATH];

					KillTimer(hWndDlg, wParam);
					GetXMLFieldExBuff(lpszXML, dwXMLSize, szNetwork, sizeof(szNetwork), NULL, "sms_response", "network", NULL);

					if (ack->result == ACKRESULT_FAILED || CompareStringA(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, lpszData, (int)dwDataSize, "no", 2) == CSTR_EQUAL) {
						char szBuff[1024];
						TCHAR tszErrorMessage[1028];
						LPSTR lpszErrorDescription;

						if (SendSMSWindowMultipleGet(hWndDlg)) {
							TVITEM tvi;
							tvi.mask = TVIF_TEXT;
							tvi.hItem = SendSMSWindowHItemSendGet(hWndDlg);
							tvi.pszText = tszPhone;
							tvi.cchTextMax = _countof(tszPhone);
							TreeView_GetItem(GetDlgItem(hWndDlg, IDC_NUMBERSLIST), &tvi);
						}
						else GetDlgItemText(hWndDlg, IDC_ADDRESS, tszPhone, _countof(szPhone));

						if (ack->result == ACKRESULT_FAILED)
							lpszErrorDescription = lpszXML;
						else {
							lpszErrorDescription = szBuff;
							GetXMLFieldExBuff(lpszXML, dwXMLSize, szBuff, sizeof(szBuff), NULL, "sms_response", "error", "params", "param", NULL);
						}

						mir_sntprintf(tszErrorMessage, TranslateT("SMS message didn't send by %S to %s because: %S"), szNetwork, tszPhone, lpszErrorDescription);
						ShowWindow(hWndDlg, SW_SHOWNORMAL);
						EnableWindow(hWndDlg, FALSE);
						HWND hwndTimeOut = CreateDialog(ssSMSSettings.hInstance, MAKEINTRESOURCE(IDD_SENDSMSTIMEDOUT), hWndDlg, SMSTimedOutDlgProc);
						SetDlgItemText(hwndTimeOut, IDC_STATUS, tszErrorMessage);
					}
					else {
						SendSMSWindowDBAdd(hWndDlg);
						if (SendSMSWindowMultipleGet(hWndDlg)) {
							if (SendSMSWindowNextHItemGet(hWndDlg, SendSMSWindowHItemSendGet(hWndDlg))) {
								SendSMSWindowAsSentSet(hWndDlg);
								SendSMSWindowHItemSendSet(hWndDlg, SendSMSWindowNextHItemGet(hWndDlg, SendSMSWindowHItemSendGet(hWndDlg)));
								SendSMSWindowNext(hWndDlg);
							}
							else SendSMSWindowRemove(hWndDlg);
						}
						else {
							if (CompareStringA(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, lpszData, (int)dwDataSize, "yes", 3) == CSTR_EQUAL ||
								CompareStringA(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, lpszData, (int)dwDataSize, "smtp", 4) == CSTR_EQUAL) {
								char szSource[MAX_PATH], szMessageID[MAX_PATH];

								if (DB_SMS_GetByte(NULL, "ShowACK", SMS_DEFAULT_SHOWACK)) {
									HWND hwndAccepted = CreateDialog(ssSMSSettings.hInstance, MAKEINTRESOURCE(IDD_SENDSMSACCEPT), hWndDlg, SMSAcceptedDlgProc);
									if (CompareStringA(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, lpszData, (int)dwDataSize, "yes", 3) == CSTR_EQUAL) {
										GetXMLFieldExBuff(lpszXML, dwXMLSize, szSource, sizeof(szSource), NULL, "sms_response", "source", NULL);
										GetXMLFieldExBuff(lpszXML, dwXMLSize, szMessageID, sizeof(szMessageID), NULL, "sms_response", "message_id", NULL);
									}
									else {
										SetDlgItemText(hwndAccepted, IDC_ST_SOURCE, TranslateT("From:"));
										SetDlgItemText(hwndAccepted, IDC_ST_MESSAGEID, TranslateT("To:"));
										GetXMLFieldExBuff(lpszXML, dwXMLSize, szSource, sizeof(szSource), NULL, "sms_response", "from", NULL);
										GetXMLFieldExBuff(lpszXML, dwXMLSize, szMessageID, sizeof(szMessageID), NULL, "sms_response", "to", NULL);
									}
									SetDlgItemTextA(hwndAccepted, IDC_NETWORK, szNetwork);
									SetDlgItemTextA(hwndAccepted, IDC_SOURCE, szSource);
									SetDlgItemTextA(hwndAccepted, IDC_MESSAGEID, szMessageID);
								}
								else SendSMSWindowRemove(hWndDlg);
							}
							else SendSMSWindowRemove(hWndDlg);
						}
					}
				}
			}
	return 0;
}
Example #30
0
void        CONFIGURATION_Deallocate(NPObject* obj)
{
    TRACEINFO;
     MEMFREE(obj);
    return;
}