示例#1
0
char * convert_flags_to_str(unsigned long flags)
{
unsigned int i;
unsigned long p;
static char buffer[290];
	*buffer = 0;
	for (i = 0, p = 1; strflags[i]; i++, p <<= 1)
	{
		if (flags & p)
		{
			strmcat(buffer, strflags[i], 280);
			strmcat(buffer, ",", 280);
		}
	}
	for (i = 0, p = PROT_REOP; protflags[i]; i++, p <<= 1)
	{
		if (flags & p)
		{
			strmcat(buffer, protflags[i], 280);
			strmcat(buffer, ",", 280);
		}
	}
	if (*buffer)
		chop(buffer, 1);
	return buffer;
}
示例#2
0
/**
 * UpdateChannelConfig
 *
 * Updates the list of channels in the user's config file.
 */
void CIRCConnection::UpdateChannelConfig(void) {
	size_t Size;
	char *Out = NULL;

	int a = 0;

	while (hash_t<CChannel *> *Chan = m_Channels->Iterate(a++)) {
		bool WasNull = (Out == NULL);

		Size = (Out ? strlen(Out) : 0) + strlen(Chan->Name) + 2;
		Out = (char *)realloc(Out, Size);

		if (AllocFailed(Out)) {
			return;
		}

		if (!WasNull) {
			strmcat(Out, ",", Size);
		} else {
			Out[0] = '\0';
		}

		strmcat(Out, Chan->Name, Size);
	}

	/* m_Owner can be NULL if the last channel was not created successfully */
	if (GetOwner() != NULL) {
		GetOwner()->SetConfigChannels(Out);
	}

	free(Out);
}
示例#3
0
int translatedpart3(int uid)
{
    char *ept;
    struct translatet *th;
    struct socketnodes *lkm;
    pcontext;
    th=gettranslate(uid);
    pcontext;
    if(th==NULL)
	return 0x0;
    lkm=getpsocketbysock(th->sock);
    if(lkm==NULL)
    {
	erasetranslate(uid);
	return 0x0;
    }
    pcontext;
    ept=nobreak(ircbuf);
    ept=strstr(ept,lngtxt(870));
    if(ept!=NULL)
    {
	ept=strchr(ept,'>');
	if(ept!=NULL)
	{
	    ept++;
	    th->translatedtext=strmcat(th->translatedtext,ept);
	    th->translatedtext=strmcat(th->translatedtext," ");
	}
	lkm->sock->handler=translatedpart4;
    } else {
	if(strstr(ircbuf,"</strong>")!=NULL)
	    lkm->sock->handler=translatedpart4;
    }
    return 0x0;
}
示例#4
0
文件: pathutl.c 项目: NUOG/ejudge
int
pathmake3(char *dst, ...)
{
  va_list  args;
  char    *p;
  path_t   temp;

  temp[0] = 0;
  va_start(args, dst);
  while ((p = va_arg(args, char*))) {
    if (p[0] == '/' && p[1] == 0) {
      strmcat(temp, PATH_SEP, PATH_MAX);
    } else {
      strmcat(temp, p, PATH_MAX);
    }
  }
  va_end(args);
  
  dst[0] = 0;
  if (!os_IsAbsolutePath(temp)) {
    os_rGetWorkingDir(dst, PATH_MAX, 1);
    pathcat(dst, PATH_SEP);
  }
  pathcat(dst, temp);
  return strlen(dst);
}
示例#5
0
/*
 * bits_to_lastlog_level: converts the bitmap of lastlog levels into a nice
 * string format.  Note that this uses the global buffer, so watch out 
 */
char	* bits_to_lastlog_level(unsigned long level)
{
	static	char	buffer[481]; /* this *should* be enough for this */
	int	i;
unsigned long	p;

	if (level == LOG_ALL)
		strcpy(buffer, "ALL");
	else if (level == 0)
		strcpy(buffer, "NONE");
	else
	{
		*buffer = '\0';
		for (i = 0, p = 1; i < NUMBER_OF_LEVELS; i++, p <<= 1)
		{
			if (level & p)
			{
				if (*buffer)
					strmcat(buffer, space, 480);
				strmcat(buffer, levels[i],480);
			}
		}
	}
	return (buffer);
}
示例#6
0
/**
 * GetChannelModes
 *
 * Returns the channel's modes.
 */
