mirror of
https://github.com/AppleWin/AppleWin.git
synced 2025-01-03 11:30:22 +00:00
tfesupp: remove all manual string manipulations - just use std::string. (PR #1065)
This commit is contained in:
parent
00668c2668
commit
a4341aa808
@ -29,7 +29,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|||||||
#include "../Registry.h"
|
#include "../Registry.h"
|
||||||
#include "../resource/resource.h"
|
#include "../resource/resource.h"
|
||||||
#include "../Tfe/PCapBackend.h"
|
#include "../Tfe/PCapBackend.h"
|
||||||
#include "../Tfe/tfesupp.h"
|
|
||||||
|
|
||||||
CPageConfigTfe* CPageConfigTfe::ms_this = 0; // reinit'd in ctor
|
CPageConfigTfe* CPageConfigTfe::ms_this = 0; // reinit'd in ctor
|
||||||
|
|
||||||
@ -109,26 +108,23 @@ void CPageConfigTfe::DlgCANCEL(HWND window)
|
|||||||
EndDialog(window, 0);
|
EndDialog(window, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL CPageConfigTfe::get_tfename(int number, char **ppname, char **ppdescription)
|
BOOL CPageConfigTfe::get_tfename(int number, std::string & name, std::string & description)
|
||||||
{
|
{
|
||||||
if (PCapBackend::tfe_enumadapter_open())
|
if (PCapBackend::tfe_enumadapter_open())
|
||||||
{
|
{
|
||||||
char *pname = NULL;
|
std::string adapterName;
|
||||||
char *pdescription = NULL;
|
std::string adapterDescription;
|
||||||
|
|
||||||
while (number--)
|
while (number--)
|
||||||
{
|
{
|
||||||
if (!PCapBackend::tfe_enumadapter(&pname, &pdescription))
|
if (!PCapBackend::tfe_enumadapter(adapterName, adapterDescription))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
lib_free(pname);
|
|
||||||
lib_free(pdescription);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PCapBackend::tfe_enumadapter(&pname, &pdescription))
|
if (PCapBackend::tfe_enumadapter(adapterName, adapterDescription))
|
||||||
{
|
{
|
||||||
*ppname = pname;
|
name = adapterName;
|
||||||
*ppdescription = pdescription;
|
description = adapterDescription;
|
||||||
PCapBackend::tfe_enumadapter_close();
|
PCapBackend::tfe_enumadapter_close();
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -166,17 +162,15 @@ int CPageConfigTfe::gray_ungray_items(HWND hwnd)
|
|||||||
|
|
||||||
if (enable)
|
if (enable)
|
||||||
{
|
{
|
||||||
char *pname = NULL;
|
std::string name;
|
||||||
char *pdescription = NULL;
|
std::string description;
|
||||||
|
|
||||||
number = SendMessage(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE), CB_GETCURSEL, 0, 0);
|
number = SendMessage(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE), CB_GETCURSEL, 0, 0);
|
||||||
|
|
||||||
if (get_tfename(number, &pname, &pdescription))
|
if (get_tfename(number, name, description))
|
||||||
{
|
{
|
||||||
SetWindowText(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE_NAME), pname);
|
SetWindowText(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE_NAME), name.c_str());
|
||||||
SetWindowText(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE_DESC), pdescription);
|
SetWindowText(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE_DESC), description.c_str());
|
||||||
lib_free(pname);
|
|
||||||
lib_free(pdescription);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -222,25 +216,23 @@ void CPageConfigTfe::init_tfe_dialog(HWND hwnd)
|
|||||||
{
|
{
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
|
|
||||||
char *pname;
|
std::string name;
|
||||||
char *pdescription;
|
std::string description;
|
||||||
|
|
||||||
temp_hwnd=GetDlgItem(hwnd,IDC_TFE_SETTINGS_INTERFACE);
|
temp_hwnd=GetDlgItem(hwnd,IDC_TFE_SETTINGS_INTERFACE);
|
||||||
|
|
||||||
for (cnt = 0; PCapBackend::tfe_enumadapter(&pname, &pdescription); cnt++)
|
for (cnt = 0; PCapBackend::tfe_enumadapter(name, description); cnt++)
|
||||||
{
|
{
|
||||||
BOOL this_entry = FALSE;
|
BOOL this_entry = FALSE;
|
||||||
|
|
||||||
if (strcmp(pname, m_tfe_interface_name.c_str()) == 0)
|
if (name == m_tfe_interface_name)
|
||||||
{
|
{
|
||||||
this_entry = TRUE;
|
this_entry = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetWindowText(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE_NAME), pname);
|
SetWindowText(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE_NAME), name.c_str());
|
||||||
SetWindowText(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE_DESC), pdescription);
|
SetWindowText(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE_DESC), description.c_str());
|
||||||
SendMessage(temp_hwnd, CB_ADDSTRING, 0, (LPARAM)pname);
|
SendMessage(temp_hwnd, CB_ADDSTRING, 0, (LPARAM)name.c_str());
|
||||||
lib_free(pname);
|
|
||||||
lib_free(pdescription);
|
|
||||||
|
|
||||||
if (this_entry)
|
if (this_entry)
|
||||||
{
|
{
|
||||||
|
@ -28,7 +28,7 @@ protected:
|
|||||||
virtual void DlgCANCEL(HWND window);
|
virtual void DlgCANCEL(HWND window);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BOOL get_tfename(int number, char **ppname, char **ppdescription);
|
BOOL get_tfename(int number, std::string & name, std::string & description);
|
||||||
int gray_ungray_items(HWND hwnd);
|
int gray_ungray_items(HWND hwnd);
|
||||||
void init_tfe_dialog(HWND hwnd);
|
void init_tfe_dialog(HWND hwnd);
|
||||||
void save_tfe_dialog(HWND hwnd);
|
void save_tfe_dialog(HWND hwnd);
|
||||||
|
@ -76,9 +76,9 @@ int PCapBackend::tfe_enumadapter_open(void)
|
|||||||
return tfe_arch_enumadapter_open();
|
return tfe_arch_enumadapter_open();
|
||||||
}
|
}
|
||||||
|
|
||||||
int PCapBackend::tfe_enumadapter(char **ppname, char **ppdescription)
|
int PCapBackend::tfe_enumadapter(std::string & name, std::string & description)
|
||||||
{
|
{
|
||||||
return tfe_arch_enumadapter(ppname, ppdescription);
|
return tfe_arch_enumadapter(name, description);
|
||||||
}
|
}
|
||||||
|
|
||||||
int PCapBackend::tfe_enumadapter_close(void)
|
int PCapBackend::tfe_enumadapter_close(void)
|
||||||
|
@ -54,7 +54,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static int tfe_enumadapter_open(void);
|
static int tfe_enumadapter_open(void);
|
||||||
static int tfe_enumadapter(char **ppname, char **ppdescription);
|
static int tfe_enumadapter(std::string & name, std::string & description);
|
||||||
static int tfe_enumadapter_close(void);
|
static int tfe_enumadapter_close(void);
|
||||||
|
|
||||||
static std::string tfe_interface;
|
static std::string tfe_interface;
|
||||||
|
@ -41,7 +41,6 @@
|
|||||||
|
|
||||||
#include <StdAfx.h> // this is necessary in linux, but in MSVC windows.h MUST come after winsock2.h (from pcap.h above)
|
#include <StdAfx.h> // this is necessary in linux, but in MSVC windows.h MUST come after winsock2.h (from pcap.h above)
|
||||||
#include "tfearch.h"
|
#include "tfearch.h"
|
||||||
#include "tfesupp.h"
|
|
||||||
#include "../Log.h"
|
#include "../Log.h"
|
||||||
|
|
||||||
|
|
||||||
@ -258,16 +257,16 @@ int tfe_arch_enumadapter_open(void)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tfe_arch_enumadapter(char **ppname, char **ppdescription)
|
int tfe_arch_enumadapter(std::string & name, std::string & description)
|
||||||
{
|
{
|
||||||
if (!TfePcapNextDev)
|
if (!TfePcapNextDev)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
*ppname = lib_stralloc(TfePcapNextDev->name);
|
name = TfePcapNextDev->name;
|
||||||
if (TfePcapNextDev->description)
|
if (TfePcapNextDev->description)
|
||||||
*ppdescription = lib_stralloc(TfePcapNextDev->description);
|
description = TfePcapNextDev->description;
|
||||||
else
|
else
|
||||||
*ppdescription = lib_stralloc(TfePcapNextDev->name);
|
description = TfePcapNextDev->name;
|
||||||
|
|
||||||
TfePcapNextDev = TfePcapNextDev->next;
|
TfePcapNextDev = TfePcapNextDev->next;
|
||||||
|
|
||||||
@ -293,20 +292,18 @@ pcap_t * TfePcapOpenAdapter(const std::string & interface_name)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* look if we can find the specified adapter */
|
/* look if we can find the specified adapter */
|
||||||
char *pname;
|
std::string name;
|
||||||
char *pdescription;
|
std::string description;
|
||||||
BOOL found = FALSE;
|
BOOL found = FALSE;
|
||||||
|
|
||||||
if (!interface_name.empty()) {
|
if (!interface_name.empty()) {
|
||||||
/* we have an interface name, try it */
|
/* we have an interface name, try it */
|
||||||
TfePcapDevice = TfePcapAlldevs;
|
TfePcapDevice = TfePcapAlldevs;
|
||||||
|
|
||||||
while (tfe_arch_enumadapter(&pname, &pdescription)) {
|
while (tfe_arch_enumadapter(name, description)) {
|
||||||
if (strcmp(pname, interface_name.c_str())==0) {
|
if (name == interface_name) {
|
||||||
found = TRUE;
|
found = TRUE;
|
||||||
}
|
}
|
||||||
lib_free(pname);
|
|
||||||
lib_free(pdescription);
|
|
||||||
if (found) break;
|
if (found) break;
|
||||||
TfePcapDevice = TfePcapNextDev;
|
TfePcapDevice = TfePcapNextDev;
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ int tfe_arch_receive(pcap_t * TfePcapFP,
|
|||||||
);
|
);
|
||||||
|
|
||||||
extern int tfe_arch_enumadapter_open(void);
|
extern int tfe_arch_enumadapter_open(void);
|
||||||
extern int tfe_arch_enumadapter(char **ppname, char **ppdescription);
|
extern int tfe_arch_enumadapter(std::string & name, std::string & description);
|
||||||
extern int tfe_arch_enumadapter_close(void);
|
extern int tfe_arch_enumadapter_close(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -33,122 +33,12 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include "tfesupp.h"
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
// Lib Stuff
|
|
||||||
/* #define LIB_DEBUG*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef LIB_DEBUG
|
|
||||||
#define LIB_DEBUG_SIZE 0x10000
|
|
||||||
#define LIB_DEBUG_GUARD 0x1000
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define CRC32_POLY 0xedb88320
|
#define CRC32_POLY 0xedb88320
|
||||||
static unsigned long crc32_table[256];
|
static unsigned long crc32_table[256];
|
||||||
static int crc32_is_initialized = 0;
|
static int crc32_is_initialized = 0;
|
||||||
|
|
||||||
void lib_free(void *ptr)
|
|
||||||
{
|
|
||||||
#ifdef LIB_DEBUG
|
|
||||||
lib_debug_free(ptr, 1, 1);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef LIB_DEBUG
|
|
||||||
lib_debug_libc_free(ptr);
|
|
||||||
#else
|
|
||||||
free(ptr);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void *lib_malloc(size_t size)
|
|
||||||
{
|
|
||||||
#ifdef LIB_DEBUG
|
|
||||||
void *ptr = lib_debug_libc_malloc(size);
|
|
||||||
#else
|
|
||||||
void *ptr = malloc(size);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef __OS2__
|
|
||||||
if (ptr == NULL && size > 0)
|
|
||||||
exit(-1);
|
|
||||||
#endif
|
|
||||||
#ifdef LIB_DEBUG
|
|
||||||
lib_debug_alloc(ptr, size, 3);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
/* Malloc enough space for `str', copy `str' into it and return its
|
|
||||||
address. */
|
|
||||||
char *lib_stralloc(const char *str)
|
|
||||||
{
|
|
||||||
size_t size;
|
|
||||||
char *ptr;
|
|
||||||
|
|
||||||
if (str == NULL)
|
|
||||||
exit(-1);
|
|
||||||
|
|
||||||
size = strlen(str) + 1;
|
|
||||||
ptr = (char *)lib_malloc(size);
|
|
||||||
|
|
||||||
memcpy(ptr, str, size);
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Like realloc, but abort if not enough memory is available. */
|
|
||||||
void *lib_realloc(void *ptr, size_t size)
|
|
||||||
{
|
|
||||||
#ifdef LIB_DEBUG
|
|
||||||
void *new_ptr = lib_debug_libc_realloc(ptr, size);
|
|
||||||
#else
|
|
||||||
void *new_ptr = realloc(ptr, size);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef __OS2__
|
|
||||||
if (new_ptr == NULL)
|
|
||||||
exit(-1);
|
|
||||||
#endif
|
|
||||||
#ifdef LIB_DEBUG
|
|
||||||
lib_debug_free(ptr, 1, 0);
|
|
||||||
lib_debug_alloc(new_ptr, size, 1);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return new_ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Util Stuff
|
|
||||||
|
|
||||||
/* Set a new value to the dynamically allocated string *str.
|
|
||||||
Returns `-1' if nothing has to be done. */
|
|
||||||
int util_string_set(char **str, const char *new_value)
|
|
||||||
{
|
|
||||||
if (*str == NULL) {
|
|
||||||
if (new_value != NULL)
|
|
||||||
*str = lib_stralloc(new_value);
|
|
||||||
} else {
|
|
||||||
if (new_value == NULL) {
|
|
||||||
lib_free(*str);
|
|
||||||
*str = NULL;
|
|
||||||
} else {
|
|
||||||
/* Skip copy if src and dest are already the same. */
|
|
||||||
if (strcmp(*str, new_value) == 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
*str = (char *)lib_realloc(*str, strlen(new_value) + 1);
|
|
||||||
strcpy(*str, new_value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// crc32 Stuff
|
// crc32 Stuff
|
||||||
|
|
||||||
unsigned long crc32_buf(const char *buffer, unsigned int len)
|
unsigned long crc32_buf(const char *buffer, unsigned int len)
|
||||||
@ -173,4 +63,3 @@ unsigned long crc32_buf(const char *buffer, unsigned int len)
|
|||||||
|
|
||||||
return ~crc;
|
return ~crc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,15 +39,6 @@
|
|||||||
#ifndef _TFESUPP_H
|
#ifndef _TFESUPP_H
|
||||||
#define _TFESUPP_H
|
#define _TFESUPP_H
|
||||||
|
|
||||||
extern FILE* g_fh; // Filehandle for log file
|
|
||||||
|
|
||||||
extern void *lib_malloc(size_t size);
|
|
||||||
extern void *lib_realloc(void *p, size_t size);
|
|
||||||
extern void lib_free(void *ptr);
|
|
||||||
extern char *lib_stralloc(const char *str);
|
|
||||||
|
|
||||||
extern int util_string_set(char **str, const char *new_value);
|
|
||||||
|
|
||||||
extern unsigned long crc32_buf(const char *buffer, unsigned int len);
|
extern unsigned long crc32_buf(const char *buffer, unsigned int len);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user