Example #1
0
domainname guess_zone_name(const char *file) {
  const char *ptr = file + strlen(file) - 1;
  char tmp[256];
  int t;

  while (ptr >= file) {
    if (*ptr == pathdelim) { ptr++; break; }
    ptr--;
  }

  t = strlen(ptr);
  if (tolower(ptr[0]) == 'd' &&
      tolower(ptr[1]) == 'b' &&
      ptr[2] == '.') {
    return ptr + 3;
  } else if (t >= 4 && (strncmpi(ptr + t - 4, ".prm", 4) == 0 || strncmpi(ptr + t - 4, ".dns", 4) == 0)) {
    if (strlen(ptr) - 4 >= 256) throw PException("File name too long!");
    memcpy(tmp, ptr, t - 4);
    tmp[t - 4] = '\0';
    return domainname((char*)tmp);
  } else return ptr;
}
Example #2
0
struct clan* clan_searchname( const char* name ){
	struct clan* c;

	DBIterator *iter = db_iterator(clan_db);
	for( c = (struct clan*)dbi_first(iter); dbi_exists(iter); c = (struct clan*)dbi_next(iter) ){
		if( strncmpi( c->name, name, NAME_LENGTH ) == 0 ){
			break;
		}
	}
	dbi_destroy(iter);

	return c;
}
Example #3
0
/// Party data lookup using party name.
struct party_data* party_searchname(const char* str)
{
    struct party_data* p;

    DBIterator *iter = db_iterator(party_db);
    for( p = (struct party_data*)dbi_first(iter); dbi_exists(iter); p = (struct party_data*)dbi_next(iter) ) {
        if( strncmpi(p->party.name,str,NAME_LENGTH) == 0 )
            break;
    }
    dbi_destroy(iter);

    return p;
}
Example #4
0
// Alternative to searchvar()            [JdS 2004/1/28]
// searcharg() searches for a "variable" of a given name
int searcharg(char *name)
{
 int i=0, l=strlen(name);

 while(i<argvarcount)
 {
  if(!strncmpi(argnameptr[i],name,l))
   return 1;
  i++;
 }

 return 0;
}
Example #5
0
boolean restrict_name(struct obj *otmp, const char *name)  /* returns 1 if name is restricted for otmp->otyp */
{
	const struct artifact *a;
	const char *aname;

	if (!*name) return FALSE;
	if (!strncmpi(name, "the ", 4)) name += 4;

		/* Since almost every artifact is SPFX_RESTR, it doesn't cost
		   us much to do the string comparison before the spfx check.
		   Bug fix:  don't name multiple elven daggers "Sting".
		 */
	for (a = artilist+1; a->otyp; a++) {
	    if (a->otyp != otmp->otyp) continue;
	    aname = a->name;
	    if (!strncmpi(aname, "the ", 4)) aname += 4;
	    if (!strcmp(aname, name))
		return ((boolean)((a->spfx & (SPFX_NOGEN|SPFX_RESTR)) != 0 ||
			otmp->quan > 1L));
	}

	return FALSE;
}
Example #6
0
int searchvar(char *name)
{
 int i=0,nameidx=0;
 int l=strlen(name);

 while(i<argnamecount)
 {
  if(!strncmpi(argnamestr+nameidx+sizeof(int),name,l))
   return 1;
  nameidx+=*(int*)(&argnamestr[nameidx]);
  i++;
 }
 return 0;
}
Example #7
0
shellCmd_t* shellFindCmd(uint8_t *str) 
{
    int i;
    
    for (i = 0; i < CMD_NUM; i++) {
        if (strncmpi(str, shellCmdTable[i].name, strlen(shellCmdTable[i].name)) == 0 &&
            (str[strlen(shellCmdTable[i].name)] == ' ' ||
             str[strlen(shellCmdTable[i].name)] == '\r' ||
             str[strlen(shellCmdTable[i].name)] == '\n') ) {
            return &(shellCmdTable[i]);
        }
    }
    return NULL;
}
Example #8
0
/// Party data lookup using party name.
struct party_data* party_searchname(const char* str)
{
	struct party_data* p;

	DBIterator* iter = party_db->iterator(party_db);
	for( p = (struct party_data*)iter->first(iter,NULL); iter->exists(iter); p = (struct party_data*)iter->next(iter,NULL) )
	{
		if( strncmpi(p->party.name,str,NAME_LENGTH) == 0 )
			break;
	}
	iter->destroy(iter);

	return p;
}
Example #9
0
/**
 * Read and set configuration.
 *  If the option is supported, adjust the internal state.
 * @param self: pointer to db
 * @param key: config keyword
 * @param value: config value for keyword
 * @return true if successful, false if something has failed
 */
static bool account_db_sql_set_property(AccountDB* self, const char* key, const char* value) {
	AccountDB_SQL* db = (AccountDB_SQL*)self;
	const char* signature;

	signature = "login_server_";
	if( strncmp(key, signature, strlen(signature)) == 0 ) {
		key += strlen(signature);
		if( strcmpi(key, "ip") == 0 )
			safestrncpy(db->db_hostname, value, sizeof(db->db_hostname));
		else
		if( strcmpi(key, "port") == 0 )
			db->db_port = (uint16)strtoul(value, NULL, 10);
		else
		if( strcmpi(key, "id") == 0 )
			safestrncpy(db->db_username, value, sizeof(db->db_username));
		else
		if( strcmpi(key, "pw") == 0 )
			safestrncpy(db->db_password, value, sizeof(db->db_password));
		else
		if( strcmpi(key, "db") == 0 )
			safestrncpy(db->db_database, value, sizeof(db->db_database));
		else
		if( strcmpi(key, "account_db") == 0 )
			safestrncpy(db->account_db, value, sizeof(db->account_db));
		else
		if( strcmpi(key, "global_acc_reg_str_table") == 0 )
			safestrncpy(db->global_acc_reg_str_table, value, sizeof(db->global_acc_reg_str_table));
		else
		if( strcmpi(key, "global_acc_reg_num_table") == 0 )
			safestrncpy(db->global_acc_reg_num_table, value, sizeof(db->global_acc_reg_num_table));
		else
			return false;// not found
		return true;
	}

	signature = "login_";
	if( strncmpi(key, signature, strlen(signature)) == 0 ) {
		key += strlen(signature);
		if( strcmpi(key, "codepage") == 0 )
			safestrncpy(db->codepage, value, sizeof(db->codepage));
		else
		if( strcmpi(key, "case_sensitive") == 0 )
			db->case_sensitive = (config_switch(value)==1);
		else
			return false;// not found
		return true;
	}

	return false;// not found
}
Example #10
0
int IsCenterOnLine(char* linetxt)
{
   char* pos;
   
   if (strncmpi(linetxt, "$[CENTER](", 10) == 0)
   {
        pos = strchr(linetxt, ')');   
        if (!pos) 
           return FALSE;
        else
           return TRUE;     
   }
   
   return FALSE;
}
Example #11
0
bool findfile(const char * filename, const char * path) {
    DIR *dir;
    struct dirent *file;

    dir = opendir(path);

    char temp[11];
    while ((file = readdir(dir))) {
        snprintf(temp,sizeof(temp),"%s",file->d_name);
        if (!strncmpi(temp,filename,11)) {
            closedir(dir);
            return true;
        }
    }
    closedir(dir);
    return false;
}
Example #12
0
bool loginlog_config_read(const char* key, const char* value)
{
    const char* signature;

    signature = "sql.";
    if( strncmpi(key, signature, strlen(signature)) == 0 )
    {
        key += strlen(signature);
        if( strcmpi(key, "db_hostname") == 0 )
            safestrncpy(global_db_hostname, value, sizeof(global_db_hostname));
        else if( strcmpi(key, "db_port") == 0 )
            global_db_port = (uint16)strtoul(value, NULL, 10);
        else if( strcmpi(key, "db_username") == 0 )
            safestrncpy(global_db_username, value, sizeof(global_db_username));
        else if( strcmpi(key, "db_password") == 0 )
            safestrncpy(global_db_password, value, sizeof(global_db_password));
        else if( strcmpi(key, "db_database") == 0 )
            safestrncpy(global_db_database, value, sizeof(global_db_database));
        else if( strcmpi(key, "codepage") == 0 )
            safestrncpy(global_codepage, value, sizeof(global_codepage));
        else
            return false;// not found
        return true;
    }

    if( strcmpi(key, "log_db_ip") == 0 )
        safestrncpy(log_db_hostname, value, sizeof(log_db_hostname));
    else if( strcmpi(key, "log_db_port") == 0 )
        log_db_port = (uint16)strtoul(value, NULL, 10);
    else if( strcmpi(key, "log_db_id") == 0 )
        safestrncpy(log_db_username, value, sizeof(log_db_username));
    else if( strcmpi(key, "log_db_pw") == 0 )
        safestrncpy(log_db_password, value, sizeof(log_db_password));
    else if( strcmpi(key, "log_db_db") == 0 )
        safestrncpy(log_db_database, value, sizeof(log_db_database));
    else if( strcmpi(key, "log_codepage") == 0 )
        safestrncpy(log_codepage, value, sizeof(log_codepage));
    else if( strcmpi(key, "log_login_db") == 0 )
        safestrncpy(log_login_db, value, sizeof(log_login_db));
    else
        return false;

    return true;
}
Example #13
0
 void
 interject_assistance(
 int num,
 int interjection_type,
 genericptr_t ptr1,
 genericptr_t ptr2)
 {
     switch (num) {
     case 1: {
         char *panicmsg = (char *)ptr1;
         char *datadir = (char *)ptr2;
         char *tempdir = nh_getenv("TEMP");
         interjection_type = INTERJECT_PANIC;
         interjection[INTERJECT_PANIC] = 1;
         /*
          * ptr1 = the panic message about to be delivered.
          * ptr2 = the directory prefix of the dungeon file
          *        that failed to open.
          * Check to see if datadir matches tempdir or a
          * common windows temp location. If it does, inform
          * the user that they are probably trying to run the
          * game from within their unzip utility, so the required
          * files really don't exist at the location. Instruct
          * them to unpack them first.
          */
         if (panicmsg && datadir) {
             if (!strncmpi(datadir, "C:\\WINDOWS\\TEMP", 15) ||
                 strstri(datadir, "TEMP") ||
                 (tempdir && strstri(datadir, tempdir))) {
                 (void)strncpy(interjection_buf[INTERJECT_PANIC],
                     "\nOne common cause of this error is attempting to execute\n"
                     "the game by double-clicking on it while it is displayed\n"
                     "inside an unzip utility.\n\n"
                     "You have to unzip the contents of the zip file into a\n"
                     "folder on your system, and then run \"NetHack.exe\" or \n"
                     "\"NetHackW.exe\" from there.\n\n"
                     "If that is not the situation, you are encouraged to\n"
                     "report the error as shown above.\n\n", 1023);
             }
         }
     }
         break;
     }
 }
