void add_to_netq(unsigned long ip, unsigned short port, int rating, int replace)
{
if (rating > 100) rating=100;
if (rating < 0) rating=0;
if (ip == ((unsigned long) -1) || ip == 0L) {
return;
}
struct in_addr in;
in.s_addr=ip;
char *t=inet_ntoa(in);
if (!port) port=CONFIG_port_DEFAULT;
if (t && ip != ((unsigned long) -1) && ip) {
char host[256];
safe_strncpy(host,t,sizeof(host));
if (is_accessable_addr(ip) && allowIP(ip)) {
sprintf(host+strlen(host),":%d",port);
int x;
int nh=g_lvnetcons.GetCount();
int bestpos=-1;
int lastrat=-1;
for (x = 0; x < nh; x ++) {
char text[256];
text[0]=0;
g_lvnetcons.GetText(x,2,text,sizeof(text));
int rat=atoi(text);
if (rating > rat && bestpos < 0) bestpos=x;
text[0]=0;
g_lvnetcons.GetText(x,1,text,sizeof(text));
if (!stricmp(text,host)) {
if (g_lvnetcons.GetParam(x)) return;
char rat[32];
g_lvnetcons.GetText(x,2,rat,sizeof(rat));
int irat=atoi(rat);
if (irat < rating) {
if (irat < 50)
rating = irat+1;
else rating=irat;
};
if (!replace && rating < lastrat) {
sprintf(rat,"%d",rating);
g_lvnetcons.SetItemText(x,2,rat);
return;
};
g_lvnetcons.DeleteItem(x--);
nh--;
break;
};
lastrat=rat;
};
if (bestpos < 0) bestpos=nh;
char buf[32];
sprintf(buf,"%d",rating);
g_lvnetcons.InsertItem(bestpos,"",0);
g_lvnetcons.SetItemText(bestpos,1,host);
g_lvnetcons.SetItemText(bestpos,2,buf);
};
};
}
开发者ID:eiginn,项目名称:waste,代码行数:64,代码来源:netq.cpp
示例4: ExecuteMacro
int
ExecuteMacro(char *argv, int namelength)
{
RXSTRING rxRc;
RXSTRING rxArg[2];
int rxArgCount = 0;
char pszName[CCHMAXPATH];
char *rxArgStr;
short sRc;
long rc;
if (namelength >= sizeof(pszName))
return 1;
/* FIXME HBB 20010121: 3rd argument doesn't make sense. Either
* this should be sizeof(pszName), or it shouldn't use
* safe_strncpy(), here */
safe_strncpy(pszName, argv, namelength + 1);
rxArgStr = &argv[namelength];
RXSTRPTR(rxRc) = NULL;
#if 0
/*
C-like calling of function: program name is first
parameter.
In REXX you would have to use
Parse Arg param0, param1
to get the program name in param0 and the arguments in param1.
Some versions before gnuplot 3.7pl1 used a similar approach but
passed program name and arguments in a single string:
(==> Parse Arg param0 param1)
*/
MAKERXSTRING(rxArg[0], pszName, strlen(pszName));
rxArgCount++;
if (*rxArgStr) {
MAKERXSTRING(rxArg[1], rxArgStr, strlen(rxArgStr));
rxArgCount++;
}
#else
/*
REXX standard calling (gnuplot 3.7pl1 and above):
The program name is not supplied and so all actual arguments
are in a single string:
Parse Arg param
We even handle blanks like cmd.exe when calling REXX programs.
*/
if (*rxArgStr) {
MAKERXSTRING(rxArg[0], rxArgStr, strlen(rxArgStr));
rxArgCount++;
}
#endif
CallFromRexx = TRUE;
rc = RexxStart(
rxArgCount,
rxArg,
pszName,
NULL,
"GNUPLOT",
RXCOMMAND,
NULL,
&sRc,
&rxRc);
CallFromRexx = FALSE;
/* am: a word WRT errors codes:
the negative ones don't seem to have symbolic names, you can get
them from the OREXX reference, they're not in REXX Programming Guide -
no idea where to retrieve them from a Warp 3 reference ??
The positive ones are somehow referenced in REXXPG
*/
if (rc < 0) {
/* REXX error */
} else if (rc > 0) {
/* Interpreter couldn't be started */
if (rc == -4)
/* run was cancelled, but don't give error message */
rc = 0;
} else if (rc==0) {
/* all was fine */
}
/* We don't we try to use rxRc ?
BTW, don't use free() instead since it's allocated inside RexxStart()
and not in our executable using the EMX libraries */
if (RXSTRPTR(rxRc))
/* I guess it's NULL if something major went wrong,
NULL strings are usually not part of the REXX language ... */
DosFreeMem(rxRc.strptr);
return rc;
}
bool DOS_Shell::Execute(char * name,char * args) {
/* return true => don't check for hardware changes in do_command
* return false => check for hardware changes in do_command */
char fullname[DOS_PATHLENGTH+4]; //stores results from Which
char* p_fullname;
char line[CMD_MAXLINE];
if(strlen(args)!= 0){
if(*args != ' '){ //put a space in front
line[0]=' ';line[1]=0;
strncat(line,args,CMD_MAXLINE-2);
line[CMD_MAXLINE-1]=0;
}
else
{
safe_strncpy(line,args,CMD_MAXLINE);
}
}else{
line[0]=0;
};
/* check for a drive change */
if (((strcmp(name + 1, ":") == 0) || (strcmp(name + 1, ":\\") == 0)) && isalpha(*name))
{
if (!DOS_SetDrive(toupper(name[0])-'A')) {
WriteOut(MSG_Get("SHELL_EXECUTE_DRIVE_NOT_FOUND"),toupper(name[0]));
}
return true;
}
/* Check for a full name */
p_fullname = Which(name);
if (!p_fullname) return false;
strcpy(fullname,p_fullname);
const char* extension = strrchr(fullname,'.');
__android_log_print(ANDROID_LOG_INFO, "dosbox", "command fullname:%s", fullname);
/*always disallow files without extension from being executed. */
/*only internal commands can be run this way and they never get in this handler */
if(extension == 0)
{
//Check if the result will fit in the parameters. Else abort
if(strlen(fullname) >( DOS_PATHLENGTH - 1) ) return false;
char temp_name[DOS_PATHLENGTH+4],* temp_fullname;
//try to add .com, .exe and .bat extensions to filename
strcpy(temp_name,fullname);
strcat(temp_name,".COM");
temp_fullname=Which(temp_name);
if (temp_fullname) { extension=".com";strcpy(fullname,temp_fullname); }
else
{
strcpy(temp_name,fullname);
strcat(temp_name,".EXE");
temp_fullname=Which(temp_name);
if (temp_fullname) { extension=".exe";strcpy(fullname,temp_fullname);}
else
{
strcpy(temp_name,fullname);
strcat(temp_name,".BAT");
temp_fullname=Which(temp_name);
if (temp_fullname) { extension=".bat";strcpy(fullname,temp_fullname);}
else
{
return false;
}
}
}
}
if (strcasecmp(extension, ".bat") == 0)
{ /* Run the .bat file */
/* delete old batch file if call is not active*/
bool temp_echo=echo; /*keep the current echostate (as delete bf might change it )*/
if(bf && !call) delete bf;
bf=new BatchFile(this,fullname,name,line);
echo=temp_echo; //restore it.
}
else
{ /* only .bat .exe .com extensions maybe be executed by the shell */
if(strcasecmp(extension, ".com") !=0)
{
if(strcasecmp(extension, ".exe") !=0) return false;
}
/* Run the .exe or .com file from the shell */
/* Allocate some stack space for tables in physical memory */
reg_sp-=0x200;
//Add Parameter block
DOS_ParamBlock block(SegPhys(ss)+reg_sp);
block.Clear();
//Add a filename
RealPt file_name=RealMakeSeg(ss,reg_sp+0x20);
MEM_BlockWrite(Real2Phys(file_name),fullname,(Bitu)(strlen(fullname)+1));
/* HACK: Store full commandline for mount and imgmount */
full_arguments.assign(line);
/* Fill the command line */
//.........这里部分代码省略.........
/* Write out a tar header for the specified file/directory/whatever */
static int writeTarHeader(struct TarBallInfo *tbInfo,
const char *header_name, const char *fileName, struct stat *statbuf)
{
struct tar_header_t header;
memset(&header, 0, sizeof(header));
strncpy(header.name, header_name, sizeof(header.name));
/* POSIX says to mask mode with 07777. */
PUT_OCTAL(header.mode, statbuf->st_mode & 07777);
PUT_OCTAL(header.uid, statbuf->st_uid);
PUT_OCTAL(header.gid, statbuf->st_gid);
memset(header.size, '0', sizeof(header.size)-1); /* Regular file size is handled later */
/* users report that files with negative st_mtime cause trouble, so: */
PUT_OCTAL(header.mtime, statbuf->st_mtime >= 0 ? statbuf->st_mtime : 0);
/* Enter the user and group names */
safe_strncpy(header.uname, get_cached_username(statbuf->st_uid), sizeof(header.uname));
safe_strncpy(header.gname, get_cached_groupname(statbuf->st_gid), sizeof(header.gname));
if (tbInfo->hlInfo) {
/* This is a hard link */
header.typeflag = LNKTYPE;
strncpy(header.linkname, tbInfo->hlInfo->name,
sizeof(header.linkname));
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
/* Write out long linkname if needed */
if (header.linkname[sizeof(header.linkname)-1])
writeLongname(tbInfo->tarFd, GNULONGLINK,
tbInfo->hlInfo->name, 0);
#endif
} else if (S_ISLNK(statbuf->st_mode)) {
char *lpath = xmalloc_readlink_or_warn(fileName);
if (!lpath)
return FALSE;
header.typeflag = SYMTYPE;
strncpy(header.linkname, lpath, sizeof(header.linkname));
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
/* Write out long linkname if needed */
if (header.linkname[sizeof(header.linkname)-1])
writeLongname(tbInfo->tarFd, GNULONGLINK, lpath, 0);
#else
/* If it is larger than 100 bytes, bail out */
if (header.linkname[sizeof(header.linkname)-1]) {
free(lpath);
bb_error_msg("names longer than "NAME_SIZE_STR" chars not supported");
return FALSE;
}
#endif
free(lpath);
} else if (S_ISDIR(statbuf->st_mode)) {
header.typeflag = DIRTYPE;
/* Append '/' only if there is a space for it */
if (!header.name[sizeof(header.name)-1])
header.name[strlen(header.name)] = '/';
} else if (S_ISCHR(statbuf->st_mode)) {
header.typeflag = CHRTYPE;
PUT_OCTAL(header.devmajor, major(statbuf->st_rdev));
PUT_OCTAL(header.devminor, minor(statbuf->st_rdev));
} else if (S_ISBLK(statbuf->st_mode)) {
header.typeflag = BLKTYPE;
PUT_OCTAL(header.devmajor, major(statbuf->st_rdev));
PUT_OCTAL(header.devminor, minor(statbuf->st_rdev));
} else if (S_ISFIFO(statbuf->st_mode)) {
header.typeflag = FIFOTYPE;
} else if (S_ISREG(statbuf->st_mode)) {
/* header.size field is 12 bytes long */
/* Does octal-encoded size fit? */
uoff_t filesize = statbuf->st_size;
if (sizeof(filesize) <= 4
|| filesize <= (uoff_t)0777777777777LL
) {
PUT_OCTAL(header.size, filesize);
}
/* Does base256-encoded size fit?
* It always does unless off_t is wider than 64 bits.
*/
else if (ENABLE_FEATURE_TAR_GNU_EXTENSIONS
#if ULLONG_MAX > 0xffffffffffffffffLL /* 2^64-1 */
&& (filesize <= 0x3fffffffffffffffffffffffLL)
#endif
) {
/* GNU tar uses "base-256 encoding" for very large numbers.
* Encoding is binary, with highest bit always set as a marker
* and sign in next-highest bit:
* 80 00 .. 00 - zero
* bf ff .. ff - largest positive number
* ff ff .. ff - minus 1
* c0 00 .. 00 - smallest negative number
*/
char *p8 = header.size + sizeof(header.size);
do {
*--p8 = (uint8_t)filesize;
filesize >>= 8;
} while (p8 != header.size);
*p8 |= 0x80;
} else {
static int writeTarHeader(struct TarBallInfo *tbInfo,
const char *header_name, const char *fileName, struct stat *statbuf)
{
struct TarHeader header;
if (sizeof(header) != 512)
BUG_tar_header_size();
memset(&header, 0, sizeof(struct TarHeader));
strncpy(header.name, header_name, sizeof(header.name));
/* POSIX says to mask mode with 07777. */
PUT_OCTAL(header.mode, statbuf->st_mode & 07777);
PUT_OCTAL(header.uid, statbuf->st_uid);
PUT_OCTAL(header.gid, statbuf->st_gid);
memset(header.size, '0', sizeof(header.size)-1); /* Regular file size is handled later */
PUT_OCTAL(header.mtime, statbuf->st_mtime);
/* Enter the user and group names */
safe_strncpy(header.uname, get_cached_username(statbuf->st_uid), sizeof(header.uname));
safe_strncpy(header.gname, get_cached_groupname(statbuf->st_gid), sizeof(header.gname));
if (tbInfo->hlInfo) {
/* This is a hard link */
header.typeflag = LNKTYPE;
strncpy(header.linkname, tbInfo->hlInfo->name,
sizeof(header.linkname));
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
/* Write out long linkname if needed */
if (header.linkname[sizeof(header.linkname)-1])
writeLongname(tbInfo->tarFd, GNULONGLINK,
tbInfo->hlInfo->name, 0);
#endif
} else if (S_ISLNK(statbuf->st_mode)) {
char *lpath = xmalloc_readlink_or_warn(fileName);
if (!lpath)
return FALSE;
header.typeflag = SYMTYPE;
strncpy(header.linkname, lpath, sizeof(header.linkname));
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
/* Write out long linkname if needed */
if (header.linkname[sizeof(header.linkname)-1])
writeLongname(tbInfo->tarFd, GNULONGLINK, lpath, 0);
#else
/* If it is larger than 100 bytes, bail out */
if (header.linkname[sizeof(header.linkname)-1]) {
free(lpath);
bb_error_msg("names longer than "NAME_SIZE_STR" chars not supported");
return FALSE;
}
#endif
free(lpath);
} else if (S_ISDIR(statbuf->st_mode)) {
header.typeflag = DIRTYPE;
/* Append '/' only if there is a space for it */
if (!header.name[sizeof(header.name)-1])
header.name[strlen(header.name)] = '/';
} else if (S_ISCHR(statbuf->st_mode)) {
header.typeflag = CHRTYPE;
PUT_OCTAL(header.devmajor, major(statbuf->st_rdev));
PUT_OCTAL(header.devminor, minor(statbuf->st_rdev));
} else if (S_ISBLK(statbuf->st_mode)) {
header.typeflag = BLKTYPE;
PUT_OCTAL(header.devmajor, major(statbuf->st_rdev));
PUT_OCTAL(header.devminor, minor(statbuf->st_rdev));
} else if (S_ISFIFO(statbuf->st_mode)) {
header.typeflag = FIFOTYPE;
} else if (S_ISREG(statbuf->st_mode)) {
if (sizeof(statbuf->st_size) > 4
&& statbuf->st_size > (off_t)0777777777777LL
) {
bb_error_msg_and_die("cannot store file '%s' "
"of size %"OFF_FMT"d, aborting",
fileName, statbuf->st_size);
}
header.typeflag = REGTYPE;
PUT_OCTAL(header.size, statbuf->st_size);
} else {
bb_error_msg("%s: unknown file type", fileName);
return FALSE;
}
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
/* Write out long name if needed */
/* (we, like GNU tar, output long linkname *before* long name) */
if (header.name[sizeof(header.name)-1])
writeLongname(tbInfo->tarFd, GNULONGNAME,
header_name, S_ISDIR(statbuf->st_mode));
#endif
/* Now write the header out to disk */
chksum_and_xwrite(tbInfo->tarFd, &header);
/* Now do the verbose thing (or not) */
if (tbInfo->verboseFlag) {
FILE *vbFd = stdout;
if (tbInfo->tarFd == STDOUT_FILENO) /* If the archive goes to stdout, verbose to stderr */
vbFd = stderr;
//.........这里部分代码省略.........
请发表评论