RESULT<const char *> CChannel::GetChannelModes(void) {
	int i;
	size_t Size;
	char *NewTempModes;
	char ModeString[2];
	int ModeType;

	if (m_TempModes != NULL) {
		RETURN(const char *, m_TempModes);
	}

	Size = m_Modes.GetLength() + 1024;
	m_TempModes = (char *)malloc(Size);

	if (AllocFailed(m_TempModes)) {
		THROW(const char *, Generic_OutOfMemory, "malloc() failed.");
	}

	strmcpy(m_TempModes, "+", Size);

	for (i = 0; i < m_Modes.GetLength(); i++) {
		ModeType = GetOwner()->RequiresParameter(m_Modes[i].Mode);

		if (m_Modes[i].Mode != '\0' && ModeType != 3) {
			ModeString[0] = m_Modes[i].Mode;
			ModeString[1] = '\0';

			strmcat(m_TempModes, ModeString, Size);
		}
	}

	for (i = 0; i < m_Modes.GetLength(); i++) {
		ModeType = GetOwner()->RequiresParameter(m_Modes[i].Mode);

		if (m_Modes[i].Mode != '\0' && m_Modes[i].Parameter && ModeType != 3) {
			strmcat(m_TempModes, " ", Size);

			if (strlen(m_TempModes) + strlen(m_Modes[i].Parameter) > Size) {
				Size += strlen(m_Modes[i].Parameter) + 1024;
				NewTempModes = (char *)realloc(m_TempModes, Size);

				if (AllocFailed(NewTempModes)) {
					free(m_TempModes);
					m_TempModes = NULL;

					THROW(const char *, Generic_OutOfMemory, "urealloc() failed.");
				}

				m_TempModes = NewTempModes;
			}

			strmcat(m_TempModes, m_Modes[i].Parameter, Size);
		}
示例#7
0
/**
 * generate output
 */
void gen_output(char **weather, unsigned short int *flags, char **format_code) {
	char *buffer = NULL;
	unsigned short int counter;

	if(*flags&BIT3)
		symlinking_image(weather[11]);

	if(*flags&BIT2) 
		strmcat(&buffer,*format_code);
	else if(*flags&BIT1) { // short
		strmcat(format_code,"%lc\n%cm, %ctC°\nWind: %cws, %cwd°\n\nForecats:\n%tT\n\
		Temp: min %ttlC°, max %tthC°\n");
		
		strmcat(&buffer,*format_code);
	} else { // std long output
示例#8
0
文件: ui.c 项目: Nuos/crawler
bool ui_console_handle_event(SDL_Event* event)
{
	if (!console_enabled)
		return false;
	switch (event->type) {
	case SDL_KEYDOWN:
		if (event->key.keysym.sym == SDLK_BACKQUOTE || event->key.keysym.sym == SDLK_ESCAPE) {
			ui_console_toggle(false);
		} else if (event->key.keysym.sym == SDLK_RETURN) {
			ui_execute_console_command(console_cmdline);
			memset(console_cmdline, 0, MAX_CONSOLE_INPUT);
		} else if (event->key.keysym.sym == SDLK_BACKSPACE) {
			char* s = console_cmdline;
			size_t len = strlen(s);
			while (len > 0) {
				if ((s[len-1] & 0x80) == 0) {
					s[len-1] = 0;
					break;
				}
				if ((s[len-1] & 0xc0) == 0x80) {
					/* byte from a multibyte sequence */
					s[len-1] = 0;
					--len;
				}
				if ((s[len-1] & 0xc0) == 0xc0) {
					/* first byte of a multibyte sequence */
					s[len-1] = 0;
					break;
				}
			}
		}
		return true;
	case SDL_TEXTINPUT:
		//printf("%s (%c) (%d)\n", event->text.text, event->text.text[0], event->text.text[0]);
		if (console_first_char) {
			console_first_char = false;
			printf("Discarding %s\n", event->text.text);
			return true;
		}
		if (event->text.text[0] < 0) {
			strmcat(console_cmdline, "?", MAX_CONSOLE_INPUT);
		} else {
			strmcat(console_cmdline, event->text.text, MAX_CONSOLE_INPUT);
		}
		return true;
	}
	return false;
}
示例#9
0
文件: notice.c 项目: BitchX/BitchX1.1
char *ircop_flags_to_str(long flag)
{
int p, i;
char *buffer = new_malloc(BIG_BUFFER_SIZE+1);

	for (i = 0, p = 1; opflags[i]; i++, p <<= 1)
	{
		if (flag & p)
		{
			strmcat(buffer, opflags[i], BIG_BUFFER_SIZE);
			strmcat(buffer, ",", BIG_BUFFER_SIZE);
		}
	}
	if (*buffer)
		chop(buffer, 1);
	return buffer;
}
示例#10
0
文件: sysdep.c 项目: jimboman77/MJ
int log_error(const char *function, const char *file, const int line, const char *format,...) {
  char nformat[1024];
  va_list args;
  sprintf(nformat,"Error occurred in %s(), at %s:%d\n",function,file,line);
  strmcat(nformat,format,1023-(strlen(nformat)+strlen(format)));
  va_start(args,format);
  return vlog_msg(LogError,nformat,args);
}
示例#11
0
/**
 * symlinking new icon to actual.gif in .cache/weather/
 */
void symlinking_image(char *image) {
	char *filename_new = SHARED_FOLDER;
	char *filename_old = 0;

	getCachePath(&filename_old, APP_NAME);
	strmcat(&filename_old, "actual.gif");
	strmcat(&filename_new, "/%1.gif");
	strmreplace(&filename_new, "%1", image);

	unlink(filename_old);

	if(symlink(filename_new, filename_old) == -1)
		outerr("Error symlinking");

	freeChar(&filename_new);
	freeChar(&filename_old);
}
示例#12
0
文件: pathutl.c 项目: NUOG/ejudge
int
pathmake(char *dst, ...)
{
  va_list  args;
  char    *p;
  
  dst[0] = 0;
  va_start(args, dst);
  while ((p = va_arg(args, char*))) {
    if (p[0] == '/' && p[1] == 0) {
      strmcat(dst, PATH_SEP, PATH_MAX);
    } else {
      strmcat(dst, p, PATH_MAX);
    }
  }
  va_end(args);
  return strlen(dst);
}
示例#13
0
int translatedpart2(int uid)
{
    char *ept,*upt,*pt;
    struct translatet *th;
    struct socketnodes *lkm;
    pcontext;
    th=gettranslate(uid);
    pcontext;
    if(th==NULL)
	return 0x0;
    lkm=getpsocketbysock(th->sock);
    if(lkm==NULL)
    {
	erasetranslate(uid);
	return 0x0;
    }
    pcontext;
    ept=strstr(ircbuf,lngtxt(869));
    if(ept==NULL)
    {
	ept=ircbuf;
	upt=strchr(ept,':');
	if(upt!=NULL)
	{
	    upt++;*upt=' ';
	    upt++;*upt=0;
	    upt=strchr(th->translatedtext,'\r');
	    if (upt==NULL) upt=strchr(th->translatedtext,'\n');
	    if (upt!=NULL) *upt=0;
	    pt=strchr(ept,'&');
	    if(pt!=NULL)
	    {
		upt=strchr(pt+1,';');
		if(upt!=NULL)
		{
		    upt++;
		    while(*upt)
		    {
			*pt=*upt;
			pt++;
			upt++;
		    }
		    *pt=0;
		}
	    }
	    if(th->direction!=TR_TO)
		th->translatedtext=strmcat(th->translatedtext,ept);
	    lkm->sock->handler=translatedpart3;
	}
    } else {
	lkm->sock->handler=translatedpart3;
    }
    return 0x0;
}
示例#14
0
文件: xcopy.c 项目: FDOS/xcopy
/*-------------------------------------------------------------------------*/
void build_filename(char *dest_filename,
                    const char *src_filename,
                    const char *filepattern) {
  char drive[MAXDRIVE],
       dir[MAXDIR],
       filename_file[MAXFILE],
       filename_ext[MAXEXT],
       filepattern_file[MAXFILE],
       filepattern_ext[MAXEXT],
       tmp_filename[MAXFILE],
       tmp_ext[MAXEXT];

  _splitpath(src_filename, drive, dir, filename_file, filename_ext);
  _splitpath(filepattern, drive, dir, filepattern_file, filepattern_ext);
  build_name(tmp_filename, filename_file, filepattern_file);
  build_name(tmp_ext, filename_ext, filepattern_ext);
  strmcpy(dest_filename, drive, MAXPATH);
  strmcat(dest_filename, dir, MAXPATH);
  strmcat(dest_filename, tmp_filename, MAXPATH);
  strmcat(dest_filename, tmp_ext, MAXPATH);
}
示例#15
0
文件: pathutl.c 项目: NUOG/ejudge
int
pathmake2(char *dst, ...)
{
  va_list  args;
  char    *p;
  path_t   temp;

  if (os_IsAbsolutePath(dst)) return strlen(dst);
  
  temp[0] = 0;
  va_start(args, dst);
  while ((p = va_arg(args, char*))) {
    if (p[0] == '/' && p[1] == 0) {
      strmcat(temp, PATH_SEP, PATH_MAX);
    } else {
      strmcat(temp, p, PATH_MAX);
    }
  }
  va_end(args);
  pathcpy(dst, temp);
  return strlen(dst);
}
示例#16
0
文件: send.c 项目: jnbek/TekNap
static void	new_dcc_message_transmit (char *user, const char *text, const char *text_display, int type, int flag)
{
GetFile  *gf = NULL;
char		tmp[BIG_BUFFER_SIZE+1];
int 		len = 0;
char		buffer[NICKNAME_LEN+10];

	*tmp = 0;

	switch(type)
	{
		case NAP_CHAT_CONNECTED:
			break;
		default:
			return;
	}
	gf = find_in_getfile(0, user, NULL, NULL, 0, type);
	if (!gf)
	{
		if ((gf = find_in_getfile(0, user, NULL, NULL, 0, NAP_CHAT)))
			say("No active DCC CHAT connection for %s", user);
		else
			say("No DCC CHAT connection for %s", user);
		return;
	}

	strmcat(tmp, text, BIG_BUFFER_SIZE-3);
	len = strlen(tmp);

	my_encrypt(tmp, len, gf->passwd);
	tmp[len++] = '\n';
	tmp[len] = 0;

	write(gf->socket, tmp, len);
	gf->received += len;

	if (flag)
		put_it(FORMAT_SENDDCC, user, gf->ip, text_display?text_display:text);
	sprintf(buffer, "=%s", user);
	addtabkey(buffer, "msg", (char *)(text_display ? text_display : text));
}
示例#17
0
/**
 * JoinChannels
 *
 * Joins the channels which the user should be in (according to
 * the configuration file).
 */
void CIRCConnection::JoinChannels(void) {
	size_t Size;
	const char *Channels;

	if (m_DelayJoinTimer) {
		m_DelayJoinTimer->Destroy();
		m_DelayJoinTimer = NULL;
	}

	Channels = GetOwner()->GetConfigChannels();

	if (Channels != NULL && Channels[0] != '\0') {
		char *DupChannels, *newChanList, *Channel, *ChanList = NULL;
		CKeyring *Keyring;

		DupChannels = strdup(Channels);

		if (AllocFailed(DupChannels)) {
			return;
		}

		Channel = strtok(DupChannels, ",");

		Keyring = GetOwner()->GetKeyring();

		while (Channel != NULL && Channel[0] != '\0') {
			const char *Key = Keyring->GetKey(Channel);

			if (Key != NULL) {
				WriteLine("JOIN %s %s", Channel, Key);
			} else {
				if (ChanList == NULL || strlen(ChanList) > 400) {
					if (ChanList != NULL) {
						WriteLine("JOIN %s", ChanList);
						free(ChanList);
					}

					Size = strlen(Channel) + 1;
					ChanList = (char *)malloc(Size);

					if (AllocFailed(ChanList)) {
						free(DupChannels);

						return;
					}

					strmcpy(ChanList, Channel, Size);
				} else {
					Size = strlen(ChanList) + 1 + strlen(Channel) + 2;
					newChanList = (char *)realloc(ChanList, Size);

					if (AllocFailed(newChanList)) {
						continue;
					}

					ChanList = newChanList;

					strmcat(ChanList, ",", Size);
					strmcat(ChanList, Channel, Size);
				}
			}

			Channel = strtok(NULL, ",");
		}

		if (ChanList != NULL) {
			WriteLine("JOIN %s", ChanList);
			free(ChanList);
		}

		free(DupChannels);
	}
}
示例#18
0
文件: MOVE.C 项目: FDOS/move
static void move_files(const char *src_pathname, const char *src_filename,
                       const char *dest_pathname, const char *dest_filename,
                       int movedirs)
{
    char filepattern[MAXPATH],src_path_filename[MAXPATH],dest_path_filename[MAXPATH];
    char tmp_filename[MAXFILE+MAXEXT],tmp_pathname[MAXPATH];
    struct ffblk fileblock;
    int fileattrib, done;

    fileattrib=FA_RDONLY+FA_ARCH+FA_SYSTEM;

    if (movedirs || !ContainsWildCards(src_filename))
       fileattrib +=FA_DIREC;

    /* Find first source file. */
    strmcpy(filepattern, src_pathname, sizeof(filepattern));
    strmcat(filepattern, src_filename, sizeof(filepattern));
    done=findfirst(filepattern, &fileblock, fileattrib);
    while ((!done) && (fileblock.ff_name[0] == '.'))
	   done = findnext(&fileblock);

    if (done)
    {
       char buffer[80];
#ifdef USE_KITTEN
       sprintf(buffer, "%s%s %s", src_pathname, src_filename, kittengets(1,0,"does not exist!"));
#else
       sprintf(buffer, "%s%s does not exist!", src_pathname, src_filename);
#endif
       /* error */
       fprintf(stderr, " [%s]\n", buffer);
    }

    /* Check if destination directory has to be created. */
    if ((!done) && !dir_exists(dest_pathname))
    {
        strmcpy(tmp_pathname, dest_pathname, sizeof(tmp_pathname));
        if (makedir(tmp_pathname) != 0)
	{
#ifdef USE_KITTEN
	    error(1,10,"Unable to create directory");
	    kittenclose();
#else
	    error("Unable to create directory");
#endif
	    exit(4);
        } /* end if. */

    } /* end if. */

    /* Copy files. */
    while (!done)
    {
        /* Build source filename including path. */
        strmcpy(src_path_filename, src_pathname, sizeof(src_path_filename));
        strmcat(src_path_filename, fileblock.ff_name,
	        sizeof(src_path_filename));

        /* Build destination filename including path. */
        strmcpy(dest_path_filename, dest_pathname, sizeof(dest_path_filename));
        build_filename(tmp_filename, fileblock.ff_name, dest_filename);
        strmcat(dest_path_filename, tmp_filename, sizeof(dest_path_filename));
        prepare_move(src_path_filename, dest_path_filename);

	do {
	  done = findnext(&fileblock);
	} while ((!done) && (fileblock.ff_name[0] == '.'));
    } /* end while. */

} /* end move_files. */
示例#19
0
/**
 * UtilSaltedMd5
 *
 * Computes the MD5 hash of a given string and returns
 * a string representation of the hash.
 *
 * @param String the string which should be hashed
 * @param Salt the salt value
 * @param BrokenAlgo whether to use the broken algorithm
 */
const char *UtilMd5(const char *String, const char *Salt, bool BrokenAlgo) {
#ifdef HAVE_LIBSSL
	MD5_CTX context;
#else /* HAVE_LIBSSL */
	sMD5_CTX context;
#endif /* HAVE_LIBSSL */
	broken_sMD5_CTX broken_context;
	unsigned char digest[16];
	char *StringAndSalt, *StringPtr;
	static char *SaltAndResult = NULL;
	int rc;

	free(SaltAndResult);

	if (Salt != NULL) {
		rc = asprintf(&StringAndSalt, "%s%s", String, Salt);
	} else {
		rc = asprintf(&StringAndSalt, "%s", String);
	}

	if (RcFailed(rc)) {
		g_Bouncer->Fatal();
	}

	if (!BrokenAlgo) {
#ifdef HAVE_LIBSSL
		MD5_Init(&context);
		MD5_Update(&context, (unsigned char *)StringAndSalt, strlen(StringAndSalt));
		MD5_Final(digest, &context);
#else /* HAVE_LIBSSL */
		MD5Init(&context);
		MD5Update(&context, (unsigned char *)StringAndSalt, strlen(StringAndSalt));
		MD5Final(digest, &context);
#endif /* HAVE_LIBSSL */
	} else {
		broken_MD5Init(&broken_context);
		broken_MD5Update(&broken_context, (unsigned char *)StringAndSalt, strlen(StringAndSalt));
		broken_MD5Final(digest, &broken_context);
	}

	free(StringAndSalt);

	if (Salt != NULL) {
		SaltAndResult = (char *)malloc(strlen(Salt) + 50);

		if (AllocFailed(SaltAndResult)) {
			g_Bouncer->Fatal();
		}

		strmcpy(SaltAndResult, Salt, strlen(Salt) + 50);
		strmcat(SaltAndResult, "$", strlen(Salt) + 50);
		StringPtr = SaltAndResult + strlen(SaltAndResult);
	} else {
		StringPtr = SaltAndResult = (char *)malloc(50);

		if (AllocFailed(SaltAndResult)) {
			g_Bouncer->Fatal();
		}
	}

	for (int i = 0; i < 16; i++) {
		/* TODO: don't use sprintf */
		sprintf(StringPtr + i * 2, "%02x", digest[i]);
	}

	return SaltAndResult;
}
示例#20
0
bool CLHttpUser::bProcessGetRequest(char * pszRequest, bool bIsGetCommand) {
	//LogEvent("Request", pszRequest);

	int nUriLength = nUnescapedURI(pszRequest);
	if (nUriLength <= 0)
		return false;

	CLFileShareListAccess clCritSection;

	if (bShutdownInProgress)
		return false;

	static char szTempfile[MAX_PATH+1];
	szTempfile[0] = '\0';

	if (!bReadGetParameters(pszRequest)) {
		SendError(400, "Bad Request");
		return false;
	}

	DWORD dwRemoteIP = ntohl(stAddr.S_un.S_addr);
	for (CLFileShareNode * pclCur = pclFirstNode; pclCur ; pclCur = pclCur->pclNext) {
		if ((pclCur->st.dwAllowedIP ^ dwRemoteIP) & pclCur->st.dwAllowedMask)
			continue; // Not an allowed IP address

		if (!pclCur->bIsDirectory() && pclCur->nGetSrvPathLen() != nUriLength)
			continue; // not the right length, quickly move on to the next.

		if (pclCur->bIsDirectory() ?
		    (strncmp(pclCur->st.pszSrvPath, pszRequest, pclCur->nGetSrvPathLen() - 1) == 0) :
		    (strncmp(pclCur->st.pszSrvPath, pszRequest, pclCur->nGetSrvPathLen()) == 0)) {
			/*OutputDebugString( "Request for file OK : ");
			OutputDebugString( pclCur->st.pszSrvPath );
			OutputDebugString( "\n" );*/

			static char szSrvPath[MAX_PATH+1];
			static char szRealPath[MAX_PATH+1];
			char* pszSrvPath  = pclCur->st.pszSrvPath;
			char* pszRealPath = pclCur->st.pszRealPath;

			if (pclCur->bIsDirectory()) {
				strcpy(szRealPath, pclCur->st.pszRealPath);
				strcpy(szSrvPath, pclCur->st.pszSrvPath);
				pszRealPath = szRealPath;
				pszSrvPath = szSrvPath;

				if (nUriLength > MAX_PATH)
					nUriLength = MAX_PATH;

				pszRequest[nUriLength] = '\0';

				if (pclCur->nGetSrvPathLen() - nUriLength == 1) {
					SendRedir(302, "Found", "The document has moved", pszRequest);
					return false;
				} else {
					strmcat(pszRealPath, &pszRequest[pclCur->nGetSrvPathLen()], MAX_PATH);
					strmcat(pszSrvPath,  &pszRequest[pclCur->nGetSrvPathLen()], MAX_PATH);
				}
				pszRequest[nUriLength] = ' ';

				// hacker protection - should be removed by the browser
				if (strstr(pszRealPath, "..")) {
					SendError(404, "Not Found", "The requested URL was not found on this server.");
					return false;
				}

				char* pszTmp = pszRealPath;
				while (pszTmp = strchr(pszTmp, '/'))
					* pszTmp = '\\';

				hFile = CreateFile(pszRealPath, GENERIC_READ ,
				    FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

				if (hFile == INVALID_HANDLE_VALUE) {
					if (pszSrvPath[strlen(pszSrvPath)-1] != '/') {
						strmcat(pszRealPath, "\\", MAX_PATH);
						strmcat(pszSrvPath,  "/", MAX_PATH);
					}

					// a directory with index.htm
					strmcat(szRealPath, "index.htm", MAX_PATH);

					hFile = CreateFile(pszRealPath, GENERIC_READ ,
					    FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_HIDDEN, NULL);

					if (hFile == INVALID_HANDLE_VALUE) {
						// a directory with index.html
						strmcat(szRealPath, "l", MAX_PATH);

						hFile = CreateFile(pszRealPath, GENERIC_READ ,
						    FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_HIDDEN, NULL);

						if (hFile == INVALID_HANDLE_VALUE) {
							// generate directory index in temporary file
							if (*szTempfile == '\0') {
								GetTempPath(MAX_PATH, szTempfile);
								strmcat(szTempfile, "\\HttpServerTemp", MAX_PATH);
								strmcat(szTempfile, pszSrvPath, MAX_PATH);
								char* pszTmp = szTempfile;
								while (pszTmp = strchr(pszTmp, '/'))
									* pszTmp = '~';
							}
							pszRealPath[strlen(pszRealPath) - 10] = '\0';

							// detecting browser function removed
							// every browser should support it by now
							bool BrowserSupportsXML = true; 
							  //(apszParam[eUserAgent] != NULL) &&
							  //  (strstr(apszParam[eUserAgent], "Firefox") ||
							  //   (strstr(apszParam[eUserAgent], "MSIE") && !strstr(apszParam[eUserAgent], "Opera")));

							if ((indexCreationMode == INDEX_CREATION_XML ||
							     (indexCreationMode == INDEX_CREATION_DETECT && BrowserSupportsXML)) &&
							    bCreateIndexXML(pszRealPath, szTempfile, pszSrvPath, dwRemoteIP)) {
								hFile = CreateFile(szTempfile, GENERIC_READ ,
								    FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

								strcpy(szRealPath, "a.xml"); // restore .xml for mime type
							} else if ((indexCreationMode == INDEX_CREATION_HTML ||
							    indexCreationMode == INDEX_CREATION_DETECT) &&
							    bCreateIndexHTML(pszRealPath, szTempfile, pszSrvPath, dwRemoteIP)) {
								hFile = CreateFile(szTempfile, GENERIC_READ,
								    FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

								strcpy(szRealPath, "a.html"); // restore .html for mime type
							} else {
								continue;
							}
						} else {
							strmcat(pszSrvPath, "index.html", MAX_PATH);
							szTempfile[0] = '\0';
						}
					} else {
						strmcat(pszSrvPath, "index.htm", MAX_PATH);
						szTempfile[0] = '\0';
					}
				} else {
					szTempfile[0] = '\0';
				}
			} else {
				hFile = CreateFile(pszRealPath, GENERIC_READ ,
				    FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

				if (hFile == INVALID_HANDLE_VALUE) {
					SendError(404, "Not Found", "HTTP server failed to open local file");
					return false;
				}
			}

			strcpy(this->szCurrentDLSrvPath, pszSrvPath);

			DWORD nDataSize = GetFileSize(hFile, NULL);
			dwTotalSize = nDataSize;

			FILETIME stFileTime;
			GetFileTime(hFile, NULL, NULL, &stFileTime);

			char szCurTime[ 100 ];
			time_t ltime;
			time(&ltime);
			strftime(szCurTime, sizeof(szCurTime), "%a, %d %b %Y %H:%M:%S GMT", gmtime(&ltime));

			char szFileTime[ 100 ];
			FileTimeToUnixTime(&stFileTime, &ltime);
			strftime(szFileTime, sizeof(szFileTime), "%a, %d %b %Y %H:%M:%S GMT", gmtime(&ltime));
			
			if (apszParam[eIfModifiedSince] && strcmp(apszParam[eIfModifiedSince], szFileTime) == 0) {
				SendError(304, "Not Modified" );
				return true;
			}
	
			// we found match send file !!
			if (bIsGetCommand) {
				if (! pclCur->bAddUser(this)) {
					SendError(403, "Forbidden", "Access has been denied because there are too many connections");
					return false;
				}
			}

			if (*(ULONG*)(&stAddr) != 0x0100007F && // do not show popup of 127.0.0.1
			    strstr(pszRealPath, "\\@") == NULL) { // and of shares which start with an @
				ShowPopupWindow(inet_ntoa(stAddr), pszSrvPath);
			}

			clCritSection.Unlock();

			DWORD dwFileStart = 0;
			DWORD dwDataToSend = nDataSize;

			char szETag[ 50 ];
			{
				int nETagLen = mir_snprintf(szETag, SIZEOF(szETag), "\"%x-%x-%x\"",
				    nDataSize, stFileTime.dwHighDateTime, stFileTime.dwLowDateTime);

				if (!apszParam[eIfRange] || (strncmp(szETag, apszParam[eIfRange], nETagLen) == 0)) {
					char * pszRange = apszParam[eRange];
					if (pszRange) {
						if (strncmp(pszRange, "bytes=", 6) == 0) {
							pszRange += 6;
							// Do resume !!!
							char *pszEnd;
							if (pszRange[0] == '-') {
								// its a suffix-byte-range-spec
								DWORD dwLen = strtol(pszRange + 1, &pszEnd, 10);
								if (dwLen < nDataSize)
									dwFileStart = nDataSize - dwLen;
							} else {
								DWORD dwLen = strtol(pszRange, &pszEnd, 10);
								if (*pszEnd == '-' && dwLen < nDataSize) {
									dwFileStart = dwLen;
									pszRange = pszEnd + 1;
									if (*pszRange != 0) {
										dwLen = strtol(pszEnd + 1, &pszEnd, 10);
										if (dwLen > dwFileStart)
											dwDataToSend = (dwLen + 1) - dwFileStart;
										else
											dwFileStart = 0;
									}
								} else {
									SendError(400, "Bad Request");
									return false;
								}
							}
						}
					}
				}
			}

			if (dwFileStart >= nDataSize)
				dwFileStart = 0;

			if (dwFileStart + dwDataToSend >= nDataSize)
				dwDataToSend = nDataSize - dwFileStart;


			DWORD dwBytesToWrite = 0;
			// To optimize send speed it it ideal to always send larges size packages
			// But this size depended on network media but on Ethernet it is 1518 bytes.
			// Ethernet, IP and TCP headers use some of this space and leaves 1460 bytes
			// for data transfer.
			// We will use a multiply of this to always send optimal sized packages.
			char szBuf[1460 * 4];

			if (dwFileStart > 0 || dwDataToSend != nDataSize) {
				if (SetFilePointer(hFile, dwFileStart, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER) {
					SendError(416, "Requested Range Not Satisfiable");
					return true;
				}

				const char szHttpPartial[] = "HTTP/1.1 206 Partial Content\r\n"
				    "Connection: Keep-Alive\r\n"
				    "Date: %s\r\n"
				    "Server: MirandaWeb/%s\r\n"
				    "Accept-Ranges: bytes\r\n"
				    "ETag: %s\r\n"
				    "Content-Length: %d\r\n"
				    "Content-Type: %s\r\n"
				    "Content-Range: bytes %d-%d/%d\r\n"
				    "Last-Modified: %s\r\n"
				    "\r\n";

				dwBytesToWrite = mir_snprintf(szBuf, SIZEOF(szBuf), szHttpPartial,
				    szCurTime,
				    PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM),
				    szETag,
				    dwDataToSend,
				    pszGetMimeType(pszRealPath),
				    dwFileStart,
				    (dwFileStart + dwDataToSend - 1),
				    nDataSize,
				    szFileTime);
			} else {
				const char szHttpOk[] = "HTTP/1.1 200 OK\r\n"
				    "Connection: Keep-Alive\r\n"
				    "Date: %s\r\n"
				    "Server: MirandaWeb/%s\r\n"
				    "Accept-Ranges: bytes\r\n"
				    "ETag: %s\r\n"
				    "Content-Length: %d\r\n"
				    "Content-Type: %s\r\n"
				    "Last-Modified: %s\r\n"
				    "\r\n";

				dwBytesToWrite = mir_snprintf(szBuf, SIZEOF(szBuf), szHttpOk,
				    szCurTime,
				    PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM),
				    szETag,
				    nDataSize,
				    pszGetMimeType(pszRealPath),
				    szFileTime);
			}

			Netlib_Send(hConnection, szBuf, dwBytesToWrite, 0);

			if (bIsGetCommand) {
				static int nThreadCount = 0;
				nThreadCount++;

				DWORD dwLastUpdate = GetTickCount();
				DWORD dwLastCurrentDL = 0;
				/*

				dwLastDLSTickCount = dwCurTick;
				dwCurrentDL;*/

				//DWORD dwMaxSpeed = 8192;// Byte pr Sek
				//DWORD dwMaxSpeed = 20000;// Byte pr Sek
				//DWORD dwMaxSpeed = 163840;// Byte pr Sek
				//DWORD dwMaxSpeed = 4096;// Byte pr Sek

				DWORD dwLastResetTime = GetTickCount();
				int nMaxBytesToSend = nMaxUploadSpeed / nThreadCount;

				for (;;) {
					{
						DWORD dwCurTick = GetTickCount();
						if (dwCurTick - dwLastUpdate >= 1000) {
							dwSpeed = ((dwCurrentDL - dwLastCurrentDL) * 1000) / (dwCurTick - dwLastUpdate);
							dwLastUpdate = dwCurTick;
							dwLastCurrentDL = dwCurrentDL;
						}
					}

					if (nMaxUploadSpeed == 0) {
						Sleep(1000);
						continue;
					}

					bool bSpeedLimit = (nMaxUploadSpeed >= 0) && (bIsOnline || !bLimitOnlyWhenOnline);

					DWORD dwCurOpr = sizeof(szBuf);
					if (bSpeedLimit)
						dwCurOpr = min(nMaxBytesToSend, sizeof(szBuf));

					if (!ReadFile(hFile, szBuf, dwCurOpr, &dwBytesToWrite, NULL))
						break;

					if (dwBytesToWrite <= 0)
						break;

					if (dwCurrentDL + dwBytesToWrite > dwDataToSend)
						dwBytesToWrite = dwDataToSend - dwCurrentDL;

					if (bSpeedLimit)
						nMaxBytesToSend -= dwBytesToWrite;

					DWORD dwSend = Netlib_Send(hConnection, szBuf, dwBytesToWrite, MSG_NODUMP);
					if (dwSend == SOCKET_ERROR)
						break;
					dwCurrentDL += dwSend;
					if (dwSend != dwBytesToWrite)
						break;

					if (dwCurrentDL >= dwDataToSend)
						break;

					if (bSpeedLimit && nMaxBytesToSend <= 0) {
						// we have reached the limmit
						DWORD dwTimeUsed = GetTickCount() - dwLastResetTime;
						if (dwTimeUsed < 1000)
							Sleep(1000 - dwTimeUsed);
						dwLastResetTime = GetTickCount();
						nMaxBytesToSend = nMaxUploadSpeed / nThreadCount;
					}
				}

				// file is always closed in destructor 
				if (szTempfile[0] != '\0') {
					// and here - since it is a temporary index which as to be deleted
					CloseHandle(hFile);
					hFile = INVALID_HANDLE_VALUE;

					DeleteFile(szTempfile);
				}
				clCritSection.Lock();
				nThreadCount--;

				bool bNeedToWriteConfig = false;

				if (dwCurrentDL == nDataSize) {
					if (pclCur->st.nMaxDownloads > 0) {
						pclCur->st.nMaxDownloads--;
						bNeedToWriteConfig = true;
					}
				}

				pclCur->bRemoveUser(this);

				// nMaxDownloads can have been decreesed by another thread.
				// Therefore we test it even if we did'en decreese it
				if (pclCur->st.nMaxDownloads == 0 && !pclCur->bAnyUsers()) {
					CLFileShareNode **pclPrev = &pclFirstNode;
					for (CLFileShareNode * pcl = pclFirstNode ; pcl ; pcl = pcl->pclNext) {
						if (pcl == pclCur) {
							*pclPrev = pclCur->pclNext;
							ShowPopupWindow(Translate("Share removed"), pclCur->st.pszSrvPath, RGB(255, 189, 189));
							delete pclCur;
							bNeedToWriteConfig = true;
							break;
						}
						pclPrev = &pcl->pclNext;
					}
				}

				if (bNeedToWriteConfig) {
					bWriteConfigurationFile();
				}
			}

			return true;
		}
	}


#ifdef _DEBUG
	OutputDebugString("###########   Request Failed   ###########\n");
	OutputDebugString(pszRequest);
#endif

	pszRequest[nUriLength] = 0;

	if ((nUriLength != 12 || strncmp(pszRequest, "/favicon.ico", nUriLength)) &&  // do not show popup of favicon.ico
	    *(ULONG*)(&stAddr) != 0x0100007F) { // do not show popup of 127.0.0.1
		ShowPopupWindow(inet_ntoa(stAddr), pszRequest, RGB(255, 189, 189));
	}

	SendError(404, "Not Found", "The requested URL was not found on this server.");

	return false;
}
示例#21
0
文件: xcopy.c 项目: FDOS/xcopy
/*-------------------------------------------------------------------------*/
void xcopy_file(const char *src_filename,
                const char *dest_filename) {
  int dest_file_exists;
  int fileattrib;
  struct stat src_statbuf;
  struct stat dest_statbuf;
  struct dfree disktable;
  unsigned long free_diskspace;
  char ch;
  char msg_prompt[255];


  if (switch_prompt) {
    /* ask for confirmation to create file */
    ch = confirm(dest_filename,
      catgets(cat, 3, 2, "Yes"),
      catgets(cat, 3, 3, "No"), NULL, NULL);
    if (ch == 2 /* 'N' */) {
      /* no -> skip file */
      return;
    }
  }

  /* check if source and destination file are equal */
  if (stricmp(src_filename, dest_filename) == 0) {
    printf("%s - %s\n", catgets(cat, 1, 21, "File cannot be copied onto itself"), src_filename);
    catclose(cat);
    exit(4);
  }

  /* check source file for read permission */
  /* (only usefull under an OS with the ability to deny read access) */
  if (access(src_filename, R_OK) != 0) {
    printf("%s - %s\n", catgets(cat, 1, 22, "Read access denied"), src_filename);
    if (switch_continue) {
      return;
    }
    else {
      catclose(cat);
      exit(5);
    }
  }

  /* get info of source and destination file */
  stat((char *)src_filename, &src_statbuf);
  dest_file_exists = !stat((char *)dest_filename, &dest_statbuf);

  /* get amount of free disk space in destination drive */
  getdfree(dest_drive, &disktable);
  free_diskspace = (unsigned long) disktable.df_avail *
                   disktable.df_sclus * disktable.df_bsec;

  if (dest_file_exists) {
    if (switch_date) {
      if (switch_date < 0) {
        /* check, that only newer files are copied */
        if (src_statbuf.st_mtime <= dest_statbuf.st_mtime) {
          return;
        }
      }
      else {
        /* check, that only files changed on or after the specified date */
        /* are copied                                                    */
        if (src_statbuf.st_mtime < switch_date) {
          return;
        }
      }
    }

    switch (switch_confirm) {
      case 1:
        /* skip file */
        return;
      case 2:
        /* ask for confirmation to overwrite file */
        strmcpy(msg_prompt,
          catgets(cat, 3, 1, "Overwrite"), sizeof(msg_prompt));
        strmcat(msg_prompt, " ", sizeof(msg_prompt));
        strmcat(msg_prompt, dest_filename, sizeof(msg_prompt));
        ch = confirm(msg_prompt,
          catgets(cat, 3, 2, "Yes"),
          catgets(cat, 3, 3, "No"),
          catgets(cat, 3, 4, "Overwrite all"),
          catgets(cat, 3, 5, "Skip all"));
        switch (ch) {
          case 2: /* 'N' */
            /* no -> skip file */
            return;
          case 3: /* 'O' */
            /* overwrite all -> set confirm switch */
            switch_confirm = 0;
            break;
          case 4: /* 'S' */
            /* skip all -> set confirm switch */
            switch_confirm = 1;
            return;
        }
        break;
    }

    /* check free space on destination disk */
    /* *** was wrong, was: "if (src... > free... - dest...) ..." */
    if ( (src_statbuf.st_size > dest_statbuf.st_size) &&
         ((src_statbuf.st_size - dest_statbuf.st_size) > free_diskspace) ) {
      printf("%s - %s\n", catgets(cat, 1, 23, "Insufficient disk space in destination path"), dest_filename);
      catclose(cat);
      exit(39);
    }

    /* get file attribute from destination file */
    fileattrib = _chmod(dest_filename, 0);

    /* check destination file for write permission */
    if ((fileattrib & (64 ^ FA_RDONLY)) != 0) {
      if (!switch_readonly) {
        printf("%s - %s\n", catgets(cat, 1, 24, "Write access denied"), dest_filename);
        if (switch_continue) {
          return;
        }
        else {
          catclose(cat);
          exit(5);
        }
      }

      /* check, if file copying should be simulated */
      if (!switch_listmode) {
        /* remove readonly attribute from destination file */
        fileattrib = fileattrib ^ FA_RDONLY;
        _chmod(dest_filename, 1, fileattrib);
      }
    }
  }
  else {
    /* check free space on destination disk */
    if (src_statbuf.st_size > free_diskspace) {
      printf("%s - %s\n", catgets(cat, 1, 25, "Insufficient disk space in destination path"), dest_filename);
      catclose(cat);
      exit(39);
    }
  }

  if (!switch_quiet) {
    printf("%s %s", catgets(cat, 1, 26, "Copying"), src_filename);
    if (switch_fullnames) {
      printf(" -> %s\n", dest_filename);
    }
    else {
      printf("\n");
    }
  }

  /* check, if file copying should be simulated */
  if (!switch_listmode) {
    copy_file(src_filename, dest_filename, switch_continue);

    if (switch_archive_reset) {
      /* remove archive attribute from source file */
      fileattrib = _chmod(src_filename, 0);
      _chmod(src_filename, 1, fileattrib ^ FA_ARCH);
    }
  }

  file_counter++;
}
示例#22
0
文件: xcopy.c 项目: FDOS/xcopy
/*-------------------------------------------------------------------------*/
void xcopy_files(const char *src_pathname,
                 const char *src_filename,
                 const char *dest_pathname,
                 const char *dest_filename) {
  char filepattern[MAXPATH],
       new_src_pathname[MAXPATH],
       new_dest_pathname[MAXPATH],
       src_path_filename[MAXPATH],
       dest_path_filename[MAXPATH],
       tmp_filename[MAXFILE + MAXEXT],
       tmp_pathname[MAXPATH];
  struct ffblk fileblock;
  int fileattrib,
      done;


  if (switch_emptydir ||
      switch_subdir ||
      switch_tree) {
    /* copy files in subdirectories too */
    strmcpy(filepattern, src_pathname, sizeof(filepattern));
    strmcat(filepattern, "*.*", sizeof(filepattern));
    done = findfirst(filepattern, &fileblock, FA_DIREC);
    while (!done) {
      if ((fileblock.ff_attrib & FA_DIREC) != 0 &&
          strcmp(fileblock.ff_name, ".") != 0 &&
          strcmp(fileblock.ff_name, "..") != 0) {
        /* build source pathname */
        strmcpy(new_src_pathname, src_pathname, sizeof(new_src_pathname));
        strmcat(new_src_pathname, fileblock.ff_name, sizeof(new_src_pathname));
        strmcat(new_src_pathname, DIR_SEPARATOR, sizeof(new_src_pathname));

        /* build destination pathname */
        strmcpy(new_dest_pathname, dest_pathname, sizeof(new_dest_pathname));
        strmcat(new_dest_pathname, fileblock.ff_name, sizeof(new_dest_pathname));
        strmcat(new_dest_pathname, DIR_SEPARATOR, sizeof(new_dest_pathname));

        xcopy_files(new_src_pathname, src_filename,
                    new_dest_pathname, dest_filename);
      }

      done = findnext(&fileblock);
    }
  }

  fileattrib = FA_RDONLY + FA_ARCH;
  if (switch_hidden) {
    /* replace hidden and system files too */
    fileattrib = fileattrib + FA_HIDDEN + FA_SYSTEM;
  }

  /* find first source file */
  strmcpy(filepattern, src_pathname, sizeof(filepattern));
  strmcat(filepattern, src_filename, sizeof(filepattern));
  done = findfirst(filepattern, &fileblock, fileattrib);

  if (!done) {
    file_found = -1;
  }

  /* check if destination directory must be created */
  if ((!done || switch_emptydir) &&
      !dir_exists(dest_pathname)) {
    strmcpy(tmp_pathname, dest_pathname, sizeof(tmp_pathname));
    if (make_dir(tmp_pathname) != 0) {
      printf("%s %s\n", catgets(cat, 1, 20, "Unable to create directory"), tmp_pathname);
      if (switch_continue) {
        return;
      }
      else {
        catclose(cat);
        exit(4);
      }
    }
  }

  /* check, if only directory tree should be created */
  if (switch_tree) {
    return;
  }

  /* copy files */
  while (!done) {
    /* check, if copied files should have archive attribute set */
    if ((switch_archive == 0 && switch_archive_reset == 0) ||
        fileblock.ff_attrib & FA_ARCH) {
      /* build source filename including path */
      strmcpy(src_path_filename, src_pathname, sizeof(src_path_filename));
      strmcat(src_path_filename, fileblock.ff_name, sizeof(src_path_filename));

      /* build destination filename including path */
      strmcpy(dest_path_filename, dest_pathname, sizeof(dest_path_filename));
      build_filename(tmp_filename, fileblock.ff_name, dest_filename);
      strmcat(dest_path_filename, tmp_filename, sizeof(dest_path_filename));

      xcopy_file(src_path_filename, dest_path_filename);
    }

    done = findnext(&fileblock);
  }
}
示例#23
0
int translatedpart4(int uid)
{
    char *ept,*pt;
    struct translatet *th;
    struct socketnodes *lkm;
    pcontext;
    th=gettranslate(uid);
    pcontext;
    if(th==NULL)
	return 0x0;
    lkm=getpsocketbysock(th->sock);
    if(lkm==NULL)
    {
	erasetranslate(uid);
	return 0x0;
    }
    pcontext;
    ept=strstr(ircbuf,lngtxt(871));
    if(ept==NULL)
    {
	ept=strstr(ircbuf,"<p>");
    }
    if(ept!=NULL)
    {
	ept=strstr(th->translatedtext,lngtxt(872));
	if(ept!=NULL)
	{
	    ept=strchr(th->translatedtext,':');
	    if(ept==th->translatedtext) ept=strchr(ept+1,':');
	    if(ept!=NULL)
	    {
		*ept=0;
		th->translatedtext=strmcat(th->translatedtext,lngtxt(873));
	    }
	}
	ept=strstr(th->translatedtext,"<P>");
	if(ept!=NULL)
	{ 
	    *ept=0;
	}
	th->translatedtext=strmcat(th->translatedtext,"\r\n");
	if(th->direction==TR_TO)
	{
	    if(user(th->usern)->outstate==STD_CONN)
	    {
		writesock(user(th->usern)->outsock,th->translatedtext);
		if(user(th->usern)->instate>STD_NOCON)
		{
		    pt=strchr(th->translatedtext,':');
		    if(pt!=NULL)
		    {
			if(strchr("#!&+",*th->dest)!=NULL)
			{
			    ssnprintf(user(th->usern)->insock,lngtxt(874),user(th->usern)->nick,user(th->usern)->login,user(th->usern)->host,th->dest,pt);
			} else {
			    ssnprintf(user(th->usern)->insock,lngtxt(875),th->dest,user(th->usern)->nick,pt);
			}
		    }
		}
	    }
	} else {
	    if(user(th->usern)->instate>STD_NOCON)
	    {
		writesock(user(th->usern)->insock,th->translatedtext);
	    }
	}
	erasetranslate(uid); /* job done, socket gone */
    } else {    
	ept=nobreak(ircbuf);
	pt=strstr(ept,"<textarea");
	if(pt!=NULL)
	{
	    pt=strchr(pt,'>');
	    if(pt!=NULL)
	    {
		ept=pt+1;
	    }
	}
	while(*ept==' ' || *ept==9) ept++;
	if(*ept)
	{
	    th->translatedtext=strmcat(th->translatedtext,ept);
	    th->translatedtext=strmcat(th->translatedtext," ");
	}
    }
    return 0x0;
}
示例#24
0
文件: pathutl.c 项目: NUOG/ejudge
char *
pathcat(char *dst, char const *src)
{
  return strmcat(dst, src, PATH_MAX);
}
示例#25
0
文件: xcopy.c 项目: FDOS/xcopy
/*-------------------------------------------------------------------------*/
int main(int argc, const char **argv) {
  int fileargc, 
	  switchargc;
  char *fileargv[255],
       *switchargv[255],
       env_prompt[MAXSWITCH],
       tmp_switch[MAXSWITCH] = "",
       src_pathname[MYMAXPATH] = "",
       src_filename[MAXFILE + MAXEXT] = "",
       dest_pathname[MYMAXPATH] = "",
       dest_filename[MAXFILE + MAXEXT] = "",
       *ptr,
       ch;
  int i, length;
  THEDATE dt;
#ifdef __WATCOMC__
  struct dostime_t tm;
#else
  struct time tm;
#endif

  cat = catopen ("xcopy", 0);	/* initialize kitten */

  classify_args(argc, argv, &fileargc, fileargv, &switchargc, switchargv);

  if (fileargc < 1 || switchargv[0] == "?") {
    print_help();
    catclose(cat);
    exit(4);
  }

  if (fileargc > 2) {
    printf("%s\n",catgets(cat, 1, 1, "Invalid number of parameters"));
    catclose(cat);
    exit(4);
  }

  /* activate termination function */
  /* (writes no. of copied files at exit) */
  atexit(exit_fn);

  /* read environment variable COPYCMD to set confirmation switch */
  strmcpy(env_prompt, getenv("COPYCMD"), sizeof(env_prompt));
  if (env_prompt[0] != '\0') {
    strupr(env_prompt);
    if (strcmp(env_prompt, "/Y") == 0)
      /* overwrite existing file(s) */
      switch_confirm = 0;
    else if (strcmp(env_prompt, "/N") == 0)
      /* skip existing file(s) */
      switch_confirm = 1;
    else
      /* ask for confirmation */
      switch_confirm = 2;
  }

  /* get switches */
  for (i = 0; i < switchargc; i++) {
    strmcpy(tmp_switch, switchargv[i], sizeof(tmp_switch));
    strupr(tmp_switch);
    if (strcmp(tmp_switch, "A") == 0)
      switch_archive = -1;
    else if (strcmp(tmp_switch, "C") == 0)
      switch_continue = -1;
    else if (strcmp(tmp_switch, "D") == 0)
      switch_date = -1;
    else if (strncmp(tmp_switch, "D:", 2) == 0) {
      if (strtodate(tmp_switch+2, &dt) != 0 ||
          !datevalid(&dt)) {
        printf("%s\n",catgets(cat, 1, 2, "Invalid date"));
        catclose(cat);
        exit(4);
      }
#ifdef __WATCOMC__
      memset((void *)&tm, 0, sizeof(struct dostime_t));
      /* tm.tm_hour = 0; tm.tm_min = 0; tm.tm_sec = 0; tm.tm_hund = 0; */
#else
      memset((void *)&tm, 0, sizeof(struct time));
      /* tm.ti_hour = 0; tm.ti_min = 0; tm.ti_sec = 0; tm.ti_hund = 0; */
#endif
      switch_date = dostounix(&dt, &tm);
    }
    else if (strcmp(tmp_switch, "E") == 0)
      switch_emptydir = -1;
    else if (strcmp(tmp_switch, "F") == 0)
      switch_fullnames = -1;
    else if (strcmp(tmp_switch, "H") == 0)
      switch_hidden = -1;
    else if (strcmp(tmp_switch, "I") == 0)
      switch_intodir = -1;
    else if (strcmp(tmp_switch, "L") == 0)
      switch_listmode = -1;
    else if (strcmp(tmp_switch, "M") == 0)
      switch_archive_reset = -1;
    else if (strcmp(tmp_switch, "N") == 0)
      switch_confirm = 1;
    else if (strcmp(tmp_switch, "P") == 0)
      switch_prompt = -1;
    else if (strcmp(tmp_switch, "Q") == 0)
      switch_quiet = -1;
    else if (strcmp(tmp_switch, "R") == 0)
      switch_readonly = -1;
    else if (strcmp(tmp_switch, "S") == 0)
      switch_subdir = -1;
    else if (strcmp(tmp_switch, "T") == 0)
      switch_tree = -1;
    else if (strcmp(tmp_switch, "V") == 0) {
      switch_verify = -1;
      bak_verify = getverify();
      setverify(1);
    }
    else if (strcmp(tmp_switch, "W") == 0)
      switch_wait = -1;
    else if (strcmp(tmp_switch, "Y") == 0)
      switch_confirm = 0;
    else if (strcmp(tmp_switch, "-Y") == 0)
      switch_confirm = 2;
    else {
      printf("%s - %s\n", catgets(cat, 1, 3, "Invalid switch"), switchargv[i]);
      catclose(cat);
      exit(4);
    }
  }

  /* get source pathname (with trailing backspace) and filename/-pattern */
  length = strlen(fileargv[0]);
  if (length > (MAXPATH - 1)) {
    printf("%s\n", catgets(cat, 1, 4, "Source path too long"));
    catclose(cat);
    exit(4);
  }
  _fullpath(src_pathname, fileargv[0], MYMAXPATH);
  if (src_pathname[0] == '\0') {
    printf("%s\n", catgets(cat, 1, 5, "Invalid source drive specification"));
    catclose(cat);
    exit(4);
  }
  /* check source path */
  if (!dir_exists(src_pathname)) {
    /* source path contains a filename/-pattern -> separate it */
    ptr = strrchr(src_pathname, *DIR_SEPARATOR);
    ptr++;
    strmcpy(src_filename, ptr, sizeof(src_filename));
    *ptr = '\0';
    if (!dir_exists(src_pathname)) {
      printf("%s - %s\n", catgets(cat, 1, 6, "Source path not found"), src_pathname);
      catclose(cat);
      exit(4);
    }
  }
  else {
    /* source is a directory -> filepattern = "*.*" */
    strmcpy(src_filename, "*.*", sizeof(src_filename));
  }
  cat_separator(src_pathname);
  length = strlen(src_pathname);
  if (length > (MAXDRIVE - 1 + MAXDIR - 1)) {
    printf("%s\n", catgets(cat, 1, 7, "Source path too long"));
    catclose(cat);
    exit(4);
  }

  /* get destination pathname (with trailing backspace) and */
  /* filename/-pattern */
  if (fileargc < 2) {
    /* no destination path specified -> use current */
    getcwd(dest_pathname, MAXPATH);
    strmcpy(dest_filename, "*.*", sizeof(dest_filename));
  }
  else {
    /* destination path specified */
    length = strlen(fileargv[1]);
    if (length > (MAXPATH - 1)) {
      printf("%s\n", catgets(cat, 1, 8, "Destination path too long"));
      catclose(cat);
      exit(4);
    }
    _fullpath(dest_pathname, fileargv[1], MYMAXPATH);
    if (dest_pathname[0] == '\0') {
      printf("%s\n", catgets(cat, 1, 9, "Invalid destination drive specification"));
      catclose(cat);
      exit(4);
    }
    /* check destination path */
    if (fileargv[1][length - 1] != *DIR_SEPARATOR &&
        !dir_exists(dest_pathname)) {
      ptr = strrchr(dest_pathname, *DIR_SEPARATOR);
      ptr++;
      strmcpy(dest_filename, ptr, sizeof(dest_filename));
      *ptr = '\0';
      if ((ptr = strchr(dest_filename, '*')) == NULL &&
          (ptr = strchr(dest_filename, '?')) == NULL) {
        /* last destination entry is not a filepattern -> does it specify */
        /* a file or directory? */
        if (((ptr = strchr(src_filename, '*')) == NULL &&
             (ptr = strchr(src_filename, '?')) == NULL) ||
            !switch_intodir) {
          /* source is a single file or switch /I was not specified -> ask */
          /* user if destination should be a file or a directory */
          printf("%s %s %s\n",
            catgets(cat, 1, 10, "Does"),
            dest_filename,
            catgets(cat, 1, 11, "specify a file name"));
          ch = confirm(
            catgets(cat, 1, 12, "or directory name on the target"),
            catgets(cat, 1, 13, "File"),
            catgets(cat, 1, 14, "Directory"), NULL, NULL);
          switch (ch) {
            case 1: /* 'F' */
              /* file */
              switch_file = -1;
              break;
            case 2: /* 'D' */
              /* directory */
              switch_intodir = -1;
              break;
          }
        }
        if (switch_intodir) {
          /* destination is a directory -> filepattern = "*.*" */
          strmcat(dest_pathname, dest_filename, sizeof(dest_pathname));
          strmcpy(dest_filename, "*.*", sizeof(dest_filename));
        }
      }
    }
    else {
      /* destination is a directory -> filepattern = "*.*" */
      strmcpy(dest_filename, "*.*", sizeof(dest_filename));
    }
  }
  cat_separator(dest_pathname);
  length = strlen(dest_pathname);
  if (length > (MAXDRIVE - 1 + MAXDIR - 1)) {
    printf("%s\n",catgets(cat, 1, 15, "Destination path too long"));
    catclose(cat);
    exit(4);
  }

  /* check for cyclic path */
  if ((switch_emptydir || switch_subdir) &&
      cyclic_path(src_pathname, dest_pathname)) {
    printf("%s\n",catgets(cat, 1, 16, "Cannot perform a cyclic copy"));
    catclose(cat);
    exit(4);
  }

  /* get destination drive (1 = A, 2 = B, 3 = C, ...) */
  dest_drive = toupper(dest_pathname[0]) - 64;

  if (switch_wait) {
    printf("%s\n",catgets(cat, 1, 17, "Press enter to continue..."));
    (void)getchar(); /* getch(); would need conio.h */
    fflush(stdin);
  }

  xcopy_files(src_pathname, src_filename, dest_pathname, dest_filename);
  if (!file_found) {
    printf("%s - %s\n",catgets(cat, 1, 18, "File not found"), src_filename);
    catclose(cat);
    exit(1);
  }

  catclose(cat);
  return 0;
}