Example #14
0
// Search for the party according to its name
struct party_data* search_partyname(char *str)
{
	struct DBIterator* iter;
	struct party_data* p;
	struct party_data* result = NULL;

	iter = party_db->iterator(party_db);
	for( p = (struct party_data*)iter->first(iter,NULL); iter->exists(iter); p = (struct party_data*)iter->next(iter,NULL) )
	{
		if( strncmpi(p->party.name, str, NAME_LENGTH) == 0 )
		{
			result = p;
			break;
		}
	}
	iter->destroy(iter);

	return result;
}
Example #15
0
/*
	lParam == NULL ...	全 IPMSG を終了
	lParam != NULL ...	lParam を BOOL * とみなし、IPMSG proccess が存在する
						場合は、そこにTRUE を代入する。
*/
BOOL CALLBACK TerminateIPMsgProc(HWND hWnd, LPARAM lParam)
{
	char	buf[MAX_BUF];

	if (::GetClassName(hWnd, buf, sizeof(buf)) != 0) {
		if (strncmpi(IPMSG_CLASS, buf, strlen(IPMSG_CLASS)) == 0) {
			if (lParam)
				*(BOOL *)lParam = TRUE;		// existFlg;
			else {
				::SendMessage(hWnd, WM_CLOSE, 0, 0);
				for (int i=0; i < 10; i++) {
					Sleep(300);
					if (!IsWindow(hWnd)) break;
				}
			}
		}
	}
	return	TRUE;
}
Example #16
0
bool
evalKey(
    const char *context,    // (I) 初期設定ファイルから読み取った文字列
    const char *name,       // (I) parameter を象徴する名前
    bool       &value )     // (O) parameter の値(bool)
{
    bool    ret = false;
    char    target[BUFSIZ];
    int     len;

    sprintf( target, "%s: ", name );
    len = strlen( target );

    if ( !strncmp( context, target, len ) ) {
        value = !strncmpi( context + len, "TRUE", 4 ) ? true : false;
        ret = true;
    }

    return ( ret );
}
int ares_strncasecmp(const char *a, const char *b, size_t n)
{
#if defined(HAVE_STRNCMPI)
  return strncmpi(a, b, n);
#elif defined(HAVE_STRNICMP)
  return strnicmp(a, b, n);
#else
  size_t i;

  for (i = 0; i < n; i++) {
    int c1 = ISUPPER(a[i]) ? tolower(a[i]) : a[i];
    int c2 = ISUPPER(b[i]) ? tolower(b[i]) : b[i];
    if (c1 != c2)
      return c1-c2;
    if (!c1)
      break;
  }
  return 0;
#endif
}
Example #18
0
// find target frame for any HTML tag with TARGET attribute
// <A HREF=... TARGET=...>
int findtarget(int basetarget)
{
 int target=basetarget;
 char *tagarg;

 if(arachne.framescount && getvar("TARGET",&tagarg))
 {
  int fr=0;

  if(!strcmpi(tagarg,"_parent"))
   return p->htmlframe[p->currentframe].parent;

  do
  {
   if(!strncmpi(p->htmlframe[fr].framename,tagarg,39))
    target=fr;
  }
  while(fr++<arachne.framescount);
 }
 return target;
}
Example #19
0
/*
 *  Check if the passed line begins with a specified word
 *  The word is matched case-insensitively.
 *  'len' is the length of the word.
 *  On success, the pointer is placed onto the next word.
 *  Return: 0: on failure
 */
int match_(char ** const Xp, const char * const word, int len)
{ char *p;

  assert(Xp && *Xp);
  assert(word && *word);
  assert(len > 0);

  if(strncmpi(p = *Xp, word, len) == 0) {
    /* line begins with string, now test if it is a word */
    p += len;
    if(*p) {
      if(!isspace(*p))    /* no word boundary */
        return 0;
      /* skip whitespaces */
      p = ltrim(p);
    }
    *Xp = p;
    return 1;   /* found */
  }

  return 0;
}
Example #20
0
int match_(char ** const Xp, const char * const word, int len)
{	char *p;

	assert(Xp && *Xp);
	assert(word && *word);
	assert(len > 0);

	if(strncmpi(p = *Xp, word, len) == 0) {
		/* line begins with string, now test if it is a word */
		p += len;
		if(*p) {
			char *q = ltrimcl(p);	/* skip to next token */
			if(q == p) 				/* no word boundary */
				return 0;
			p = q;
		}
		*Xp = p;
		return 1;   /* found */
	}

	return 0;
}
Example #21
0
/*
 * Determines and stores the base application path
 *
 * argc     The count of main arguments
 * argv     The array of argument values
 */
void wii_set_app_path( int argc, char *argv[] )
{    
  snprintf( app_path, WII_MAX_PATH, "%s", WII_BASE_APP_DIR );

  if( ( argc > 0 ) && 
      ( argv[0] != NULL ) && 
      ( strchr( argv[0], ':' ) != NULL ) ) // To support wiiload
  {
#ifdef WII_NETTRACE
    net_print_string(__FILE__,__LINE__, "Found drive prefix" );  
#endif

    char temp_path[WII_MAX_PATH];
    snprintf( temp_path, WII_MAX_PATH, "%s", argv[0] );

    char *loc;

    // Remove the file name
    loc = strrchr( temp_path, '/' );
    if (loc != NULL)
    {
      *loc = '\0'; 
    }

    snprintf( app_path, WII_MAX_PATH, "%s/", temp_path );
  }
  else
  {
#ifdef WII_NETTRACE
    net_print_string(__FILE__,__LINE__, "No drive prefix." );  
#endif
  }

  if( strncmpi( "usb", app_path, 3 ) == 0 )
  {
    wii_is_usb = TRUE;
  }
}
Example #22
0
int curl_strnequal(const char *first, const char *second, size_t max)
{
#if defined(HAVE_STRCASECMP)
  return !strncasecmp(first, second, max);
#elif defined(HAVE_STRCMPI)
  return !strncmpi(first, second, max);
#elif defined(HAVE_STRICMP)
  return !strnicmp(first, second, max);
#else
  while (*first && *second && max) {
    if (toupper(*first) != toupper(*second)) {
      break;
    }
    max--;
    first++;
    second++;
  }
  if(0 == max)
    return 1; /* they are equal this far */

  return toupper(*first) == toupper(*second);
#endif
}
Example #23
0
long
getAllPostsFromDeliciousHTML(
        const char      *userName,   /* (I) ユーザ名       */
        const char      *password,   /* (I) パスワード     */
        long            *numOfPosts, /* (I) 取得する情報数 */
                                     /* (O) 取得した情報数 */
        DELICIOUS_POSTS *posts       /* (O) 取得した情報   */
    )
{
    long        num   = 0;
    long        total = *numOfPosts;
    long        page  = 1;
    BOOL        cont  = TRUE;
    size_t      sz    = MAX_CONTENT_SIZE * 20;
    char        url[MAX_URLLENGTH];
    char        dateTime[MAX_DATELENGTH];
    char        *response;
    char        *response2;
    char        *cookie;
    char        *p, *q, *r, *s, *t;

#define ITEMS_PER_PAGE  100

    *numOfPosts = 0;
    cookie = (char *)malloc( MAX_COOKIE_LEN );
    if ( !cookie )
        return ( num );
    memset( cookie, 0x00, MAX_COOKIE_LEN );

    if ( password && *password ) {
        /* del.icio.us に login */
        if ( !loginDelicious( userName, password, cookie ) ) {
            // login 失敗
            free( cookie );
            return ( num );
        }
    }

    response = (char *)malloc( sz );
    if ( !response ) {
        free( cookie );
        return ( num );
    }
    response2 = (char *)malloc( sz );
    if ( !response2 ) {
        free( response );
        free( cookie );
        return ( num );
    }

    dateTime[0] = NUL;
    sprintf( url,
             "http://delicious.com/%s?detail=2&setcount=%d",
             userName, ITEMS_PER_PAGE );
    setTargetURL( url );
    setUpReceiveBuffer( response, sz );
    http_getEx( url, response, cookie );
    do {
        if ( !response || !(response[0]) )
            break;

        // ブックマークを抜き出す
        p = strstr( response, "id=\"bookmarklist\"" );
        if ( !p )
            break;
        p += 17;

        do {
            posts[num].href[0]        = NUL;
            posts[num].description[0] = NUL;
            posts[num].extended[0]    = NUL;
            posts[num].hash[0]        = NUL;
            posts[num].others         = 0;
            posts[num].tag[0]         = NUL;
            posts[num].dateTime[0]    = NUL;
            posts[num].shared         = TRUE;

            q = strstr( p, "<div class=\"data\">" );
            s = strstr( p, "<div class=\"clr\"></div>" );
            t = strstr( p, "<div class=\"dateGroup\">" );
            if ( !q || !s || (q > s) )
                break;

            if ( t && (t < q) ) {
                // dateTime
                t = strstr( t + 23, "<span title=\"" );
                if ( t ) {
                    int         yy = 0, mm = 9, dd = 0;
                    int         i;
                    static char monStr[12][4] = {
                        "Jan", "Feb", "Mar", "Apr", "May", "Jun",
                        "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
                    };

                    t += 13;
                    if ( *t == '0' )
                        t++;
                    dd = atol(t);

                    while ( ((*t < 'A') || (*t > 'Z')) && (t < q) )
                        t++;
                    for ( i = 0; i < 12; i++ ) {
                        if ( !strncmpi( t, monStr[i], 3 ) ) {
                            mm = i + 1;
                            break;
                        }
                    }

                    while ( ((*t <= '0') || (*t > '9')) && (t < q) )
                        t++;
                    yy = atol( t ) + 2000;

                    if ( (yy > 0) && (mm > 0) && (dd > 0) )
                        sprintf( dateTime, "%04d-%02d-%02dT00:00:00Z",
                                 yy, mm, dd );
                }
            }

            p = q + 18;
            q = strstr( p, "<a class=\"action " );
            t = strstr( p, "<h4" );
            if ( !q || (q > s) )
                break;

            if ( q && (q < t) ) {
                p = q + 17;
                if ( !strncmp( p, "private", 7 ) ) {
                    // shared
                    posts[num].shared = FALSE;
                }
            }

            // url
            q = strstr( p, "<h4" );
            if ( !q || (q > s) )
                break;
            p = strstr( q + 3, "<a " );
            if ( !p || (p > s) )
                break;
            q = strstr( p + 3, "href=\"" );
            if ( !q || (q > s) )
                break;
            p = q + 6;
            q = strchr( p, '"' );
            if ( !q || (q > s) )
                break;
            strncpy( posts[num].href, p, q - p );
            posts[num].href[q - p] = NUL;
            while ( ( r = strstr( posts[num].href, "&amp;" ) ) != NULL )
                strcpy( r + 1, r + 5 );

            // タイトル (description)
            p = q + 1;
            q = strchr( p, '>' );
            if ( !q || (q > s) )
                break;
            p = q + 1;
            q = strstr( p, "</a>" );
            if ( !q || (q > s) )
                break;
            strncpy( posts[num].description, p, q - p );
            posts[num].description[q - p] = NUL;
            r = utf2sjis( posts[num].description );
            if ( r )
                strcpy( posts[num].description, r );
            else
                utf2sjisEx( posts[num].description );
            /* del.icio.us のタイトルには改行が含まれ得る */
            while ( ((p = strchr(posts[num].description, '\r')) != NULL) ||
                    ((p = strchr(posts[num].description, '\n')) != NULL)    )
                strcpy( p, p + 1 ); /* 改行を取り除く */
            p = q + 4;

            // others
            t = strstr( p, "<span class=\"delNavCount\">" );
            if ( t && (t < s) ) {
                p = t + 26;
                q = strstr( p, "</span>" );
                if ( q && (q < s) ) {
                    posts[num].others = atol( p );
                    p = q + 7;
                }
            }

            // コメント (extended) [optional]
            q = strstr( p, "<div class=\"description\">" );
            if ( q && (q < s) ) {
                p = q + 25;
                while ( (*p == ' ')  || (*p == '\t') ||
                        (*p == '\r') || (*p == '\n')    )
                    p++;
                q = strstr( p, "</div>" );
                if ( q && (q < s) ) {
                    while ( (*(q - 1) == ' ')  || (*(q - 1) == '\t') ||
                            (*(q - 1) == '\r') || (*(q - 1) == '\n')    )
                        q--;
                    strncpy( posts[num].extended, p, q - p );
                    posts[num].extended[q - p] = NUL;
                    r = utf2sjis( posts[num].extended );
                    if ( r )
                        strcpy( posts[num].extended, r );
                    else
                        utf2sjisEx( posts[num].extended );
                    /* del.icio.us のタイトルには改行が含まれ得る */
                    while (((p = strchr(posts[num].extended,'\r')) != NULL)||
                           ((p = strchr(posts[num].extended,'\n')) != NULL)  )
                        strcpy( p, p + 1 ); /* 改行を取り除く */

                    p = q + 6;
                }
            }

            // hash
            q = strstr( p, "hash=" );
            if ( q && (q < s) ) {
                p = q + 5;
                q = strchr( p, '&' );
                if ( q && (q < s) ) {
                    strncpy( posts[num].hash, p, q - p );
                    posts[num].hash[q - p] = NUL;

                    p = q + 5;
                }
            }

            // タグ (tag)
            q = strstr( p, "<ul class=\"tag-chain\">" );
            if ( q && (q < s) ) {
                p = q + 22;
                q = strstr( p, "<a class=\"tag-chain-item-link" );
                r = strstr( p, "</ul>" );
                if ( q && r && (q < s) && (q < r) && (r < s) ) {
                    int len;

                    p = q + 29;
                    do {
                        q = strstr( p, "<span " );
                        if ( !q || (q > r) )
                            break;
                        p = q + 6;
                        q = strchr( p, '>' );
                        if ( !q || (q > r) )
                            break;
                        p = q + 1;
                        q = strstr( p, "</span>" );
                        if ( !q || (q > r) )
                            break;

                        if ( posts[num].tag[0] == NUL )
                            len = 0;
                        else {
                            strcat( posts[num].tag, " " );
                            len = strlen( posts[num].tag );
                        }
                        strncat( posts[num].tag, p, q - p );
                        posts[num].tag[len + (q - p)] = NUL;

                        p = q + 7;
                    } while ( p < r );
                    if ( posts[num].tag[0] ) {
                        r = utf2sjis( posts[num].tag );
                        if ( r )
                            strcpy( posts[num].tag, r );
                        else
                            utf2sjisEx( posts[num].tag );
                    }
                }
            }

            // 年月日 (dateTime)
            if ( dateTime[0] )
                strcpy( posts[num].dateTime, dateTime );

            p = s + strlen("<div class=\"clr\"></div>");

            num++;
            if ( num >= total )
                break;
        } while ( p && *p );

        // 次へ
        cont = FALSE;
        if ( num < total ) {
            if ( page * ITEMS_PER_PAGE >= total )
                break;
            q = strstr( p, "class=\"pn next\">Next" );
            if ( q ) {
                while ( p < q ) {
                    if ( *q == '<' )
                        break;
                    q--;
                }
                if ( *q == '<' ) {
                    p = strstr( q, "href=\"" );
                    if ( p ) {
                        p += 6;
                        q = strchr( p, '"' );
                        if ( q ) {
                            strcpy( url, "http://delicious.com" );
                            strncpy( url + 20, p, q - p );
                            (url + 20)[q - p] = NUL;

                            Sleep( 1000 );

                            setTargetURL( url );
                            setUpReceiveBuffer( response, sz );
                            http_getEx( url, response, cookie );
                            cont = TRUE;
                        }
                    }
                }
            }
        }
    } while ( cont );

    *numOfPosts = num;

    free( response2 );
    free( response );
    free( cookie );

    return ( num );
}
Example #24
0
/// Gets a property from this database.
static bool account_db_sql_get_property(AccountDB* self, const char* key, char* buf, size_t buflen)
{
	AccountDB_SQL* db = (AccountDB_SQL*)self;
	const char* signature;

	signature = "engine.";
	if( strncmpi(key, signature, strlen(signature)) == 0 )
	{
		key += strlen(signature);
		if( strcmpi(key, "name") == 0 )
			safesnprintf(buf, buflen, "sql");
		else
		if( strcmpi(key, "version") == 0 )
			safesnprintf(buf, buflen, "%d", ACCOUNT_SQL_DB_VERSION);
		else
		if( strcmpi(key, "comment") == 0 )
			safesnprintf(buf, buflen, "SQL Account Database");
		else
			return false;// not found
		return true;
	}

	signature = "sql.";
	if( strncmpi(key, signature, strlen(signature)) == 0 )
	{
		key += strlen(signature);
		if( strcmpi(key, "db_hostname") == 0 )
			safesnprintf(buf, buflen, "%s", db->global_db_hostname);
		else
		if( strcmpi(key, "db_port") == 0 )
			safesnprintf(buf, buflen, "%d", db->global_db_port);
		else
		if( strcmpi(key, "db_username") == 0 )
			safesnprintf(buf, buflen, "%s", db->global_db_username);
		else
		if( strcmpi(key, "db_password") == 0 )
			safesnprintf(buf, buflen, "%s", db->global_db_password);
		else
		if( strcmpi(key, "db_database") == 0 )
			safesnprintf(buf, buflen, "%s", db->global_db_database);
		else
		if( strcmpi(key, "codepage") == 0 )
			safesnprintf(buf, buflen, "%s", db->global_codepage);
		else
			return false;// not found
		return true;
	}

	signature = "account.sql.";
	if( strncmpi(key, signature, strlen(signature)) == 0 )
	{
		key += strlen(signature);
		if( strcmpi(key, "db_hostname") == 0 )
			safesnprintf(buf, buflen, "%s", db->db_hostname);
		else
		if( strcmpi(key, "db_port") == 0 )
			safesnprintf(buf, buflen, "%d", db->db_port);
		else
		if( strcmpi(key, "db_username") == 0 )
			safesnprintf(buf, buflen, "%s", db->db_username);
		else
		if( strcmpi(key, "db_password") == 0 )
			safesnprintf(buf, buflen, "%s", db->db_password);
		else
		if( strcmpi(key, "db_database") == 0 )
			safesnprintf(buf, buflen, "%s", db->db_database);
		else
		if( strcmpi(key, "codepage") == 0 )
			safesnprintf(buf, buflen, "%s", db->codepage);
		else
		if( strcmpi(key, "case_sensitive") == 0 )
			safesnprintf(buf, buflen, "%d", (db->case_sensitive ? 1 : 0));
		else
		if( strcmpi(key, "account_db") == 0 )
			safesnprintf(buf, buflen, "%s", db->account_db);
		else
		if( strcmpi(key, "global_acc_reg_str_db") == 0 )
			safesnprintf(buf, buflen, "%s", db->global_acc_reg_str_db);
		else
		if( strcmpi(key, "global_acc_reg_num_db") == 0 )
			safesnprintf(buf, buflen, "%s", db->global_acc_reg_num_db);
		else
			return false;// not found
		return true;
	}

	return false;// not found
}
void DisplayContestContact::checkContact( )
{
   // check on country and district. If valid, return true,
   // having mapped any synonyms to their parents and
   // saved the pointers.

   int checkret = 0;
   double dist = 0.0;
   BaseContestLog * clp = contest;

   if ( contactFlags.getValue() & ( LOCAL_COMMENT | COMMENT_ONLY ) )
      return ;
   if ( contactFlags.getValue() & NON_SCORING )
      return ;

   QSOValid = false;             // initially, anyway
   int csret = cs.validate( );
#warning scanContest may already have set ERR_DUPCS
   if ( csret != CS_OK && csret != ERR_DUPCS )
      checkret = ERR_13;

   int index;
   if ( !checkret )
   {
// and if scanContest has set dup, then this won't fire tering a new QSO
// But it DOES fire when checking on en
      BaseContact * valp = 0;
      valp = clp->validationPoint;
      if ( clp->DupSheet.checkCurDup( this, valp, false ) )
      {
         cs.valRes = ERR_DUPCS;
         checkret = ERR_12;
      }
   }

   // search for prefix in country synonym list. Have to allow for e.g. HB0 as a mult

   if ( contactFlags.getValue() & COUNTRY_FORCED )
   {
      ctryMult = MultLists::getMultLists() ->getCtryForPrefix( forcedMult.getValue() );
   }
   else
      if ( !checkret )
      {
         ctryMult = findCtryPrefix( cs );
      }

   //   extraText = trimr( extraText );   // needs to be done already

   unsigned short cf = contactFlags.getValue();
   cf &= ~UNKNOWN_COUNTRY;
   if ( !checkret && ( clp->countryMult.getValue() || clp->districtMult.getValue() ) && !ctryMult )    // need at least a valid country
   {
      cf |= UNKNOWN_COUNTRY;
   }
   contactFlags.setValue( cf );
   if ( clp->districtMult.getValue() && ctryMult )
   {
      // if CC_mult and country "has districts" search for the "extra" in the county synonym list

      // check that the district and country agree

      // if the correct parts don't exist, not a valid contact!
      // NB that the rest of the contact has to be valid as well!

      if ( ctryMult->hasDistricts() )    // continentals dont have counties
      {
         districtMult = MultLists::getMultLists() ->searchDistrict( extraText.getValue() );
         if ( !districtMult && !( cf & VALID_DISTRICT ) )
         {
            checkret = ERR_8;
         }

         if (
            !checkret &&       						// no errors
            !( cf & VALID_DISTRICT ) &&      // ? district forced OK
            districtMult &&
            ( districtMult->country1 != ctryMult ) &&     // check district in country
            ( districtMult->country2 != ctryMult )
         )
         {
            checkret = ERR_8;
         }
      }
      // so all seems OK, or checkret is set to the first error
   }
   else
      if ( !checkret )
      {
         districtMult = 0;						// just in case we have changed the type...
         if ( clp->otherExchange.getValue() )
         {
            if ( clp->districtMult.getValue() )
            {
               if ( !trim( comments.getValue() ).size() )
                  checkret = ERR_21;
            }
            else
               if ( !trim( extraText.getValue() ).size() )
                  checkret = ERR_21;
         }
      }

   // calc the bearing and score anyway; otherwise dups get a bearing of -1

   if ( bearing < 0 )
   {
      double lon = 0.0;
      double lat = 0.0;
      int brg;

      if ( lonlat( loc.loc.getValue(), lon, lat ) == LOC_OK )
      {
         clp->disbear( lon, lat, dist, brg );
         bearing = brg;
      }
   }

   if ( checkret )
      return ;

   QSOValid = true;        // for now

   // same as ScreenContact::Check up to here

   if ( districtMult )
   {
      if ( districtMult->country1 &&
           ( ( clp->districtWorked[ districtMult->listOffset ] ) ++ < districtMult->country1->districtLimit() ) )
      {
         clp->ndistrict++;
         if ( clp->districtMult.getValue() )
         {
            multCount++;
         }
         newDistrict = true;
      }
   }

   if ( ctryMult )
   {
      if ( ( clp->countryWorked[ ctryMult->listOffset ] ) ++ == 0 )
      {
         if (!clp->nonGCountryMult.getValue() || !cs.isUK())
         {
            clp->nctry++;
            if ( clp->countryMult.getValue() )
            {
               {
                  multCount++;
               }
            }
            newCtry = true;
         }
      }
   }
   clp->DupSheet.checkCurDup( this, 0, true ); // add to duplicates list

   if ( !( contactFlags.getValue() & ( MANUAL_SCORE | NON_SCORING | LOCAL_COMMENT | COMMENT_ONLY | DONT_PRINT ) ) )
   {
      if ( loc.loc.getValue().size() == 4 && clp->allowLoc4.getValue() )
      {
         dist = clp->CalcNearest( loc.loc.getValue() ); // deal with 4 char locs
      }
      contactScore.setValue( dist );
   }

   if ( !clp->locatorField.getValue() || contactScore.getValue() >= 0 )   		// don't add -1 scores in, but DO add zero km
      // as it is 1 point.
   {
      int cscore = contactScore.getValue();
      switch ( clp->scoreMode.getValue() )
      {
         case PPKM:
            {
               if ( contactFlags.getValue() & XBAND )
               {
                  cscore = ( cscore + 1 ) / 2;
               }
               clp->contestScore += cscore;
            }
            break;

         case PPQSO:
            if ( cscore > 0 )
               clp->contestScore++;
            break;

      }
   }

   {
      // now look at the locator list
      TEMPBUFF( letters, 3 );
      TEMPBUFF( numbers, 3 );

      std::string sloc = loc.loc.getValue();
      letters[ 0 ] = sloc[ 0 ];
      letters[ 1 ] = sloc[ 1 ];
      letters[ 2 ] = 0;

      numbers[ 0 ] = sloc[ 2 ];
      numbers[ 1 ] = sloc[ 3 ];
      numbers[ 2 ] = 0;

      int lsi;

      LocSquare *ls = 0;

      for ( LocSquareIterator i = clp->locs.llist.begin(); i != clp->locs.llist.end(); i++ )
      {
         if ( strncmpi( ( *i ) ->loc, letters, 2 ) == 0 )
         {
            ls = ( *i );
            break;
         }
      }

      if ( !ls )
      {
         if ( isalpha( letters[ 0 ] ) && isalpha( letters[ 1 ] ) )
         {
            ls = new LocSquare( letters );
            clp->locs.llist.insert( ls );
         }
      }

      if ( ls )
      {
         LocCount * npt = ls->map( numbers );
         if ( npt )
         {
            if ( QSOValid )
            {
               if (!clp->GLocMult.getValue() || cs.isUK())
               {
                  if ( ( npt->valid ) ++ == 0 )
                  {
                     clp->nlocs++;
                     if ( clp->locMult.getValue() )
                     {
                        multCount++;
                     }
                     newLoc = true;
                  }
               }
               else
               {
                  ( npt->invalid ) ++ ;
               }
            }
         }
      }
   }
}
/*****
* This routine scans the editor command entered or loaded
* and composes a string used composing the WinExec command line.
*
* The user can enter a editor command of the form:
* <editor> @FILE <options> @LINE
* where @FILE is the name of the file to edit, and
* @LINE is the linenumber where the editor should start.
*
* This routine sets a global variable editor_order which can have the
* following values (where %s indicates FILE and %i indicates LINE):
*
* Value		Command			has_file_cmd	has_line_cmd
* ------------------------------------------------------------------
* 1		<editor> %s		1 or 0		0
* 2		<editor> %s %i		1		2
* 3		<editor> %i %s		2 or 0		1
*****/
static void
parse_editor_command(char *string)
{
	char *outPtr = string;
	short has_file_cmd = 0;
	short has_line_cmd = 0;
	short i;
	char szBuf[MAXPATHLEN];

	/* clear buffer */
	memset(szBuf, '\0', MAXPATHLEN);

	for(i = 0, outPtr; *outPtr != '\0'; outPtr++, i++)
	{
		switch(*outPtr)
		{
			case '@':
				outPtr++;
				if(!strncmpi(outPtr, "file", 4))
				{
					/* outPtr also gets incremented above */
				   	outPtr += 3;
					if(!has_line_cmd)
						has_file_cmd = 1;
					else
						has_file_cmd = 2;
					strcat(szBuf, "%s");
					i += 1;	
				}
				else
				{
					if(!strncmpi(outPtr, "line", 4))
					{
						outPtr += 3;
						if(!has_file_cmd)
							has_line_cmd = 1;
						else
							has_line_cmd = 2;
						strcat(szBuf, "%i");
						i+=1;
					}
					else
					{
						ErrHandler(NULL, R_MESSAGE, 
							RB_OK1, "Unknown editor"
							" variable %s detected,"
							" ignoring\n", outPtr);
						for(; *outPtr != '\0' && 
							*outPtr != ' '; 
							outPtr++, i++);
					}
				}
				break;
			default:
				szBuf[i] = *outPtr;
		}
	}
	szBuf[i] = '\0';
	/* file = 0, line = 0, see table above */
	if(!has_file_cmd && !has_line_cmd)
	{
		has_file_cmd = 1;	/* file comes first */
		strcat(szBuf, " %s");
	}
	/* file = 0, line = 1, see table above */
	if(!has_file_cmd && has_line_cmd)
	{
		editor_order = 3;	/* file comes last */
		strcat(szBuf, " %s");
		has_file_cmd = 2;
	}

	if(has_file_cmd == 1 && has_line_cmd == 2)
		editor_order = 2;
	if(has_file_cmd == 2 && has_line_cmd == 1)
		editor_order = 3;
	if(has_file_cmd == 1 && has_line_cmd == 0)
		editor_order = 1;

	strncpy(default_editor, szBuf, strlen(szBuf));
	default_editor[strlen(szBuf)] = '\0';
}
Example #27
0
int ftpsession(struct Url *url,struct HTTPrecord *cache,char *uploadfile)
{
 longword host;
 char str[256];
 char buffer[BUFLEN+2];
 tcp_Socket datasocket;
 word dataport=0;
 int rv=0,len;
 char *ptr,*datahostptr,datahost[80];
 char isdir=0,retry=0;//,ascii=0;
 long total=0;

//!!glennmcc: Nov 11, 2007 -- for 'dblp code' below
 int dblp=0;
//!!glennmcc: end

//!!glennmcc: Nov 13, 2007 -- for EZNOS2 fix below
int eznos2=0;
//!!glennmcc: end
int log;

 if(!tcpip)return 0;
 free_socket();

 if((!url->file[0] || url->file[strlen(url->file)-1]=='/') && !uploadfile)
  isdir=1;

 sprintf(str,msg_askdns,url->host);
 outs(str);

 GlobalLogoStyle=0;			//SDL set resolve animation
 host=resolve_fn( url->host, (sockfunct_t) TcpIdleFunc ); //SDL
// host=resolve( url->host );
 if(!host)
 {
  DNSerr(url->host);
  return 0;
 }

// if(!uploadfile) //!glennmcc: Oct 20, 2012 - commented-out to make upload log more verbose
   log=a_open("FTP.LOG",O_BINARY|O_WRONLY|O_CREAT|O_TRUNC,S_IREAD|S_IWRITE);

 GlobalLogoStyle=2;			//SDL set connect animation
 if (!tcp_open( socket, locport(), host, url->port, NULL ))
 {
  sprintf(str,msg_errcon,url->host);
  outs(str);
  return 0;
 }
 sprintf(str,msg_con,url->host,url->port);
 outs(str);
 write(log,str,strlen(str));
 write(log,"\r\n",2);
 sock_wait_established(socket, sock_delay, (sockfunct_t) TcpIdleFunc,
		       &status);		//SDL

 GlobalLogoStyle=1;		//SDL set data animation
 sock_mode( socket, TCP_MODE_ASCII );
 outs(MSG_LOGIN);

 do
 {
  sock_wait_input( socket, sock_delay, (sockfunct_t) TcpIdleFunc,
		   &status );		//SDL
  sock_gets( socket, (unsigned char *)buffer, sizeof( buffer ));
  outs(buffer);
  write(log,buffer,strlen(buffer));
  write(log,"\r\n",2);


//  printf("FTP daemon said>");
//  puts(buffer);
  if ( *buffer != '2' && buffer[0]!=' ') goto quit;
 }
 while(buffer[3]=='-' || buffer[0]==' '); //continued message!

 if(!url->user[0])
  ptr="anonymous";
 else
  ptr=url->user;

 sprintf( str, "USER %s", ptr);
 write(log,str,strlen(str));
 write(log,"\r\n",2);
 sock_puts(socket,(unsigned char *)str);
 sock_wait_input( socket, sock_delay, (sockfunct_t) TcpIdleFunc,
		  &status );		//SDL
 sock_gets( socket, (unsigned char *)buffer, sizeof( buffer ));
 outs(buffer);
 write(log,buffer,strlen(buffer));
 write(log,"\r\n",2);

//  printf("FTP daemon said>");
//  puts(buffer);

//!!glennmcc: May 11, 2005
//removed due to the fact that not all sites use '3'
//see additional info below with respect to anonymous password
// if ( *buffer != '3' ) goto quit;
//!!glennmcc: end

 //open cache filename:

//!glennmcc: Oct 20, 2012 - commented-out to make upload log more verbose
// if(uploadfile)
//  strcpy(cache->locname,"FTP.LOG");
// else
//!glennmcc end: Oct 20, 2012

 {
//!!glennmcc: Oct 22, 2008 -- strchr() was preventing the use of 'CachePath .\cache\'
//  ptr=strchr(cache->locname,'.');
  ptr=strrchr(cache->locname,'.');
//!!glennmcc: end
  if(ptr)
  {
   strcpy(&ptr[1],"FTP");
   strcpy(cache->rawname,cache->locname);
  }
 }

 cache->handle=a_open(cache->locname,O_BINARY|O_WRONLY|O_CREAT|O_TRUNC,S_IREAD|S_IWRITE);
 if(cache->handle<0)
  goto quit;

 strcpy(cache->mime,"text/plain");

 if(url->password[0])
  ptr=url->password;
 else
 {
  if(url->user[0] && !strcmp(url->host,AUTHENTICATION->host)
		  && !strcmp(AUTHENTICATION->realm,"$ftp"))
   ptr=AUTHENTICATION->password;
  else
  {
   ptr=configvariable(&ARACHNEcfg,"FakeFTPeMail",NULL);
   if(!ptr || !strchr(ptr,'@'))
   {
    ptr=configvariable(&ARACHNEcfg,"eMail",NULL);
    if(!ptr)
     ptr="@";
   }
  }
 }

//!!glennmcc: May 11, 2005
//some sites do not require a password after 'anonymous'
//therefer, this entire block is now within this 'if()' so that
//the password (email address), will only be sent if asked for
//!!glennmcc: Nov 13, 2007 -- EZNOS2 says "Enter PASS command"
if (strstr(buffer,"sword") || strstr(buffer,"Enter PASS command"))
//if (strstr(buffer,"sword"))//original line
{
 sprintf( str, "PASS %s", ptr);
 sock_puts(socket,(unsigned char *)str);
 write(log,str,strlen(str));
 write(log,"\r\n",2);
}//!!glennmcc: inserted Mar 02, 2008
//Some servers need the following 'do/while' section,
//therefore, only the section above for sending the password needs to be
//'blocked' when no password was requested.

 do
 {
  sock_wait_input( socket, sock_delay, (sockfunct_t) TcpIdleFunc,
		   &status );		//SDL
  sock_gets( socket, (unsigned char *)buffer, sizeof( buffer ));
  outs(buffer);
  write(log,buffer,strlen(buffer));
  write(log,"\r\n",2);
//  printf("FTP daemon said>");
//  puts(buffer);
if (strstr(buffer,"Enter PASS command")) eznos2=1;

  if (*buffer != '2' && buffer[0]!=' ' && !eznos2)
  {
   write(cache->handle,buffer,strlen(buffer));
   rv=1;
   goto quit;
  }
  else if ((buffer[3]=='-' || buffer[0]==' ') && (isdir || uploadfile))
  {
   strcat(buffer,"\r\n");
   rv=1;
   write(cache->handle,buffer,strlen(buffer));
  }
 }
 while(buffer[3]=='-' || buffer[0]==' ' || buffer[0]=='3'); //continued message!
//}//!!glennmcc: end May 11, 2005 -- removed on Mar 02, 2008

 //ask server where we have to connect:

 sock_puts(socket,(unsigned char *)"PASV");
 sock_wait_input( socket, sock_delay, (sockfunct_t) TcpIdleFunc,
		  &status );		//SDL
 sock_gets( socket, (unsigned char *)buffer, sizeof( buffer ));
 outs(buffer);
 write(log,buffer,strlen(buffer));
 write(log,"\r\n",2);



//  printf("FTP daemon said>");
//  puts(buffer);

 //2xx Entering passive mode (a,b,c,d,x,y)

 if ( *buffer != '2' ) goto quit;
 datahostptr=strchr(buffer,'(');
//!!glennmcc: Nov 13, 2007 -- EZNOS2 doesn't enclose the info in ()
//therefore, if '(' is not found... look for the last 'space'.
 if(!datahostptr) {datahostptr=strrchr(buffer,' '); eznos2=1;}
//if that still fails... 'quit'
//!!glennmcc: end
 if(!datahostptr) goto quit;//original line

 ptr=++datahostptr;
 {
  int carka=0;
  char *portptr=NULL;

  while(*ptr)
  {
   if(*ptr==',')
   {
    carka++;
    if(carka<4)
     *ptr='.';
    else if(carka==4)
    {
     *ptr='\0';
     portptr=ptr+1;
    }
    else if (carka==5)
    {
     *ptr='\0';
     dataport=256*(word)atoi(portptr);  // ,x,y -> 256*x+y
     portptr=ptr+1;
//!!glennmcc: Nov 13, 2007 -- part of above fix for EZNO2 info not in ()
 if(eznos2) dataport+=atoi(portptr);      // ,x,y -> 256*x+y
//!!glennmcc: end
    }
   }
   else if(*ptr==')' && portptr)
   {
//!!glennmcc: Nov 11, 2007 -- some servers have double ')'
// at the end of the port address info...
// this 'dblp code' will prevent that from adding the final set twice
//eg: (99,167,219,186,234,255)) instead of.... (99,167,219,186,234,255)
//without this fix ... 255 gets added a 2nd time and
//we end-up-with... port 60414 instead of the correct port of 60159
    *ptr='\0';
    if(!dblp)//!!glennmcc: Nov 11, 2007
    dataport+=atoi(portptr);      // ,x,y -> 256*x+y
    dblp=1;//!!glennmcc: Nov 11, 2007
   }
   ptr++;
  }
 }

 if(!dataport)
  goto quit;

//!!glennmcc: Aug 31, 2009
//EZNOS2 sends the IP of the machine on a router as datahost
//therefore we need to go back to the original host
if(eznos2)
{
makestr(datahost,url->host,79);
outs(datahost);
Piip();
}
else
//!!glennmcc:end

 makestr(datahost,datahostptr,79);//original line

 retry:

 if(isdir)
 {
  if(url->file[0])
  {
//!!glennmcc: Oct 15, 2007 -- fix problems with CWD on FTP servers
//which interpret the leading '/' as an attempted CD to 'root'
   if(url->file[0]=='/')
   sprintf( str, "CWD %s", url->file+1);
   else
//!!glennmcc: end Oct 15, 2007
   sprintf( str, "CWD %s", url->file);
   sock_puts(socket,(unsigned char *)str);
   do
   {
    sock_wait_input( socket, sock_delay, (sockfunct_t) TcpIdleFunc,
		     &status );		//SDL
    sock_gets( socket, (unsigned char *)buffer, sizeof( buffer ));
    outs(buffer);

//!!glennmcc: Apr 08, 2005 -- commented-out this block
// to fix the problem of 'broken dir listing' when the
// 'FTP welcome message' contains linefeeds
// such as at ftp://ftp.cdrom.com/.2/simtelnet/
/*
    if ( *buffer != '2' && buffer[0]!=' ')
    {
     write(cache->handle,buffer,strlen(buffer));
     rv=1;
     goto quit;
    }
    else if (buffer[3]=='-' || buffer[0]==' ')
*/
//!!glennmcc: end
    {
     strcat(buffer,"\r\n");
     rv=1;
     write(cache->handle,buffer,strlen(buffer));
    }
   }
//!!glennmcc: Apr 08, 2005 -- added a test for !=' ' which is also
// needed for the same fix at ftp://ftp.cdrom.com/.2/simtelnet/
   while(buffer[3]=='-' || buffer[3]!=' ' || buffer[0]==' '); //continued message!
//   while(buffer[3]=='-' || buffer[0]==' '); //continued message!
//!!glennmcc: end

  }
  strcpy(cache->mime,"ftp/list");
  sprintf( str, "LIST");
 }
 else
 {
  char *fnameptr;
  char mimestr[80]="ftp/binary";

  fnameptr=strrchr(url->file,'/');
  if(!fnameptr)
  {
   fnameptr=strrchr(url->file,'\\');
   if(!fnameptr)
    fnameptr=url->file;
   else
    fnameptr++;
   }
   else
    fnameptr++;

  sprintf( str, "TYPE I");
  if(fnameptr)
  {
   char ext[5];
   strcpy(mimestr,"file/");
   strncat(mimestr,fnameptr,70);
   mimestr[79]='\0';
   get_extension(mimestr,ext);
   if(!strncmpi(ext,"TXT",3) || !strncmpi(ext,"HTM",3))
   {
//!!glennmcc: begin June 09, 2002
//optionally upload TXT and HTM in binary mode
    ptr=configvariable(&ARACHNEcfg,"UseBinaryFTP",NULL);
    if(!ptr || toupper(*ptr)=='N')
//!!glennmcc: end
    sprintf( str, "TYPE A");
//    ascii=1;
   }
  }
  strcpy(cache->mime,mimestr);

  sock_puts(socket,(unsigned char *)str);
  write(log,str,strlen(str));
  write(log,"\r\n",2);
  sock_wait_input( socket, sock_delay, (sockfunct_t) TcpIdleFunc,
		  &status );		//SDL
  sock_gets( socket, (unsigned char *)buffer, sizeof( buffer ));
  outs(buffer);
  write(log,buffer,strlen(buffer));
  write(log,"\r\n",2);
//  printf("FTP daemon said>");
//  puts(buffer);
  if ( *buffer != '2' || uploadfile)
  {
   strcat(buffer,"\n");
   write(cache->handle,buffer,strlen(buffer));
  }
  if ( *buffer != '2' )
  {
   rv=1;
   goto quit;
  }
  if(!uploadfile)

//!!glennmcc: Oct 17, 2007 -- fix problems with FTP servers
//which interpret the leading '/' as an attempted CD to 'root'
   if(url->file[0]=='/')
   sprintf( str, "RETR %s", url->file+1);
   else
   sprintf( str, "RETR %s", url->file);
//original single line above this comment
//!!glennmcc: end
  else
   sprintf( str, "STOR %s", url->file);
 }
 sock_puts(socket,(unsigned char *)str);
 write(log,str,strlen(str));
 write(log,"\r\n",2);

//!!glennmcc: Oct 19, 2008 -- back to original fix
//!!glennmcc: Nov 15, 2007 -- always 'close' the connection when done
//with both dir listings and file downloads
//Apr 10, 2007 fix did it only for dir listings
if(isdir || strstr(str,"RETR"))
//if(isdir)
 sock_puts(socket,(unsigned char *)"QUIT");//!!glennmcc: Apr 10, 2007
//!!glennmcc: end

 if(!retry)
 {
  //get file using datahost & dataport
  GlobalLogoStyle=0;		//SDL set resolve animation
  host=resolve_fn( datahost, (sockfunct_t) TcpIdleFunc );	//SDL
//  host=resolve( datahost );
  if(!host)
   goto quit;

  GlobalLogoStyle=2;		//SDL set connect animation
  if (!tcp_open( &datasocket, locport(), host, dataport, NULL ))
  {
   sprintf(str,msg_errcon,datahost);
   outs(str);
   goto quit;
  }
  sprintf(str,msg_con,datahost,dataport);
  outs(str);
  write(log,str,strlen(str));
  write(log,"\r\n",2);

  //wait for datasocket to open:
  sock_wait_established(&datasocket, sock_delay, (sockfunct_t) TcpIdleFunc,
			&status);	//SDL

//!!glennmcc: Sep 27, 2008 -- increase D/L speed on cable & DSL
//many thanks to 'mik' for pointing me in the right direction. :)
{
#ifdef DEBUG
 char sp[80];
 sprintf(sp,"Available stack = %u bytes",_SP);
 outs(sp);
 Piip(); Piip();
#endif
 if(_SP>(1024*SETBUFSIZE))
 {
  char setbuf[1024*SETBUFSIZE];
  sock_setbuf(&datasocket, (unsigned char *)setbuf, 1024*SETBUFSIZE);
 }
}
//!!glennmcc: end

  GlobalLogoStyle=1;		//SDL set data animation
 }
 //wait for "110 openning connection" (or "550 ....error....")
 sock_wait_input( socket, sock_delay, (sockfunct_t) TcpIdleFunc,
		  &status );		//SDL

 sock_gets( socket, (unsigned char *)buffer, sizeof( buffer ));
 outs(buffer);
 write(log,buffer,strlen(buffer));
 write(log,"\r\n",2);


// printf("FTP daemon said>");
// puts(buffer);
 if ( *buffer != '1' || uploadfile)
 {
  strcat(buffer,"\n");
  write(cache->handle,buffer,strlen(buffer));
 }

 if ( *buffer != '1' )
 {
  if(!strncmp(buffer,"550",3) && !retry)
  {
   retry=1;
   isdir=1-isdir;
   if(isdir)
    strcat(url->file,"/");
   else
   {
    int i=strlen(url->file);
    if(i>0 && url->file[i-1]=='/')
     url->file[i-1]='\0';
   }
   goto retry;
  }

  strcpy(cache->mime,"text/plain");
  rv=1;
  goto dataquit;
 }

 if(!uploadfile) //-------------------------------------- download ---------------
 {
  while ( 1 )
  {
   xChLogoTICK(1);
   if(GUITICK())
    if(GLOBAL.gotolocation || GLOBAL.abort)
     goto dataquit;

   if (sock_dataready( &datasocket ))
   {
    len = sock_fastread( &datasocket, (unsigned char*)buffer, BUFLEN );
    write(cache->handle,buffer,len);
    total+=len;
    sprintf(str,MSG_BYTESR,MSG_DOWNLD,total);
    outs(str);
   }
   else
    sock_tick( &datasocket, &status ); //shift TCP/IP
  }
 }
 else //-------------------------------------- upload ------------------
 {
  int f,lenread,done;
  long length;
  char pom[256];

/*  if(ascii)
   f=a_sopen(uploadfile,O_RDONLY|O_TEXT, SH_DENYNO, S_IREAD);
  else*/
   f=a_sopen(uploadfile,O_RDONLY|O_BINARY, SH_DENYNO, S_IREAD);

  if(f<0)
   goto dataquit;

  lenread=done=0;
  length=0l;

  {
   long filel=a_filelength(f);
   while(1)
   {
    sprintf(pom,MSG_UPLOAD,length,filel);
    outs(pom);
//!!glennmcc:Oct 23, 2008 -- 'reversed the logic'
// to keep from overflowing at 21megs
    if(filel>100)
    percentbar((int)(length/(filel/100)));
//  percentbar((int)(100*length/filel));
    lenread=a_read(f,buffer,BUFLEN);
    length+=lenread;
    if(lenread<=0)
     done=1;

    //wait until we can write to socket:
    while(sock_tbleft(&datasocket)<lenread) //SDL
//    while( datasocket.datalen > 1024)
    {
     sock_tick(&datasocket,&status);
     xChLogoTICK(1); // animation of logo
     if(GUITICK())
      goto dataquit;
    }

    if(done)
    {
     sock_close( &datasocket );
     a_close(f);
     goto dataclose;
    }

    sock_fastwrite(&datasocket,(unsigned char *)buffer,lenread);
    sock_tick(&datasocket,&status);
   }//loop
  }
 }


dataquit:
//!!glennmcc: Nov 15,  2007 -- removed sock_abort because it was
// sometimes preventing the connection from being closed,
// therefore preventing access to several files within a short time
// due to too many connections open from the same IP
// sock_abort( &datasocket );//original line
//!!glennmcc: end

dataclose:
 outs(MSG_CLOSE);

 sock_puts(socket,(unsigned char *)"QUIT");//!!glennmcc: Dec 04, 2006
 sock_wait_closed( &datasocket, sock_delay, (sockfunct_t) TcpIdleFunc,
		   &status );		//SDL

 if(uploadfile)
 {
  sock_wait_input( socket, sock_delay, (sockfunct_t) TcpIdleFunc,
		   &status );		//SDL
  sock_gets( socket, (unsigned char *)buffer, sizeof( buffer ));
  outs(buffer);
 }

quit:
  sock_puts(socket,(unsigned char *)"QUIT");
  sock_close( socket );
  closing[socknum]=1;
  sock_keepalive[socknum][0]='\0';
//    sock_wait_closed( socket, sock_delay, NULL, &status );

//we will better wait because we are about to deallocate datasocket

sock_err:
    switch (status) {
	case 1 : /* foreign host closed */
		 write(log,MSG_CLOSE,strlen(MSG_CLOSE));
		 write(log,"\r\n",2);
		 close(log);
		 break;
	case -1: /* timeout */
		 sprintf(str,MSG_TCPERR, sockerr(socket));
		 outs(str);
		 write(log,str,strlen(str));
		 write(log,"\r\n",2);
		 close(log);
		 break;
    }

 if(total)
 {
  cache->knowsize=1;
  cache->size=total;
  rv=1;
 }
 if(cache->handle>=0)
 {
  a_close(cache->handle);
  rv=1;
 }

 return rv;
}
Example #28
0
// load configuration options
bool ipban_config_read(const char* key, const char* value)
{
	const char* signature;

	if( ipban_inited )
		return false;// settings can only be changed before init

	signature = "sql.";
	if( strncmpi(key, signature, strlen(signature)) == 0 )
	{
		key += strlen(signature);
		if( strcmpi(key, "db_hostname") == 0 )
			safestrncpy(global_db_hostname, value, sizeof(global_db_hostname));
		else
		if( strcmpi(key, "db_port") == 0 )
			global_db_port = (uint16)strtoul(value, NULL, 10);
		else
		if( strcmpi(key, "db_username") == 0 )
			safestrncpy(global_db_username, value, sizeof(global_db_username));
		else
		if( strcmpi(key, "db_password") == 0 )
			safestrncpy(global_db_password, value, sizeof(global_db_password));
		else
		if( strcmpi(key, "db_database") == 0 )
			safestrncpy(global_db_database, value, sizeof(global_db_database));
		else
		if( strcmpi(key, "codepage") == 0 )
			safestrncpy(global_codepage, value, sizeof(global_codepage));
		else
			return false;// not found
		return true;
	}

	signature = "ipban.sql.";
	if( strncmpi(key, signature, strlen(signature)) == 0 )
	{
		key += strlen(signature);
		if( strcmpi(key, "db_hostname") == 0 )
			safestrncpy(ipban_db_hostname, value, sizeof(ipban_db_hostname));
		else
		if( strcmpi(key, "db_port") == 0 )
			ipban_db_port = (uint16)strtoul(value, NULL, 10);
		else
		if( strcmpi(key, "db_username") == 0 )
			safestrncpy(ipban_db_username, value, sizeof(ipban_db_username));
		else
		if( strcmpi(key, "db_password") == 0 )
			safestrncpy(ipban_db_password, value, sizeof(ipban_db_password));
		else
		if( strcmpi(key, "db_database") == 0 )
			safestrncpy(ipban_db_database, value, sizeof(ipban_db_database));
		else
		if( strcmpi(key, "codepage") == 0 )
			safestrncpy(ipban_codepage, value, sizeof(ipban_codepage));
		else
		if( strcmpi(key, "ipban_table") == 0 )
			safestrncpy(ipban_table, value, sizeof(ipban_table));
		else
			return false;// not found
		return true;
	}

	signature = "ipban.";
	if( strncmpi(key, signature, strlen(signature)) == 0 )
	{
		key += strlen(signature);
		if( strcmpi(key, "enable") == 0 )
			login_config.ipban = (bool)config_switch(value);
		else
		if( strcmpi(key, "dynamic_pass_failure_ban") == 0 )
			login_config.dynamic_pass_failure_ban = (bool)config_switch(value);
		else
		if( strcmpi(key, "dynamic_pass_failure_ban_interval") == 0 )
			login_config.dynamic_pass_failure_ban_interval = atoi(value);
		else
		if( strcmpi(key, "dynamic_pass_failure_ban_limit") == 0 )
			login_config.dynamic_pass_failure_ban_limit = atoi(value);
		else
		if( strcmpi(key, "dynamic_pass_failure_ban_duration") == 0 )
			login_config.dynamic_pass_failure_ban_duration = atoi(value);
		else
			return false;// not found
		return true;
	}

	return false;// not found
}
Example #29
0
File: STR.C Project: ifilex/SRC
int strcmpi(char *str1,char *str2)
{
 return strncmpi(str1,str2,-1);
}
Example #30
0
int
name_to_mon(const char *in_str)
{
    /* Be careful.  We must check the entire string in case it was something
       such as "ettin zombie corpse".  The calling routine doesn't know about
       the "corpse" until the monster name has already been taken off the
       front, so we have to be able to read the name with extraneous stuff such 
       as "corpse" stuck on the end. This causes a problem for names which
       prefix other names such as "ettin" on "ettin zombie".  In this case we
       want the _longest_ name which exists. This also permits plurals created
       by adding suffixes such as 's' or 'es'.  Other plurals must still be
       handled explicitly. */
    int i;
    int mntmp = NON_PM;
    char *s, *str, *term;
    /* Note: these bounds assume that we never lengthen str. */
    char mutable_in_str[strlen(in_str) + 1];
    int len, slen;

    /* special case: debug-mode players can create monsters by number; this is
       intended for programmatic monster creation */
    if (wizard && sscanf(in_str, "monsndx #%d", &mntmp) == 1 &&
        mntmp >= LOW_PM && mntmp < SPECIAL_PM)
        return mntmp;

    str = strcpy(mutable_in_str, in_str);

    if (!strncmp(str, "a ", 2))
        str += 2;
    else if (!strncmp(str, "an ", 3))
        str += 3;

    slen = strlen(str);
    term = str + slen;

    if ((s = strstri_mutable(str, "vortices")) != 0)
        strcpy(s + 4, "ex");
    /* be careful with "ies"; "priest", "zombies" */
    else if (slen > 3 && !strcmpi(term - 3, "ies") &&
             (slen < 7 || strcmpi(term - 7, "zombies")))
        strcpy(term - 3, "y");
    /* luckily no monster names end in fe or ve with ves plurals */
    else if (slen > 3 && !strcmpi(term - 3, "ves"))
        strcpy(term - 3, "f");

    slen = strlen(str); /* length possibly needs recomputing */

    {
        static const struct alt_spl {
            const char *name;
            short pm_val;
        } names[] = {
            /* Alternate spellings */
            { "grey dragon", PM_GRAY_DRAGON },
            { "baby grey dragon", PM_BABY_GRAY_DRAGON },
            { "grey unicorn", PM_GRAY_UNICORN },
            { "grey ooze", PM_GRAY_OOZE },
            { "gray-elf", PM_GREY_ELF },
            { "mindflayer", PM_MIND_FLAYER },
            { "master mindflayer", PM_MASTER_MIND_FLAYER },
            /* Hyphenated names */
            { "ki rin", PM_KI_RIN },
            { "uruk hai", PM_URUK_HAI },
            { "orc captain", PM_ORC_CAPTAIN },
            { "woodland elf", PM_WOODLAND_ELF },
            { "green elf", PM_GREEN_ELF },
            { "grey elf", PM_GREY_ELF },
            { "gray elf", PM_GREY_ELF },
            { "elf lord", PM_ELF_LORD },
            { "olog hai", PM_OLOG_HAI },
            { "arch lich", PM_ARCH_LICH },
            /* Some irregular plurals */
            { "incubi", PM_INCUBUS },
            { "succubi", PM_SUCCUBUS },
            { "violet fungi", PM_VIOLET_FUNGUS },
            { "homunculi", PM_HOMUNCULUS },
            { "baluchitheria", PM_BALUCHITHERIUM },
            { "lurkers above", PM_LURKER_ABOVE },
            { "cavemen", PM_CAVEMAN },
            { "cavewomen", PM_CAVEWOMAN },
            { "djinn", PM_DJINNI },
            { "mumakil", PM_MUMAK },
            { "erinyes", PM_ERINYS },
            /* falsely caught by -ves check above */
            { "master of thief", PM_MASTER_OF_THIEVES },
            /* end of list */
            {0, 0}
        };
        const struct alt_spl *namep;

        for (namep = names; namep->name; namep++)
            if (!strncmpi(str, namep->name, (int)strlen(namep->name)))
                return namep->pm_val;
    }

    for (len = 0, i = LOW_PM; i < NUMMONS; i++) {
        int m_i_len = strlen(mons[i].mname);

        if (m_i_len > len && !strncmpi(mons[i].mname, str, m_i_len)) {
            if (m_i_len == slen)
                return i;       /* exact match */
            else if (slen > m_i_len &&
                     (str[m_i_len] == ' ' || !strcmpi(&str[m_i_len], "s") ||
                      !strncmpi(&str[m_i_len], "s ", 2) ||
                      !strcmpi(&str[m_i_len], "'") ||
                      !strncmpi(&str[m_i_len], "' ", 2) ||
                      !strcmpi(&str[m_i_len], "'s") ||
                      !strncmpi(&str[m_i_len], "'s ", 3) ||
                      !strcmpi(&str[m_i_len], "es") ||
                      !strncmpi(&str[m_i_len], "es ", 3))) {
                mntmp = i;
                len = m_i_len;
            }
        }
    }
    if (mntmp == NON_PM)
        mntmp = title_to_mon(str, NULL, NULL);
    return mntmp;
}