Ejemplo n.º 1
0
/* This function parses the query string */
static void f_parse_query_string( INT32 args )     
{
  struct pike_string *query; /* Query string to parse */
  struct svalue *exist, skey, sval; /* svalues used */
  struct mapping *variables; /* Mapping to store vars in */
  unsigned char *ptr;   /* Pointer to current char in loop */
  unsigned char *name;  /* Pointer to beginning of name */
  unsigned char *equal; /* Pointer to the equal sign */
  unsigned char *end;   /* Pointer to the ending null char */
  int namelen, valulen; /* Length of the current name and value */
  get_all_args("Caudium.parse_query_string", args, "%S%m", &query, &variables);
  skey.type = sval.type = T_STRING;
  /* end of query string */
  end = (unsigned char *)(query->str + query->len);
  name = ptr = (unsigned char *)query->str;
  equal = NULL;
  for(; ptr <= end; ptr++) {
    switch(*ptr)
    {
     case '=':
      /* Allow an unencoded '=' in the value. It's invalid but... */
      if(equal == NULL)
	equal=ptr;
      break;
     case '\0':
      if(ptr != end)
	continue;
     case ';': /* It's recommended to support ';'
		  instead of '&' in query strings... */
     case '&':
      if(equal == NULL) { /* value less variable, we can ignore this */
	name = ptr+1;
	break;
      }
      namelen = equal - name;
      valulen = ptr - ++equal;
      skey.u.string = url_decode(name, namelen, 0);
      if (skey.u.string == NULL) { /* OOM. Bail out */
	Pike_error("Caudium.parse_query_string(): Out of memory in url_decode().\n");
      }
      exist = low_mapping_lookup(variables, &skey);
      if(exist == NULL || exist->type != T_STRING) {
	sval.u.string = url_decode(equal, valulen, 0);
	if (sval.u.string == NULL) { /* OOM. Bail out */
	  Pike_error("Caudium.parse_query_string(): "
		     "Out of memory in url_decode().\n");
	}
      } else {
	/* Add strings separed with '\0'... */
	struct pike_string *tmp;
	tmp = url_decode(equal, valulen, 1);
	if (tmp == NULL) {
	  Pike_error("Caudium.parse_query_string(): "
		     "Out of memory in url_decode().\n");
	}
	sval.u.string = add_shared_strings(exist->u.string, tmp);
	free_string(tmp);
      }
      mapping_insert(variables, &skey, &sval);
      free_string(skey.u.string);
      free_string(sval.u.string);

      /* Reset pointers */
      equal = NULL;
      name = ptr+1;
    }
  }
  pop_n_elems(args);
}
Ejemplo n.º 2
0
Archivo: ui.c Proyecto: ec429/spiffy
void ui_init(SDL_Surface *screen, button **buttons, bool edgeload, bool pause, bool keyboard, bool printer)
{
	static button btn[nbuttons];
	*buttons=btn;
	for(unsigned int i=0;i<nbuttons;i++)
	{
		btn[i].img=NULL;
		btn[i].tooltip=NULL;
	}
	char title[64];
	snprintf(title, 64, "Spiffy - ZX Spectrum %s", name_from_machine(zx_machine));
	SDL_WM_SetCaption(title, "Spiffy");
	SDL_EnableUNICODE(1);
	SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
	SDL_FillRect(screen, &(SDL_Rect){0, y_cntl, screen->w, 1}, SDL_MapRGB(screen->format, 255, 255, 255));
	SDL_FillRect(screen, &(SDL_Rect){0, y_cntl+1, screen->w, 63}, SDL_MapRGB(screen->format, 0, 0, 0)); // controls area
	SDL_FillRect(screen, &(SDL_Rect){0, y_cntl+64, screen->w, 16}, SDL_MapRGB(screen->format, 63, 63, 63)); // status bar
	if(keyboard)
	{
		for(unsigned int i=0;i<10;i++)
			km[i]=configIMG_Load(kmn[i]);
		SDL_FillRect(screen, &(SDL_Rect){0, y_keyb, screen->w, 1}, SDL_MapRGB(screen->format, 255, 255, 255));
		SDL_FillRect(screen, &(SDL_Rect){0, y_keyb+1, screen->w, 160}, SDL_MapRGB(screen->format, 0, 0, 0));
		if(km[0])
			SDL_BlitSurface(km[0], NULL, screen, &(SDL_Rect){0, y_keyb+1, screen->w, 160});
	}
	if(printer)
	{
		SDL_FillRect(screen, &(SDL_Rect){0, y_prnt, screen->w, 1}, SDL_MapRGB(screen->format, 255, 255, 255));
		SDL_FillRect(screen, &(SDL_Rect){0, y_prnt+1, screen->w, 119}, SDL_MapRGB(screen->format, 31, 31, 31)); // printer area
		SDL_FillRect(screen, &(SDL_Rect){32, y_prnt+100, 256, 20}, SDL_MapRGB(screen->format, 191, 191, 195)); // printer paper
	}
	FILE *fimg;
	string img;
	fimg=configopen("buttons/load.pbm", "rb");
	img=sslurp(fimg);
	if(fimg) fclose(fimg);
	btn[0]=(button){.img=pbm_string(img), .posn={116, y_cntl+2, 17, 17}, .col=0x8f8f1f, .tooltip="Load a tape image or snapshot"};
	free_string(&img);
	fimg=configopen("buttons/flash.pbm", "rb");
	img=sslurp(fimg);
	if(fimg) fclose(fimg);
	btn[1]=(button){.img=pbm_string(img), .posn={136, y_cntl+2, 17, 17}, .col=edgeload?0xffffff:0x1f1f1f, .tooltip=edgeload?"Disable edge-loader":"Enable edge-loader"};
	free_string(&img);
	fimg=configopen("buttons/play.pbm", "rb");
	img=sslurp(fimg);
	if(fimg) fclose(fimg);
	btn[2]=(button){.img=pbm_string(img), .posn={156, y_cntl+2, 17, 17}, .col=0x3fbf5f, .tooltip="Play the virtual tape"};
	free_string(&img);
	fimg=configopen("buttons/next.pbm", "rb");
	img=sslurp(fimg);
	if(fimg) fclose(fimg);
	btn[3]=(button){.img=pbm_string(img), .posn={176, y_cntl+2, 17, 17}, .col=0x07079f, .tooltip="Skip to the next tape block"};
	free_string(&img);
	fimg=configopen("buttons/stop.pbm", "rb");
	img=sslurp(fimg);
	if(fimg) fclose(fimg);
	btn[4]=(button){.img=pbm_string(img), .posn={196, y_cntl+2, 17, 17}, .col=0x3f0707, .tooltip="Stop the tape at the end of each block"};
	free_string(&img);
	fimg=configopen("buttons/rewind.pbm", "rb");
	img=sslurp(fimg);
	if(fimg) fclose(fimg);
	btn[5]=(button){.img=pbm_string(img), .posn={216, y_cntl+2, 17, 17}, .col=0x7f076f, .tooltip="Rewind to the beginning of the tape"};
	free_string(&img);
	fimg=configopen("buttons/pause.pbm", "rb");
	img=sslurp(fimg);
	if(fimg) fclose(fimg);
	btn[6]=(button){.img=pbm_string(img), .posn={8, y_cntl+44, 17, 17}, .col=pause?0xbf6f07:0x7f6f07, .tooltip=pause?"Unpause the emulation":"Pause the emulation"};
	free_string(&img);
	fimg=configopen("buttons/reset.pbm", "rb");
	img=sslurp(fimg);
	if(fimg) fclose(fimg);
	btn[7]=(button){.img=pbm_string(img), .posn={28, y_cntl+44, 17, 17}, .col=0xffaf07, .tooltip="Reset the Spectrum"};
	free_string(&img);
	fimg=configopen("buttons/bug.pbm", "rb");
	img=sslurp(fimg);
	if(fimg) fclose(fimg);
	btn[8]=(button){.img=pbm_string(img), .posn={48, y_cntl+44, 17, 17}, .col=0xbfff3f, .tooltip="Start the debugger"};
	free_string(&img);
#ifdef AUDIO
	btn[9].posn=(SDL_Rect){76, 321, 7, 6};
	btn[10].posn=(SDL_Rect){76, 328, 7, 6};
	btn[11].posn=(SDL_Rect){136, 321, 7, 6};
	btn[12].posn=(SDL_Rect){136, 328, 7, 6};
	fimg=configopen("buttons/record.pbm", "rb");
	img=sslurp(fimg);
	if(fimg) fclose(fimg);
	btn[13]=(button){.img=pbm_string(img), .posn={8, y_cntl+24, 17, 17}, .col=0x7f0707, .tooltip="Record audio"};
	drawbutton(screen, btn[13]);
	free_string(&img);
#endif /* AUDIO */
	fimg=configopen("buttons/snap.pbm", "rb");
	img=sslurp(fimg);
	if(fimg) fclose(fimg);
	btn[14]=(button){.img=pbm_string(img), .posn={68, y_cntl+44, 17, 17}, .col=0xbfbfbf, .tooltip="Save a snapshot"};
	drawbutton(screen, btn[14]);
	free_string(&img);
	fimg=configopen("buttons/trec.pbm", "rb");
	img=sslurp(fimg);
	if(fimg) fclose(fimg);
	btn[15]=(button){.img=pbm_string(img), .posn={236, y_cntl+2, 17, 17}, .col=0x4f0f0f, .tooltip="Record tape"};
	drawbutton(screen, btn[15]);
	free_string(&img);
	fimg=configopen("buttons/feed.pbm", "rb");
	img=sslurp(fimg);
	if(fimg) fclose(fimg);
	btn[16]=(button){.img=pbm_string(img), .posn={88, y_cntl+44, 17, 17}, .col=printer?0x3f276f:0x170f1f, .tooltip=printer?"ZX Printer: Paper feed":"ZX Printer is disabled"};
	drawbutton(screen, btn[16]);
	free_string(&img);
	fimg=configopen("buttons/js_c.pbm", "rb");
	img=sslurp(fimg);
	if(fimg) fclose(fimg);
	btn[17]=(button){.img=pbm_string(img), .posn={108, y_cntl+44, 9, 9}, .col=0x3fff3f, .tooltip="Select CURSOR keystick"};
	free_string(&img);
	fimg=configopen("buttons/js_s.pbm", "rb");
	img=sslurp(fimg);
	if(fimg) fclose(fimg);
	btn[18]=(button){.img=pbm_string(img), .posn={116, y_cntl+44, 9, 9}, .col=0x3f3f3f, .tooltip="Select SINCLAIR keystick"};
	free_string(&img);
	fimg=configopen("buttons/js_k.pbm", "rb");
	img=sslurp(fimg);
	if(fimg) fclose(fimg);
	btn[19]=(button){.img=pbm_string(img), .posn={108, y_cntl+52, 9, 9}, .col=0x3f3f3f, .tooltip="Select KEMPSTON keystick"};
	free_string(&img);
	fimg=configopen("buttons/js_x.pbm", "rb");
	img=sslurp(fimg);
	if(fimg) fclose(fimg);
	btn[20]=(button){.img=pbm_string(img), .posn={116, y_cntl+52, 9, 9}, .col=0x3f3f3f, .tooltip="Disable keystick"};
	free_string(&img);
	ksupdate(screen, *buttons, JS_C);
	fimg=configopen("buttons/bw.pbm", "rb");
	img=sslurp(fimg);
	if(fimg) fclose(fimg);
	btn[21]=(button){.img=pbm_string(img), .posn={128, y_cntl+44, 17, 17}, .col=0x9f9f9f, .tooltip="Enable Black&White filter"};
	drawbutton(screen, btn[21]);
	free_string(&img);
	fimg=configopen("buttons/scan.pbm", "rb");
	img=sslurp(fimg);
	if(fimg) fclose(fimg);
	btn[22]=(button){.img=pbm_string(img), .posn={148, y_cntl+44, 17, 17}, .col=0x5f5fcf, .tooltip="Enable TV Scanlines filter"};
	drawbutton(screen, btn[22]);
	free_string(&img);
	fimg=configopen("buttons/blur.pbm", "rb");
	img=sslurp(fimg);
	if(fimg) fclose(fimg);
	btn[23]=(button){.img=pbm_string(img), .posn={168, y_cntl+44, 17, 17}, .col=0xbf3f3f, .tooltip="Enable Horizontal Blur filter"};
	drawbutton(screen, btn[23]);
	free_string(&img);
	fimg=configopen("buttons/vblur.pbm", "rb");
	img=sslurp(fimg);
	if(fimg) fclose(fimg);
	btn[24]=(button){.img=pbm_string(img), .posn={188, y_cntl+44, 17, 17}, .col=0xbf3f3f, .tooltip="Enable Vertical Blur filter"};
	drawbutton(screen, btn[24]);
	free_string(&img);
	fimg=configopen("buttons/misg.pbm", "rb");
	img=sslurp(fimg);
	if(fimg) fclose(fimg);
	btn[25]=(button){.img=pbm_string(img), .posn={208, y_cntl+44, 17, 17}, .col=0x1f5f1f, .tooltip="Enable Misaligned Green filter"};
	drawbutton(screen, btn[25]);
	free_string(&img);
	fimg=configopen("buttons/slow.pbm", "rb");
	img=sslurp(fimg);
	if(fimg) fclose(fimg);
	btn[26]=(button){.img=pbm_string(img), .posn={228, y_cntl+44, 17, 17}, .col=0x8f8faf, .tooltip="Enable Slow Fade filter"};
	drawbutton(screen, btn[26]);
	free_string(&img);
	fimg=configopen("buttons/pal.pbm", "rb");
	img=sslurp(fimg);
	if(fimg) fclose(fimg);
	btn[27]=(button){.img=pbm_string(img), .posn={248, y_cntl+44, 17, 17}, .col=0x4f4f4f, .tooltip="Enable PAL Chroma Distortion filter"};
	drawbutton(screen, btn[27]);
	free_string(&img);
	for(unsigned int i=0;i<9;i++)
		drawbutton(screen, btn[i]);
}
Ejemplo n.º 3
0
std::string Drakes::BuildDescription(CHAR_DATA & ch, const char * stoneName, Age age)
{
    std::ostringstream result;
    
    // Devise a random seed based on caster and stone type
    unsigned int seed(ch.id);
    for (size_t i(0); stoneName[i] != '\0'; ++i)
        seed += stoneName[i];

    // Determine the random words
    const char * strata("banded with");
    srand(seed);
    switch (number_range(0, 4))
    {
        case 0: strata = "banded with"; break;
        case 1: strata = "lined in"; break;
        case 2: strata = "shot through with streaks of"; break;
        case 3: strata = "speckled with"; break;
        case 4: strata = "marked with bands of"; break;
    }
    srand(time(0));

    switch (age)
    {
        case Hatchling:
            result << "A drake hatchling is here, " << strata << ' ' << stoneName << ". ";
            result << "Pale scrapings of the stone curl all over its mineral flesh, lending it an almost downy appearance. ";
            result << "With its tiny fangs and complete absence of wings, the drake seems to be quite young.";
            break;

        case Youngling:
            result << "A drake youngling is here, " << strata << ' ' << stoneName << ". ";
            result << "The early stubs of its wings have begun to develop, tipped in small claws. ";
            result << "The " << stoneName << " in its flesh is starting to show early signs of deepening in hue.";
            break;

        case Fledgling:
            result << "A drake fledgling is here, " << strata << ' ' << stoneName << ". ";
            result << "Though still clearly a juvenile, the plates of stone which make up its flesh have ";
            result << "taken on nearly the deeper hue associated with adults of its kind. ";
            result << "Claw-tipped wings sprout from its sides, almost fully-developed.";
            break;

        case Wingborne:
            result << "A full-grown drake is here, " << strata << ' ' << stoneName << ". ";
            result << "Sharp fangs protrude from its maw, complementing the curved claws extending from its wings. ";
            result << "Stony scale plates armor its body, their weight balanced by a ridged tail.";
            break;

        case Greater:
            result << "A greater drake is here, " << strata << ' ' << stoneName << ". ";
            result << "Though similar in appearance to the rest of its kind, this beast is unusually large, bearing ";
            result << "pronounced fangs and powerful claw-tipped wings.";
            break;

        case Elder:
            result << "An elder drake is here, " << strata << ' ' << stoneName << ". ";
            result << "Thick, tough plates of stone armor adorn its body, protruding out in spikes at sharp angles. ";
            result << "Its eyes are dark and focused, taking in the world about it with their steely gaze."; 
            break;

        case Ancient:
            result << "An ancient drake is here, " << strata << ' ' << stoneName << ". ";
            result << "The thick plates of its stony hide have fused together over time and sprouted sharp spikes, which ";
            result << "jut out at a odd angles from its body and tail. With powerful fangs and long claws on the ends of ";
            result << "mighty wings, this beast seems formidable indeed.";
            break;
    }

    // Format the string before returning
    // All the memory manipulation issues are to support the awkward API of format_string
    char * descIn(str_dup(result.str().c_str()));
    char * resultDesc(format_string(descIn));
    std::string desc(resultDesc);
    free_string(resultDesc);
    return desc;
}
Ejemplo n.º 4
0
cast_data::~cast_data()
{
    free_string(arg);
}
Ejemplo n.º 5
0
void generate_auto_quest()
{

  extern bool quest;
   
  extern CHAR_DATA *quest_mob;
  extern CHAR_DATA *quest_target;
  extern OBJ_DATA *quest_object;
  extern int quest_timer;
  extern int quest_wait;
  extern sh_int quest_personality;
 // int  hunt_flags = 0;
  char new_long_desc[MAX_STRING_LENGTH];
  sh_int       loop_counter = 0; 

  int a = 140;
  int b = 0;
  sh_int  average_level= 0;
      
  /* generate a new quest! */
  if ( quest )
  {
    return;
  }
      
#if 0
      /* Work out levels of currently playing folks */
  if ( descriptor_list && descriptor_list->connected == CON_PLAYING )
  {
  for ( d = descriptor_list; d; d = d->next )
  {
    if (    d->connected != CON_PLAYING )
      continue;
	if (IS_IMMORTAL(d->character))
		continue;
      player_count += 1;
      total_levels += d->character->level;
  }
  player_count = UMAX( 1, player_count );
  average_level = ( total_levels / player_count );
#endif

  quest_mob = NULL;
  quest_target = NULL;

  average_level = number_range( 0, 65 );
  if ( average_level < 20 )
  {
    a = number_range( 5, 25 );
    b = number_range( 30, 45 );
//    hunt_flags = HUNT_WORLD | HUNT_OPENDOOR ;
    quest_personality = 1;
  }
  else   if ( average_level < 40 )
  {
    a = number_range( 30, 40 );
    b = number_range( 40, 55 );
//    hunt_flags = HUNT_WORLD | HUNT_OPENDOOR | HUNT_PICKDOOR;
    quest_personality = 2;
  }
  else
  {
    a = number_range( 50, 55 );
    b = number_range( 56, 99 );
//    hunt_flags = HUNT_WORLD | HUNT_OPENDOOR | HUNT_PICKDOOR | HUNT_UNLOCKDOOR;
    quest_personality = 3;
  }
  if (quest_personality == 0 )
	  quest_personality = 1;

  while (  ( quest_mob == NULL )
        && ( loop_counter < 500 )  )
  {
    loop_counter++;
    quest_mob    = get_quest_giver(a, b);
  }

  if ( quest_mob == NULL )
  {
    quest = FALSE;
    quest_wait = number_range( 1, 3 );
    return;
  }
  loop_counter = 0;
  while (  ( quest_target == NULL )
        && ( loop_counter < 500 )  )
  {
    loop_counter++;
    quest_target = get_quest_target( a, b );
	
    if (  ( quest_target == NULL )
       || ( quest_target == quest_mob )  ) 
      quest_target = NULL;
	  
  }



  if ( quest_target == NULL )
  {
    quest = FALSE;
    quest_wait = number_range( 1, 3 );
    return;
  }
  quest_object = load_quest_object( quest_target );
  if ( quest_object == NULL )
  {
    quest = FALSE;
    quest_wait = number_range( 1, 3 );
    return;
  }
      /* Set values on quest item for Qp, Pracs, Exp, Gold */
  quest_object->value[0] = UMAX( 1, ( quest_target->level / 3 ) );
  quest_object->value[1] = number_range(1, 60);
  quest_object->value[2] = ( quest_target->level * 100 );
  quest_object->value[3] = average_level;
  quest_object->value[4] = 2;

  if ( number_percent() < 10 )
  {
    quest_object->value[0] += 2;
    quest_object->value[1] += 3;
    quest_object->value[2] *= 2;
    quest_object->value[4] *= 3;
  }
      
  quest_timer = 0;
  quest = TRUE;
  new_long_desc[0] = '\0';
  if ( quest_mob->pIndexData->long_descr_orig != NULL )
    free_string( quest_mob->pIndexData->long_descr_orig );
  quest_mob->pIndexData->long_descr_orig = str_dup(quest_mob->long_descr );
  sprintf( new_long_desc, "{x%s{x says have you found {x%s{x?\n\r",
         quest_mob->short_descr, quest_object->short_descr );
  if ( quest_mob->long_descr != NULL )      
    free_string( quest_mob->long_descr );    
  quest_mob->long_descr = str_dup( new_long_desc );
  SET_BIT( quest_mob->act, PLR_NOSUMMON );
  REMOVE_BIT(quest_mob->act, ACT_AGGRESSIVE);

  new_long_desc[0] = '\0';
  if ( quest_target->pIndexData->long_descr_orig != NULL )
    free_string( quest_target->pIndexData->long_descr_orig );
  quest_target->pIndexData->long_descr_orig = str_dup( quest_target->long_descr );
  sprintf( new_long_desc, "{x%s{x says I stole {x%s{x!\n\r",
        quest_target->pIndexData->short_descr, quest_object->short_descr );
  if ( quest_target->long_descr != NULL )     
        free_string( quest_target->long_descr );   
  quest_target->long_descr = str_dup( new_long_desc );

  SET_BIT( quest_target->act, PLR_NOSUMMON );  
  return;

}
Ejemplo n.º 6
0
reset_data::~reset_data()
{
    is_free = true;
    free_string(notes);
}
Ejemplo n.º 7
0
ban_data::~ban_data()
{
    free_string(name);
    free_string(banned_by);
}
Ejemplo n.º 8
0
/* Date stamp idea comes from Alander of ROM */
void do_note( CHAR_DATA *ch, const char *argument )
{
    NOTE_DATA *pnote;
    char       buf  [ MAX_STRING_LENGTH   ];
    char       buf1 [ MAX_STRING_LENGTH*7 ];
    char       arg  [ MAX_INPUT_LENGTH    ];
    int        vnum;
    int        anum;

    if ( IS_NPC( ch ) )
	return;

    argument = one_argument( argument, arg );
    smash_tilde( argument );

    if ( arg[0] == '\0' )
    {
	do_note( ch, "read" );
	return;
    }

    if ( !str_cmp( arg, "list" ) )
    {
	vnum    = 0;
	buf1[0] = '\0';
	for ( pnote = note_list; pnote; pnote = pnote->next )
	{
	    if ( is_note_to( ch, pnote ) )
	    {
		sprintf( buf, "[%3d%s] %s: %s\n\r",
			vnum,
			( pnote->date_stamp > ch->last_note
			 && str_cmp( pnote->sender, ch->name ) ) ? "N" : " ",
			pnote->sender, pnote->subject );
		strcat( buf1, buf );
		vnum++;
	    }
	}
	send_to_char( buf1, ch );
	return;
    }

    if ( !str_cmp( arg, "read" ) )
    {
	bool fAll;

	if ( !str_cmp( argument, "all" ) )
	{
	    fAll = TRUE;
	    anum = 0;
	}
	else if ( argument[0] == '\0' || !str_prefix( argument, "next" ) )
	  /* read next unread note */
	{
	    vnum    = 0;
	    buf1[0] = '\0';
	    for ( pnote = note_list; pnote; pnote = pnote->next )
	    {
		if ( is_note_to( ch, pnote )
		    && str_cmp( ch->name, pnote->sender )
		    && ch->last_note < pnote->date_stamp )
		{
		    break;
		}
		else
		{
		    if ( is_note_to( ch, pnote ) )
		        vnum++;
		}
	    }
	    if ( pnote )
	    {
		sprintf( buf, "[%3d] %s: %s\n\r%s\n\rTo: %s\n\r",
			vnum,
			pnote->sender,
			pnote->subject,
			pnote->date,
			pnote->to_list );
		strcat( buf1, buf );
		strcat( buf1, pnote->text );
		ch->last_note = UMAX( ch->last_note, pnote->date_stamp );
		send_to_char( buf1, ch );
		return;
	    }
	    send_to_char( "You have no unread notes.\n\r", ch );
	    return;
	}
	else if ( is_number( argument ) )
	{
	    fAll = FALSE;
	    anum = atoi( argument );
	}
	else
	{
	    send_to_char( "Note read which number?\n\r", ch );
	    return;
	}

	vnum    = 0;
	buf1[0] = '\0';
	for ( pnote = note_list; pnote; pnote = pnote->next )
	{
	    if ( is_note_to( ch, pnote ) )
	    {
	        if ( vnum == anum || fAll )
		{
		    sprintf( buf, "[%3d] %s: %s\n\r%s\n\rTo: %s\n\r",
			    vnum,
			    pnote->sender,
			    pnote->subject,
			    pnote->date,
			    pnote->to_list );
		    strcat( buf1, buf );
		    strcat( buf1, pnote->text );
		    if ( !fAll )
		      send_to_char( buf1, ch );
		    else
		      strcat( buf1, "\n\r" );
		    ch->last_note = UMAX( ch->last_note, pnote->date_stamp );
		    if ( !fAll )
		      return;
		}
		vnum++;
	    }
	}

	if ( !fAll )
	    send_to_char( "No such note.\n\r", ch );
	else
	    send_to_char( buf1, ch );
	return;
    }

    if ( !str_cmp( arg, "+" ) )
    {
	note_attach( ch );
	strcpy( buf, ch->pnote->text );
	if ( strlen( buf ) + strlen( argument ) >= MAX_STRING_LENGTH - 200 )
	{
	    send_to_char( "Note too long.\n\r", ch );
	    return;
	}

	strcat( buf, argument );
	strcat( buf, "\n\r"   );
	free_string( ch->pnote->text );
	ch->pnote->text = str_dup( buf );
	send_to_char( "Ok.\n\r", ch );
	return;
    }

    if ( !str_cmp( arg, "subject" ) )
    {
	note_attach( ch );
	free_string( ch->pnote->subject );
	ch->pnote->subject = str_dup( argument );
	send_to_char( "Ok.\n\r", ch );
	return;
    }

    if ( !str_cmp( arg, "to" ) )
    {
	note_attach( ch );
	free_string( ch->pnote->to_list );
	ch->pnote->to_list = str_dup( argument );
	send_to_char( "Ok.\n\r", ch );
	return;
    }

    if ( !str_cmp( arg, "clear" ) )
    {
	if ( ch->pnote )
	{
	    free_string( ch->pnote->text    );
	    free_string( ch->pnote->subject );
	    free_string( ch->pnote->to_list );
	    free_string( ch->pnote->date    );
	    free_string( ch->pnote->sender  );
	    ch->pnote->next	= note_free;
	    note_free		= ch->pnote;
	    ch->pnote		= NULL;
	}

	send_to_char( "Ok.\n\r", ch );
	return;
    }

    if ( !str_cmp( arg, "show" ) )
    {
	if ( !ch->pnote )
	{
	    send_to_char( "You have no note in progress.\n\r", ch );
	    return;
	}

	sprintf( buf, "%s: %s\n\rTo: %s\n\r",
		ch->pnote->sender,
		ch->pnote->subject,
		ch->pnote->to_list );
	send_to_char( buf, ch );
	send_to_char( ch->pnote->text, ch );
	return;
    }

    if ( !str_cmp( arg, "post" ) || !str_prefix( arg, "send" ) )
    {
	FILE *fp;
	char *strtime;

	if ( !ch->pnote )
	{
	    send_to_char( "You have no note in progress.\n\r", ch );
	    return;
	}

	if ( !str_cmp( ch->pnote->to_list, "" ) )
	{
	    send_to_char(
	      "You need to provide a recipient (name, all, or immortal).\n\r",
			 ch );
	    return;
	}

	if ( !str_cmp( ch->pnote->subject, "" ) )
	{
	    send_to_char( "You need to provide a subject.\n\r", ch );
	    return;
	}

	ch->pnote->next			= NULL;
	strtime				= ctime( &current_time );
	strtime[strlen(strtime)-1]	= '\0';
	free_string( ch->pnote->date );
	ch->pnote->date			= str_dup( strtime );
	ch->pnote->date_stamp           = current_time;

	if ( !note_list )
	{
	    note_list	= ch->pnote;
	}
	else
	{
	    for ( pnote = note_list; pnote->next; pnote = pnote->next )
		;
	    pnote->next	= ch->pnote;
	}
	pnote		= ch->pnote;
	ch->pnote       = NULL;

	fclose( fpReserve );
	if ( !( fp = fopen( NOTE_FILE, "a" ) ) )
	{
	    perror( NOTE_FILE );
	}
	else
	{
	    fprintf( fp, "Sender  %s~\n", pnote->sender     );
	    fprintf( fp, "Date    %s~\n", pnote->date       );
	    fprintf( fp, "Stamp   %ld\n", (unsigned long)pnote->date_stamp );
	    fprintf( fp, "To      %s~\n", pnote->to_list    );
	    fprintf( fp, "Subject %s~\n", pnote->subject    );
	    fprintf( fp, "Text\n%s~\n\n", pnote->text       );
	    fclose( fp );
	}
	fpReserve = fopen( NULL_FILE, "r" );

	send_to_char( "Ok.\n\r", ch );
	return;
    }

    if ( !str_cmp( arg, "remove" ) )
    {
	if ( !is_number( argument ) )
	{
	    send_to_char( "Note remove which number?\n\r", ch );
	    return;
	}

	anum = atoi( argument );
	vnum = 0;
	for ( pnote = note_list; pnote; pnote = pnote->next )
	{
	    if ( is_note_to( ch, pnote ) && vnum++ == anum )
	    {
		note_remove( ch, pnote );
		send_to_char( "Ok.\n\r", ch );
		return;
	    }
	}

	send_to_char( "No such note.\n\r", ch );
	return;
    }

    send_to_char( "Huh?  Type 'help note' for usage.\n\r", ch );
    return;
}
Ejemplo n.º 9
0
void note_remove( CHAR_DATA *ch, NOTE_DATA *pnote )
{
    FILE      *fp;
    NOTE_DATA *prev;
    char      *to_list;
    char       to_new [ MAX_INPUT_LENGTH ];
    char       to_one [ MAX_INPUT_LENGTH ];

    /*
     * Build a new to_list.
     * Strip out this recipient.
     */
    to_new[0]	= '\0';
    to_list	= pnote->to_list;
    while ( *to_list != '\0' )
    {
	to_list	= one_argument( to_list, to_one );
	if ( to_one[0] != '\0' && str_cmp( ch->name, to_one ) )
	{
	    strcat( to_new, " "    );
	    strcat( to_new, to_one );
	}
    }

    /*
     * Just a simple recipient removal?
     */
    if ( str_cmp( ch->name, pnote->sender ) && to_new[0] != '\0' )
    {
	free_string( pnote->to_list );
	pnote->to_list = str_dup( to_new + 1 );
	return;
    }

    /*
     * Remove note from linked list.
     */
    if ( pnote == note_list )
    {
	note_list = pnote->next;
    }
    else
    {
	for ( prev = note_list; prev; prev = prev->next )
	{
	    if ( prev->next == pnote )
		break;
	}

	if ( !prev )
	{
	    bug( "Note_remove: pnote not found.", 0 );
	    return;
	}

	prev->next = pnote->next;
    }

    free_string( pnote->text    );
    free_string( pnote->subject );
    free_string( pnote->to_list );
    free_string( pnote->date    );
    free_string( pnote->sender  );
    pnote->next	= note_free;
    note_free	= pnote;

    /*
     * Rewrite entire list.
     */
    fclose( fpReserve );
    if ( !( fp = fopen( NOTE_FILE, "w" ) ) )
    {
	perror( NOTE_FILE );
    }
    else
    {
	for ( pnote = note_list; pnote; pnote = pnote->next )
	{
	    fprintf( fp, "Sender  %s~\n", pnote->sender     );
	    fprintf( fp, "Date    %s~\n", pnote->date       );
	    fprintf( fp, "Stamp   %ld\n", (unsigned long)pnote->date_stamp );
	    fprintf( fp, "To      %s~\n", pnote->to_list    );
	    fprintf( fp, "Subject %s~\n", pnote->subject    );
	    fprintf( fp, "Text\n%s~\n\n", pnote->text       );
	}
	fclose( fp );
    }
    fpReserve = fopen( NULL_FILE, "r" );
    return;
}
Ejemplo n.º 10
0
void free_pcdata(PC_DATA *pcdata)
{
    int cnt;
    GATEKEY_DATA * keys;
    GATEKEY_DATA * keys_next;

    if (!IS_VALID(pcdata))
	return;

#if !defined(FIRST_BOOT)
    free_learned(pcdata->learned);
    free_gknown(pcdata->group_known);
#endif

    free_string(pcdata->email);
    free_string(pcdata->pwd);
    free_string(pcdata->bamfin);
    free_string(pcdata->bamfout);
    free_string(pcdata->title);    
    free_string(pcdata->appearance);
    free_string(pcdata->hood_appearance);
    free_string(pcdata->veil_appearance);
    free_string(pcdata->wolf_appearance);
    free_string(pcdata->dreaming_appearance);
    free_string(pcdata->illusion_appearance);
    free_string(pcdata->ictitle);
    free_string(pcdata->imm_info);
    free_string(pcdata->lastsite);
    free_string(pcdata->lastlog);
    free_string(pcdata->afkmsg);
    free_string(pcdata->semote);
    
    free_string(pcdata->say_voice);
    free_string(pcdata->ask_voice);
    free_string(pcdata->exclaim_voice);
    free_string(pcdata->battlecry_voice);
    
    free_string(pcdata->bondedby);
    free_string(pcdata->restoremessage);
    
    free_string(pcdata->df_name);
    free_string(pcdata->polls);

    free_buf(pcdata->buffer);
    
    for (cnt = 0; cnt < MAX_ALIAS; cnt++)
    {
	free_string(pcdata->alias[cnt]);
	free_string(pcdata->alias_sub[cnt]);
    }
    
    for (cnt = 0; cnt < MAX_IGNORE; cnt++) {
       free_string(pcdata->ignore[cnt]);
    }
    
    for (cnt = 0; cnt < MAX_DISGUISE; cnt++) {
       free_string(pcdata->disguise[cnt]);
    }

    for (keys = pcdata->keys; keys != NULL; keys = keys_next) 
    {
	keys_next = keys->next;
	free_string(keys->key_alias);
	free_string(keys->key_value);
	free(keys);
    } 
    
    INVALIDATE(pcdata);
    pcdata->next = pcdata_free;
    pcdata_free = pcdata;

    return;
}
Ejemplo n.º 11
0
/* download_manifests()
 * Description: To search Clear bundles for a particular entry, a complete set of
 *		manifests must be downloaded. This function does so, asynchronously, using
 *		the curl_multi interface */
static int download_manifests(struct manifest **MoM, struct list **subs)
{
	struct list *list = NULL;
	struct file *file = NULL;
	char *tarfile, *untard_file, *url = NULL;
	struct manifest *subMan = NULL;
	int current_version;
	int ret = 0;
	double size;
	bool did_download = false;

	current_version = get_current_version(path_prefix);
	if (current_version < 0) {
		fprintf(stderr, "Error: Unable to determine current OS version\n");
		return ECURRENT_VERSION;
	}

	*MoM = load_mom(current_version, false, false, NULL);
	if (!(*MoM)) {
		fprintf(stderr, "Cannot load official manifest MoM for version %i\n", current_version);
		return EMOM_LOAD;
	}

	list = (*MoM)->manifests;
	size = query_total_download_size(list);
	if (size == -1) {
		fprintf(stderr, "Downloading manifests. Expect a delay, up to 100MB may be downloaded\n");
	} else if (size > 0) {
		fprintf(stderr, "Downloading Clear Linux manifests\n");
		fprintf(stderr, "   %.2f MB total...\n\n", size);
	}

	while (list) {
		file = list->data;
		list = list->next;

		create_and_append_subscription(subs, file->filename);

		string_or_die(&untard_file, "%s/%i/Manifest.%s", state_dir, file->last_change,
			      file->filename);

		string_or_die(&tarfile, "%s/%i/Manifest.%s.tar", state_dir, file->last_change,
			      file->filename);

		if (access(untard_file, F_OK) == -1) {
			/* Do download */
			subMan = load_manifest(file->last_change, file, *MoM, false);
			if (!subMan) {
				fprintf(stderr, "Cannot load official manifest MoM for version %i\n", current_version);
			} else {
				did_download = true;
			}

			free_manifest(subMan);
		}

		if (access(untard_file, F_OK) == -1) {
			string_or_die(&url, "%s/%i/Manifest.%s.tar", content_url, current_version,
				      file->filename);

			fprintf(stderr, "Error: Failure reading from %s\n", url);
			free_string(&url);
		}

		unlink(tarfile);
		free_string(&untard_file);
		free_string(&tarfile);
	}

	if (did_download) {
		fprintf(stderr, "Completed manifests download.\n\n");
	}

	return ret;
}
Ejemplo n.º 12
0
void free_char (CHAR_DATA *ch)
{
    OBJ_DATA *obj;
    OBJ_DATA *obj_next;
    AFFECT_DATA *paf;
    AFFECT_DATA *paf_next;

    if (!IS_VALID(ch))
	return;

    if (IS_NPC(ch))
	mobile_count--;

    for (obj = ch->carrying; obj != NULL; obj = obj_next)
    {
	obj_next = obj->next_content;
	extract_obj(obj);
    }

    for (paf = ch->affected; paf != NULL; paf = paf_next)
    {
	paf_next = paf->next;
	affect_remove(ch,paf);
    }


    free_string(ch->name);
    free_string(ch->wkname);
    free_string(ch->real_name);
    free_string(ch->short_descr);
    free_string(ch->long_descr);
    free_string(ch->description);
    free_string(ch->hood_description);
    free_string(ch->veil_description);
    free_string(ch->wolf_description);
    free_string(ch->wound_description);
    free_string(ch->aura_description);
    free_string(ch->prompt);
    free_string(ch->prefix);
    
    free_string(ch->gtitle);
    free_string(ch->sguild_title);
    free_string(ch->tguild_title);
    free_string(ch->mtitle);
    free_string(ch->mname);
    
    
  /*  free_note  (ch->pnote); */
    free_pcdata(ch->pcdata);

    ch->next = char_free;
    char_free  = ch;

    INVALIDATE(ch);
    return;
}
Ejemplo n.º 13
0
void do_resurrect(CHAR_DATA *ch, char *argument )
{
    char buf2[MAX_STRING_LENGTH];
    char buf [MAX_INPUT_LENGTH];
    char arg [MAX_STRING_LENGTH];
    CHAR_DATA *victim;
    AFFECT_DATA af;
    OBJ_DATA *obj;
    one_argument(argument,arg);
    if (IS_NPC(ch)) return;
    if (!IS_CLASS(ch, CLASS_WIZARD))
    {
        send_to_char("Huh?\n\r",ch);
        return;
    }
    if (arg[0] == '\0')
    {
        send_to_char("Resurrect what corpse?\n\r",ch);
        return;
    }
    if ( IS_CLASS(ch, CLASS_WIZARD) && ch->pcdata->powers[WL_SKILLS] < 1 )
    {
        stc("You need level 1 in Wizard Skills\n\r",ch);
        return;
    }
    if (ch->pcdata->followers > 5)
    {
        send_to_char("Nothing happens.\n\r",ch);
        return;
    }
    if ((obj = get_obj_carry(ch,arg)) == NULL)
    {
        send_to_char("You dont have that corpse.",ch);
        return;
    }
    if (obj->item_type != ITEM_CORPSE_NPC)
    {
        send_to_char("You can only Resurrect original corpses.\n\r",ch);
        return;
    }
    ch->pcdata->followers++;

    victim=create_mobile( get_mob_index( obj->value[2] ) );
    sprintf(buf,"Resurrection of %s",victim->short_descr);
    sprintf(buf2,"Resurrection of %s is here.\n\r",victim->short_descr);
    free_string(victim->short_descr);
    victim->short_descr = str_dup(buf);
    free_string(victim->name);
    SET_BIT(victim->act, ACT_NOEXP);
    if ( IS_SET(victim->act,ACT_QUEST) ) REMOVE_BIT(victim->act,ACT_QUEST);
    victim->name = str_dup(buf);
    free_string(victim->long_descr);
    victim->long_descr= str_dup(buf2);
    victim->spec_fun = NULL;
    sprintf(buf,"I invoke the rebirth of %s!",victim->name);
    do_say( ch, buf );
    sprintf(buf, "%s clambers back up to its feet.\n\r",obj->short_descr);
    act(buf,ch,NULL,NULL,TO_ROOM);
    send_to_char(buf,ch);
    char_to_room( victim, ch->in_room );

    WAIT_STATE(ch,10);
    extract_obj(obj);

    if(victim->level > ((ch->pcdata->upgrade_level + 1) * 500))
    {
        send_to_char("You are unable to control the resurrected creature.\n\r", ch);
        return;
    }

    add_follower( victim, ch );
    af.type      = skill_lookup ("charm person");
    af.duration  = 666;
    af.location  = APPLY_NONE;
    af.modifier  = 0;
    af.bitvector = AFF_CHARM;
    affect_to_char( victim, &af );
    sprintf(buf,"%s",victim->name);
    do_group(ch,buf);
    return;
}
Ejemplo n.º 14
0
static void f_buf_append( INT32 args )
{
  struct pike_string *str;
  struct svalue skey, sval; /* header, value */
  int slash_n = 0, cnt, num;
  unsigned char *pp,*ep;
  struct svalue *tmp;
  int os=0, i, j=0, l, qmark = -1;
  unsigned char *in, *query;
  
  if( Pike_sp[-1].type != T_STRING )
    Pike_error("Wrong type of argument to append()\n");
  
  str = Pike_sp[-1].u.string;
  
  if( str->len >= BUF->free ) {
    pop_n_elems(args);
    push_int(413); /* Request Entity Too Large */
    return;
  }

  MEMCPY( BUF->pos, str->str, str->len );

  for( ep = (BUF->pos + str->len), pp = MAX(BUF->data, BUF->pos-3); 
       pp < ep && slash_n < 2; pp++ )
    if( *pp == '\n' )       slash_n++;
    else if( *pp != '\r' )  slash_n=0;
  
  BUF->free -= str->len;
  BUF->pos += str->len;
  BUF->pos[0] = 0;
  pop_n_elems( args );
  if( slash_n != 2 )
  {
    /* need more data */
    push_int( 0 );
    return;
  }

  skey.type = sval.type = T_STRING;

  sval.u.string = make_shared_binary_string( (char *)pp, BUF->pos - pp);
  mapping_insert(BUF->other, SVAL(data), &sval); /* data */
  free_string(sval.u.string);
  
  in = BUF->data;
  l = pp - BUF->data;

  /* find method */
  for( i = 0; i < l; i++ ) {
    if( in[i] == ' ' ) 
      break;
    else if(in[i] == '\n') {
      push_int( 400 ); /* Bad Request */
      return;
    }
  }
  sval.u.string = make_shared_binary_string((char *)in, i);
  mapping_insert(BUF->other, SVAL(method), &sval);
  free_string(sval.u.string);
  
  i++; in += i; l -= i;

  /* find file */
  for( i = 0; i < l; i++ ) {
    if(in[i] == ' ') {
      break;
    } else  if(in[i] == '\n') {
      push_int( 400 ); /* Bad Request */
      return;
    }
  }
  sval.u.string = make_shared_binary_string((char *)in, i);
  mapping_insert(BUF->other, SVAL(raw_url), &sval);
  free_string(sval.u.string);

  /* Decode file part and return pointer to query, if any */
  query = char_decode_url(in, i);

  /* Decoded, query-less file up to the first \0 */
  sval.u.string = make_shared_string((char *)in); 
  mapping_insert(BUF->other, SVAL(file), &sval);
  free_string(sval.u.string);
  
  if(query != NULL)  {
    /* Store the query string */
    sval.u.string = make_shared_binary_string((char *)query, i - (query-in)); /* Also up to first null */
    mapping_insert(BUF->other, SVAL(query), &sval);
    free_string(sval.u.string);
  }
  
  i++; in += i; l -= i;

  /* find protocol */
  for( i = 0; i < l; i++ ) {
    if( in[i] == '\n' ) break;
    else if(in[i] == ' ') {
      push_int( 400 ); /* Bad Request */
      return;
    }
  }
  if( in[i-1] != '\r' ) 
    i++;
  sval.u.string = make_shared_binary_string((char *)in, i-1);
  mapping_insert(BUF->other, SVAL(protocol), &sval);
  free_string(sval.u.string);

  in += i; l -= i;
  if( *in == '\n' ) (in++),(l--);

  for(i = 0; i < l; i++)
  {
    if(in[i] >= 'A' && in[i] <= 'Z') in[i] |= 32; /* Lowercasing the header */
    else if( in[i] == ':' )
    {
      /* in[os..i-1] == the header */
      
      skey.u.string = make_shared_binary_string((char*)in+os, i - os);
      os = i+1;
      while(in[os]==' ') os++; /* Remove initial spaces */
      for(j=os;j<l;j++)  if( in[j] == '\n' || in[j]=='\r')  break; 

      if((tmp = low_mapping_lookup(BUF->headers, &skey)) &&
         tmp->type == T_STRING)
      {
        int len = j - os + 1;
        int len2 = len +tmp->u.string->len;
        sval.u.string = begin_shared_string(len2);
        MEMCPY(sval.u.string->str,
               tmp->u.string->str, tmp->u.string->len);
        sval.u.string->str[tmp->u.string->len] = ',';
        MEMCPY(sval.u.string->str + tmp->u.string->len + 1,
               (char*)in + os, len);
        sval.u.string = end_shared_string(sval.u.string);
      } else {
        sval.u.string = make_shared_binary_string((char*)in + os, j - os);
      }
      
      mapping_insert(BUF->headers, &skey, &sval);
      if( in[j+1] == '\n' ) j++;
      os = j+1;
      i = j;
      free_string(sval.u.string);
      free_string(skey.u.string);
    }
  }
  push_int(1);
}
Ejemplo n.º 15
0
mark_data::~mark_data()
{
    free_string(message);
    free_string(author);
}
Ejemplo n.º 16
0
int message_deserialize_request(struct message_request *req,
    msgpack_object *obj, struct api_error *api_error)
{
  msgpack_object *type, *msgid, *method, *params;
  uint64_t tmp_type;
  uint64_t tmp_msgid;

  if (!api_error)
    return (-1);

  if (!req || !obj) {
    error_set(api_error, API_ERROR_TYPE_VALIDATION, "Error");
    return (-1);
  }

  /* type */
  if (obj->via.array.ptr[0].type != MSGPACK_OBJECT_POSITIVE_INTEGER) {
    error_set(api_error, API_ERROR_TYPE_VALIDATION, "type field has wrong type");
    return (-1);
  }

  type = &obj->via.array.ptr[0];
  if (!type) {
    error_set(api_error, API_ERROR_TYPE_VALIDATION, "unpack type failed");
    return (-1);
  }

  tmp_type = unpack_uint(type);

  if (tmp_type != MESSAGE_TYPE_REQUEST) {
    error_set(api_error, API_ERROR_TYPE_VALIDATION, "type must be 0 or 1");
    return (-1);
  }

  /* message id */
  msgid = &obj->via.array.ptr[1];

  if (!msgid || msgid->type != MSGPACK_OBJECT_POSITIVE_INTEGER) {
    error_set(api_error, API_ERROR_TYPE_VALIDATION, "illegal msgid");
    return (-1);
  }

  tmp_msgid = unpack_uint(msgid);

  if (tmp_msgid >= UINT32_MAX) {
    error_set(api_error, API_ERROR_TYPE_VALIDATION, "invalid msgid");
    return (-1);
  }

  req->msgid = (uint32_t)tmp_msgid;

  /* method */
  if (obj->via.array.ptr[2].type != MSGPACK_OBJECT_STR) {
    error_set(api_error, API_ERROR_TYPE_VALIDATION, "method field has wrong type");
    return (-1);
  }

  method = &obj->via.array.ptr[2];

  if (!method) {
    error_set(api_error, API_ERROR_TYPE_VALIDATION, "unpack method failed");
    return (-1);
  }

  req->method = unpack_string(method);

  if (!req->method.str) {
    error_set(api_error, API_ERROR_TYPE_VALIDATION, "Error unpacking method");
    return (-1);
  }

  /* params */
  if (obj->via.array.ptr[3].type != MSGPACK_OBJECT_ARRAY) {
    free_string(req->method);
    error_set(api_error, API_ERROR_TYPE_VALIDATION, "params field has wrong type");
    return (-1);
  }

  params = &obj->via.array.ptr[3];

  if (!params) {
    free_string(req->method);
    error_set(api_error, API_ERROR_TYPE_VALIDATION, "unpack params failed");
    return (-1);
  }

  if (unpack_params(params, &req->params) == -1) {
    free_string(req->method);
    error_set(api_error, API_ERROR_TYPE_VALIDATION, "Error unpacking params");
    return (-1);
  }

  return (0);
}
Ejemplo n.º 17
0
message_data::~message_data()
{
    free_string(author);
    free_string(title);
    free_string(message);
}
Ejemplo n.º 18
0
/*
 * Show a list to a character.
 * Can coalesce duplicated items.
 */
void show_list_to_char(struct gameobject *list, struct char_data *ch, bool fShort, bool fShowNothing)
{
    struct gameobject *obj;
    char buf[13000];
    char **prgpstrShow;
    char *pstrShow;
    int *prgnShow;
    int nShow;
    int iShow;
    unsigned int count;
    bool fCombine;

    if (ch->desc == NULL)
	return;

    /*
     * Alloc space for output lines.
     */

    count = 0;
    for (obj = list; obj != NULL; obj = obj->next_content)
	count++;


    prgpstrShow = alloc_mem(count * (unsigned int)sizeof(char *));
    prgnShow = alloc_mem(count * (unsigned int)sizeof(int));

    nShow = 0;

    /*
     * Format the list of objects.
     */
    for (obj = list; obj != NULL; obj = obj->next_content) {
	if (obj->wear_loc == WEAR_NONE && can_see_obj(ch, obj)) {
	    pstrShow = format_obj_to_char(obj, ch, fShort);

	    fCombine = false;

	    if (IS_NPC(ch) || IS_SET(ch->comm, COMM_COMBINE)) {
		/*
		 * Look for duplicates, case sensitive.
		 * Matches tend to be near end so run loop backwords.
		 */
		for (iShow = nShow - 1; iShow >= 0; iShow--) {
		    if (!strcmp(prgpstrShow[iShow], pstrShow)) {
			prgnShow[iShow]++;
			fCombine = true;
			break;
		    }
		}
	    }

	    /*
	     * Couldn't combine, or didn't want to.
	     */
	    if (!fCombine) {
		prgpstrShow[nShow] = str_dup(pstrShow);
		prgnShow[nShow] = 1;
		nShow++;

		if (nShow > 125) {
		    send_to_char("Tell whoever it is you are looking at to drop some crap.\n\r", ch);
		    send_to_char("Maximum number of items in a list exceeded.\n\r", ch);
		    return;
		}
	    }
	}
    }

    /*
     * Output the formatted list.
     */
    for (iShow = 0; iShow < nShow; iShow++) {
	if (prgpstrShow[iShow][0] == '\0') {
	    free_string(prgpstrShow[iShow]);
	    continue;
	}

	if (IS_NPC(ch) || IS_SET(ch->comm, COMM_COMBINE)) {
	    if (prgnShow[iShow] != 1) {
		sprintf(buf, "(%3d) ", prgnShow[iShow]);
		send_to_char(buf, ch);
	    } else {
		send_to_char("      ", ch);
	    }
	}
	page_to_char(prgpstrShow[iShow], ch);
	send_to_char("\n\r", ch);
	free_string(prgpstrShow[iShow]);
    }

    if (fShowNothing && nShow == 0) {
	if (IS_NPC(ch) || IS_SET(ch->comm, COMM_COMBINE))
	    send_to_char("     ", ch);

	send_to_char("Nothing.\n\r", ch);
    }

    /*
     * Clean up.
     */
    free_mem(prgpstrShow, count * (int)sizeof(char *));
    free_mem(prgnShow, count * (int)sizeof(int));

    return;
}
Ejemplo n.º 19
0
ruler_data::~ruler_data()
{
    free_string(name);
    free_string(affiliation_name);
    free_string(keywords);
}
Ejemplo n.º 20
0
void init()
{
	sigset_t sigmask;
	sigemptyset(&sigmask);
	sigaddset(&sigmask, SIGALRM);
	sigaddset(&sigmask, SIGUSR1);
	
	sigprocmask(SIG_BLOCK, &sigmask, NULL);

	console_print("Emergence Client " VERSION "\n");
	
	SDL_Init(SDL_INIT_AUDIO);
	
	init_user();
	init_network();
	init_timer();
	init_openssl();
	init_key();
	init_download();
	init_servers();

	create_cvars();
	init_console_cvars();
	init_render_cvars();
	init_map_cvars();
	create_control_cvars();
//	create_input_cvars();
	init_tick_cvars();

	init_console();
	create_colour_cvars();
	
	struct string_t *string = new_string_string(emergence_home_dir);
	string_cat_text(string, "/client.config");
	
	if(!exec_config_file(string->text))
	{
		exec_config_file(find_resource("default-controls.config"));
	}
	else
	{
		char *ver = get_cvar_string("version");
		
		if(*ver == '\0')
		{
			struct string_t *command = new_string_text("rm ");
			string_cat_string(command, emergence_home_dir);
			string_cat_text(command, "/skins/default.skin*");
			
			console_print("%s\n", command->text);
			system(command->text);
			
			vid_mode = -1;	// find a nice mode

			exec_config_file(find_resource("default-controls.config"));
		}
		
		free(ver);
	}
	
	free_string(string);
	
	
	set_cvar_string("version", VERSION);
	
	init_skin();
	init_input();
	init_control();
	

	init_render();
	init_rcon();
	init_ping();

	create_cvar_command("quit", client_shutdown_char);
	

	init_sound();
	init_game();
	
	init_alarm();
	
	render_frame();
	
	string = new_string_text("%s%s", emergence_home_dir->text, "/client.autoexec");
	if(!exec_config_file(string->text))
		exec_config_file(find_resource("default-client.autoexec"));
	free_string(string);
	
	start_server_discovery();
}
Ejemplo n.º 21
0
buf_data_struct::~buf_data_struct()
{
    free_string(buf);
}
Ejemplo n.º 22
0
Archivo: atlc.c Proyecto: kgoulet/mdtlc
/*
atlc - arbitrary transmission line calculator, for the analysis of
transmission lines are directional couplers. 

Copyright (C) 2002. Dr. David Kirkby, PhD (G8WRB).

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either package_version 2
of the License, or (at your option) any later package_version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
USA.

Dr. David Kirkby, e-mail [email protected] 

*/
#include "config.h"


#ifdef HAVE_STRING_H
#include <string.h>
#endif

#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif

#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif  

#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif

#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif

#include "definitions.h"
#include "exit_codes.h"

#ifdef ENABLE_POSIX_THREADS
#include <pthread.h>
#endif

#ifdef ENABLE_MPI
#include <mpi.h>
#endif


#ifdef WINDOWS
#pragma hrdstop
#include <condefs.h>
#endif



struct pixels Er_on_command_line[MAX_DIFFERENT_PERMITTIVITIES];
struct pixels Er_in_bitmap[MAX_DIFFERENT_PERMITTIVITIES];

double **Vij;
double **Er;
unsigned char **oddity; 
unsigned char **cell_type; 
unsigned char *image_data;
unsigned char **cell_dielectric;  // mdtlc addition
int width=-1,  height=-1;
//extern int errno;    // mdtlc
//int errno;    // mdtlc
int number_of_workers=MAX_THREADS; 
int non_vacuum_found=FALSE;
int dielectrics_to_consider_just_now;
int coupler=FALSE;
double r=1.90;
 
char *inputfile_name;
double* pVodd;
double* pVeven;

//
// ADDITIONS FOR FLTK GUI
//
#include <windows.h>
#include <cstdlib>
#include <iostream>
#include <time.h>
//#include "browser_log.h"
//#include "trimp.h"


// moved the following from main2 to global because it has to be shared
// with gui
struct transmission_line_properties data;

//int main2(int argc, char **argv) /* Read parameters from command line */
int main2(char* p_file_name, unsigned char* bitmap_in , int w_pix , int h_pix,
    double* Vodd , double* Veven)
{
  FILE *where_to_print_fp=stdout, *image_data_fp;
  char *outputfile_name, *appendfile_name, *output_prefix;
  long i;
  size_t size;
  int offset;
  int q;
  char *end;
  
// added for mdtlc -- atlc has a habit of assuming a new run for each calculation
coupler=FALSE;
r=1.90;

  pVodd = Vodd;
  pVeven = Veven;
  
  printf("Deallocating\n");
// moved free up here to allow gui to access data
  
//if ( oddity != NULL )
//  free_ucmatrix(oddity,0,width-1,0,height-1);
//if ( cell_type != NULL )
//  free_ucmatrix(cell_type,0,width-1,0,height-1);
//if ( Vij != NULL )
//  free_dmatrix(Vij, 0,width-1,0,height-1);
//if ( Er != NULL )
//  free_dmatrix(Er,0,width-1,0,height-1);


  //errno=0;   // mdtlc
  set_data_to_sensible_starting_values(&data);
  inputfile_name=string(0,1024);
  outputfile_name=string(0,1024);
  appendfile_name=string(0,1024);
  output_prefix=string(0,1024);
  /* only use this if we have both a multi-threaded application and that 
  with have the function */
  (void) strcpy(output_prefix,"");
//  while((q=get_options(argc,argv,"Cr:vsSc:d:p:i:t:w:")) != -1)
//  switch (q) 
//  {
//    case 'C':
//      print_copyright( (char *) "1996-2002");
//      exit_with_msg_and_exit_code("",1);
//    break;
//    case 'b':
//      data.should_binary_data_be_written_tooQ=TRUE;
//    break;
//    case 'd':
//      /* Read a colour from the command line */
//      Er_on_command_line[data.dielectrics_on_command_line].other_colour=\
//      strtol(my_optarg, &end, 16);
//      /* Sepparte it into the Red, Green and Blue components */
//      Er_on_command_line[data.dielectrics_on_command_line].blue=\
//      Er_on_command_line[data.dielectrics_on_command_line].other_colour%256;
//      Er_on_command_line[data.dielectrics_on_command_line].green=\
//      Er_on_command_line[data.dielectrics_on_command_line].other_colour/(256);
//      Er_on_command_line[data.dielectrics_on_command_line].red=\
//      Er_on_command_line[data.dielectrics_on_command_line].other_colour/(256*256);
//      end++; /* Gets rid of '=' sign which we put on the command line */
//      Er_on_command_line[data.dielectrics_on_command_line].epsilon=atof(end);
//      if (data.verbose_level > 1)
//        printf("r=%x g=%x b=%x col=%x Er=%f\n",\
//      Er_on_command_line[data.dielectrics_on_command_line].red,\
//      Er_on_command_line[data.dielectrics_on_command_line].green, \
//      Er_on_command_line[data.dielectrics_on_command_line].blue, \
//      Er_on_command_line[data.dielectrics_on_command_line].other_colour, \
//      Er_on_command_line[data.dielectrics_on_command_line].epsilon);
//      data.dielectrics_on_command_line++;
//    break;
//    case 'c':
//      data.cutoff=atof(my_optarg);
//    break;
//    case 'p':
//      (void) strcpy(output_prefix,my_optarg);
//    break;
//    case 'r':
//      data.r=atof(my_optarg);
//      r=data.r;
//    break;
//    case 's':
//      data.write_bitmap_field_imagesQ=FALSE;
//    break;
//    case 'S':
//      data.write_binary_field_imagesQ=FALSE;
//    break;
//    case 't':
//      number_of_workers=atol(my_optarg);
//      if(number_of_workers > MAXIMUM_PROCESSING_DEVICES)
//      {
//         fprintf(stderr,"You are exceeded the %d limit set in the file definitions.h\n",MAXIMUM_PROCESSING_DEVICES);
//	 fprintf(stderr,"If you really do want this many, you will need to recompile\n");    
//         exit_with_msg_and_exit_code("",USER_REQUESTED_TOO_MANY_THREADS);
//      }
//#ifndef ENABLE_POSIX_THREADS
//      if(number_of_workers != 0)
//         exit_with_msg_and_exit_code("Error #1. The -t option can not be \
//used, (except to  set t=0, which is an \nexception made to allow a \
//benchmark to run), on a version of atlc that was \nnot configured with the \
//--with-threads option, and hence built without the \nthreads library.\n",1);
//#endif
//    break;
//    case 'w':
//#ifndef ENABLE_MPI
//      exit_with_msg_and_exit_code("Error #1a. The -w option can not be used on \
//a version of atlc that was not\nconfigured with the --with-mpi option, \
//hence built without the mpi\nlibrary.\n",1);
//#endif
//          break;
//    case 'i': /* Lighten or darken images of E-field */
//	  data.image_fiddle_factor=atof(my_optarg);
//	  break;
//    case 'v':
//      data.verbose_level++;
//    break;
//    case '?':
//      usage_atlc();
//  } /* End of the switch statement */

  /* There should only be one argument to atlc, the bitmapfile name.
  There can be a few options though. We now check that there is only
  one argument */

//  if(argc-my_optind == 1)  /* This should be so hopefully !! */
//  {
//#ifdef DEBUG
//  if (errno != 0)
//    fprintf(stderr,"errno=%d in atlc.c #2\n",errno);
//#endif
    (void) strcpy(inputfile_name, p_file_name);
    (void) strcpy(outputfile_name, output_prefix);
    (void) strcat(output_prefix,inputfile_name);
    (void) strcpy(outputfile_name,output_prefix);
    free_string(output_prefix,0,1024);

//    read_bitmap_file_headers(inputfile_name, &offset, &size, &width, &height);

    /* Allocate all ram now, so atlc is sure to have it. There is no point
    in getting some now, starting work then finding atlc can't get the 
    rest of what is needed. */
    offset=0;
    width = w_pix;
    height = h_pix;
    size = w_pix*h_pix*3;
//    image_data=ustring(0L,(long)size); // KG just use source bitmap from gui
    image_data = bitmap_in;
    oddity=ucmatrix(0,width-1,0,height-1);
    cell_type=ucmatrix(0,width-1,0,height-1);
    cell_dielectric=ucmatrix(0,width-1,0,height-1);  // mdtlc addition
    Vij=dmatrix(0,width-1,0,height-1);
    Er=dmatrix(0,width-1,0,height-1);
    /* On Solaris systems, if the following is not executed, only one 
    thread will run at any one time, which rather defeats the object of 
    running multi-threaded. */

#ifdef ENABLE_POSIX_THREADS
#ifdef HAVE_PTHREAD_SETCONCURRENCY     
    pthread_setconcurrency(number_of_workers);
#endif 
#endif 

    /* Each thread solves the equations for a part of the voltage
    matrix. If there were more threads than columms we would have a
    problem. I'm not sure exactly how many can be got away with, but
    one is unlikly to have more cpus that matrix columns */

    /* In theory, it would be sensible to get atlc to be able to read
    from stdin. This is a test, that checks if the filename is '-', and
    if so assumes its reading from stdin. So far, the program is
    unable to read from stdin, so this code is not really doing
    anything useful, but might be expanded at a later date. */
//#ifdef DEBUG
//  if (errno != 0)
//    fprintf(stderr,"errno=%d in atlc.c #3\n",errno);
//#endif
//    if( strcmp(argv[my_optind],"-") != 0)
//    {
//      if( (image_data_fp=fopen(inputfile_name, "rb")) == NULL)
//      {
//        fprintf(stderr,"Error #3. Can't open %s!!!!!\n", argv[my_optind]);
//        exit_with_msg_and_exit_code("",3);
//      }
//      if(fseek(image_data_fp, offset, SEEK_SET)!=0)
//      {   
//        fprintf(stderr,"Error #4. Sorry, unable to seek to the correct part \
//	(offset=%d) of the bmp image\n", offset);
//	exit_with_msg_and_exit_code("",4);
//      }
//    } /* end of if( strcmp(argv[my_optind],"-") != 0) */
//    else
//      image_data_fp=stdin;
//    /* For some unknown reason Microsoft's Visual C++ was unhappy to read
//    the bitmap image using an fread() call. Instead, the following two 
//    stupid lines fixed that issue. This will only get compiled under 
//    Windoze, the more sensible fread call being used on other operating 
//    systems. */
//
//#ifdef WINDOWS
//    for(i=0; (i < (long)size ) && (feof(image_data_fp)==0); i++)
//      image_data[i]=(unsigned char)fgetc(image_data_fp);
//#else
//	i = fread(image_data,  size, 1, image_data_fp);
//#endif
//    if((ferror(image_data_fp) || (i != 1 )))
//    {
//      fprintf(stderr,"Error #5. Unable to read all of the image data properly\n");
//      exit_with_msg_and_exit_code("",5);
//    }
    /* declare matrix's to indicate what pixels are fixed and variable */
    /* We now fill the following 3 arrays with the correct data, based on the 
    contents of the bitmap image */
 
    setup_arrays(&data);

    set_oddity_value();
   // system("PAUSE");  
    /* If there are multiple dielectrics, the impedance calculations
    needs to be done twice. We start by doing them once, for an vacuum
    dielectric. If necessary, they will be done again */
    do_fd_calculation(&data, size, where_to_print_fp,outputfile_name);
//  }
//  else
//  {
//    usage_atlc();
//    return(PROGRAM_CALLED_WITH_WRONG_NUMBER_OF_ARGUMENTS); 
//  }
  free_string(inputfile_name,0,1024);
  free_string(outputfile_name,0,1024);
  free_string(appendfile_name,0,1024);
//  free_ustring(image_data,0L,(long) size);

  free_ucmatrix(oddity,0,width-1,0,height-1);
  free_ucmatrix(cell_type,0,width-1,0,height-1);
  free_ucmatrix(cell_dielectric,0,width-1,0,height-1);  // mdtlc addition
  free_dmatrix(Vij, 0,width-1,0,height-1);
  free_dmatrix(Er,0,width-1,0,height-1);


  
    // system("PAUSE");
  
  return(OKAY); 
}
Ejemplo n.º 23
0
void do_quest( CHAR_DATA *ch, char *argument )
{
   extern bool quest;
   extern bool auto_quest;
   extern CHAR_DATA *quest_mob;
   extern CHAR_DATA *quest_target;
   extern OBJ_DATA *quest_object;
   extern int quest_timer;
   extern int quest_wait;
  
   char buf[MAX_STRING_LENGTH];
   char new_long_desc[MAX_STRING_LENGTH];
   
   if ( argument[0] == '\0' )	/* Display status */
   {
      if ( !quest )
      {
         send_to_char( "There is no quest currently running.\n\r", ch );
         if ( auto_quest )
            send_to_char( "Quests are currently running automatically.\n\r", ch );
         if ( quest_wait > 0 )
         {
            sprintf( buf, "The next quest may occur in %d minutes.\n\r", (quest_wait * 2) );
            send_to_char( buf, ch );
         }
         return;
      }
      else
         send_to_char( "There is currently a quest running ", ch );
      
      if ( auto_quest )
         send_to_char( "(Automatically)", ch );
      
      send_to_char( "\n\rQuest Details:\n\r\n\r", ch );
      if ( quest_mob )
      {

        sprintf( buf, "The questing mobile is: {x%s{x [In Room %d]\n\r", 
           quest_mob->short_descr, quest_mob->in_room->vnum );
        send_to_char( buf, ch );
      }
      else
      {
        send_to_char( "The questing mobile is dead!\n\r", ch );
      }
      if ( quest_target )
      {
        sprintf( buf, "Target Mobile is: {x%s{x [In Room %d]\n\r",
           quest_target->short_descr, quest_target->in_room->vnum );
        send_to_char( buf, ch );
      }
      else
        send_to_char( "The target mobile is dead!\n\r", ch );

      sprintf( buf, "Target Object is: {x%s{x.\n\r", quest_object->short_descr );
      send_to_char( buf, ch );

      sprintf( buf, "Quest Object is worth: %d QP, %d XP, %d raise points and %d GP\n\r",
         quest_object->value[0], (ch->level < LVL_MOBXPCAP) ? quest_object->value[1] : 0,
         quest_object->value[4], quest_object->value[2]);
      send_to_char( buf, ch );

      
      sprintf( buf, "The Quest has been running for %d/30 minutes.\n\r", (quest_timer * 2) );
      send_to_char( buf, ch );
      
      return;
   }
   if ( !strcmp( argument, "stop" ) )
   {
     if ( quest )
     {
		 /*
       sprintf( buf, "@@NThe quest has been stopped by an {mImmortal@@N. Please speak up if you have already gotten the item.\n\r" );
       do_gecho( ch, buf );
	     */
       clear_quest();
     }
     return;
   }

   if ( !strcmp( argument, "start" ) )
   {
      DESCRIPTOR_DATA *d;
      int a = 80;
      int b = 0;
      sh_int player_count = 0, average_level= 0, total_levels = 0;
      
      /* generate a new quest! */
      if ( quest )
      {
         send_to_char( "There is already a quest running...\n\r", ch );
         return;
      }
      
      if ( auto_quest )
      {
         auto_quest = FALSE;
         send_to_char( "Automatic Quests now OFF.\n\r", ch );
      }
      
      /* Work out levels of currently playing folks */
      for ( d = descriptor_list; d; d = d->next )
      {
         if (  ( d->connected != CON_PLAYING )
            || ( IS_IMMORTAL( d->character )  ) )
            continue;
         player_count += 1;
         total_levels += d->character->level;
      }
      average_level = ( ( ( total_levels == 0 ) ? 30 : total_levels ) /
                        ( ( player_count == 0 ) ? 1 : player_count ) );
      a = average_level - 20;
      b = average_level + 20;

	  sprintf(buf, "Mob lLevel: %d hLevel: %d\n\r", a, b);
	  stc(buf,ch);
      quest_mob    = get_quest_giver(a, b);
      if ( quest_mob == NULL )
      {
         send_to_char( "Failed to find a quest mob\n\r", ch );
         return;
      }
      b = UMIN( b, 110 );
      a = UMAX( 20, a );

      quest_target = get_quest_target( a, b );
      if (  ( quest_target == NULL )
         || ( quest_target == quest_mob )  )
      {
         send_to_char( "Failed to find a quest target\n\r", ch );
         return;
      }
      quest_object = load_quest_object( quest_target );
      if ( quest_object == NULL )
      {
         send_to_char( "An invalid quest object was encountered.  Check log files.\n\r", ch );
         quest = FALSE;
         return;
      }
      /* Set values on quest item for Qp, Pracs, Exp, Gold */
      quest_object->value[0] = UMAX( 1, ( quest_target->level / 3) );
      quest_object->value[1] = number_range(1, 60);
      quest_object->value[2] = ( quest_target->level * 100 );
      quest_object->value[4] = 2;

      if ( number_percent() < 10 )
      {
         quest_object->value[0] += 2;
         quest_object->value[1] += 3;
         quest_object->value[2] *= 2;
         quest_object->value[4] *= 3;
      }
      
      quest_timer = 0;
      quest = TRUE;
      new_long_desc[0] = '\0';
      if ( quest_mob->pIndexData->long_descr_orig != NULL )
        free_string( quest_mob->pIndexData->long_descr_orig );
      quest_mob->pIndexData->long_descr_orig = str_dup(quest_mob->long_descr );
      sprintf( new_long_desc, "%s {xsays have you found %s?\n\r",
         quest_mob->pIndexData->short_descr, quest_object->short_descr );
      if ( quest_mob->long_descr != NULL )      
        free_string( quest_mob->long_descr );    
      quest_mob->long_descr = str_dup( new_long_desc );
      SET_BIT( quest_mob->act, PLR_NOSUMMON );
      REMOVE_BIT(quest_mob->act, ACT_AGGRESSIVE);
     /* T!!! */
      new_long_desc[0] = '\0';
      if ( quest_target->pIndexData->long_descr_orig != NULL )
        free_string( quest_target->pIndexData->long_descr_orig );
      quest_target->pIndexData->long_descr_orig = str_dup( quest_target->long_descr );
      sprintf( new_long_desc, "%s {xsays I stole the {x%s{x!\n\r",
        quest_target->pIndexData->short_descr, quest_object->short_descr );
      if ( quest_target->long_descr != NULL )     
        free_string( quest_target->long_descr );   
      quest_target->long_descr = str_dup( new_long_desc );

      SET_BIT( quest_target->act, PLR_NOSUMMON );

      send_to_char( "QUEST STARTED!\n\r\n\r", ch );
            
      sprintf( buf, "The questing mobile is: {x%s{x [In Room %d]\n\r", 
         quest_mob->pIndexData->short_descr, quest_mob->in_room->vnum );
      send_to_char( buf, ch );
      
      sprintf( buf, "Target Mobile is: {x%s{x [In Room %d]\n\r",
         quest_target->pIndexData->short_descr, quest_target->in_room->vnum );
      send_to_char( buf, ch );
      
      sprintf( buf, "Target Object is: {x%s{x.\n\r", quest_object->short_descr );
      send_to_char( buf, ch );
      
      sprintf( buf, "Quest Object is worth: %d QP, %d XP, %d raise points and %d GP\n\r",
         quest_object->value[0], quest_object->value[1],
         quest_object->value[4], quest_object->value[2] );
      send_to_char( buf, ch );
      
      return;
   }
   if ( !str_cmp( argument, "auto" ) )
   {
      send_to_char( "AutoQuest now initiated!\n\r", ch );
      auto_quest = TRUE;
	  quest_wait = 360;
      return;
   }
   
   
   return;
}      
Ejemplo n.º 24
0
disabled_data::~disabled_data()
{
    free_string(disabled_by);
}
Ejemplo n.º 25
0
/*
** 'restore_retparm' is called when a 'return parameter' block is found on the
** stack. It saves the value currently in the parameter at the address stored as
** the return parameter address and then returns the local variable to its
** correct value
*/
void restore_retparm(int32 parmcount) {
  stack_retparm *p;
  int32 vartype, intvalue;
  float64 floatvalue;
  basicstring stringvalue;
  p = basicvars.stacktop.retparmsp;	/* Not needed, but the code is unreadable otherwise */
#ifdef DEBUG
  if (basicvars.debug_flags.stack) fprintf(stderr, "Restoring RETURN variable at %p from %p, return dest=%p\n",
   p->savedetails.address.intaddr, p, p->retdetails.address.intaddr);
#endif
  basicvars.stacktop.retparmsp++;
  switch (p->savedetails.typeinfo & PARMTYPEMASK) {	/* Fetch value from local variable and restore local var */
  case VAR_INTWORD:	/* Integer variable */
    intvalue = *p->savedetails.address.intaddr;		/* Fetch current value of local variable */
    *p->savedetails.address.intaddr = p->value.savedint;	/* Restore local variable to its old value */
    vartype = VAR_INTWORD;
    break;
  case VAR_FLOAT:	/* Floating point variable */
    floatvalue = *p->savedetails.address.floataddr;
    *p->savedetails.address.floataddr = p->value.savedfloat;
    vartype = VAR_FLOAT;
    break;
  case VAR_STRINGDOL:	/* String variable */
    stringvalue = *p->savedetails.address.straddr;
    *p->savedetails.address.straddr = p->value.savedstring;
    vartype = VAR_STRINGDOL;
    break;
  case VAR_INTBYTEPTR:	/* Indirect byte integer variable */
    intvalue = basicvars.offbase[p->savedetails.address.offset];
    basicvars.offbase[p->savedetails.address.offset] = p->value.savedint;
    vartype = VAR_INTWORD;
    break;
  case VAR_INTWORDPTR:	/* Indirect word integer variable */
    intvalue = get_integer(p->savedetails.address.offset);
    store_integer(p->savedetails.address.offset, p->value.savedint);
    vartype = VAR_INTWORD;
    break;
  case VAR_FLOATPTR:		/* Indirect floating point variable */
    floatvalue = get_float(p->savedetails.address.offset);
    store_float(p->savedetails.address.offset, p->value.savedfloat);
    vartype = VAR_FLOAT;
    break;
  case VAR_DOLSTRPTR:		/* Indirect string variable */
    intvalue = stringvalue.stringlen = get_stringlen(p->savedetails.address.offset);
    stringvalue.stringaddr = alloc_string(intvalue);
    if (intvalue>0) memmove(stringvalue.stringaddr, &basicvars.offbase[p->savedetails.address.offset], intvalue);
    memmove(&basicvars.offbase[p->savedetails.address.offset], p->value.savedstring.stringaddr, p->value.savedstring.stringlen);
    free_string(p->value.savedstring);		/* Discard saved copy of original '$ string' */
    vartype = VAR_DOLSTRPTR;
    break;
  case VAR_INTARRAY: case VAR_FLOATARRAY: case VAR_STRARRAY:	/* Array - Do nothing */
    break;
  default:
    error(ERR_BROKEN, __LINE__, "stack");
  }

/* Now restore the next parameter */

  parmcount--;
  if (parmcount>0) {	/* There are still some parameters to do */
    if (basicvars.stacktop.intsp->itemtype==STACK_LOCAL)
      restore(parmcount);
    else {	/* Must be a return parameter */
      restore_retparm(parmcount);
    }
  }

/* Now we can store the returned value in original variable */

  switch (p->retdetails.typeinfo) {
  case VAR_INTWORD:
    *p->retdetails.address.intaddr = vartype==VAR_INTWORD ? intvalue : TOINT(floatvalue);
    break;
  case VAR_FLOAT:
    *p->retdetails.address.floataddr = vartype==VAR_INTWORD ? TOFLOAT(intvalue) : floatvalue;
    break;
  case VAR_STRINGDOL:
    free_string(*p->retdetails.address.straddr);
    *p->retdetails.address.straddr = stringvalue;
    break;
  case VAR_INTBYTEPTR:
    basicvars.offbase[p->retdetails.address.offset] = vartype==VAR_INTWORD ? intvalue : TOINT(floatvalue);
    break;
  case VAR_INTWORDPTR:
    store_integer(p->retdetails.address.offset, vartype==VAR_INTWORD ? intvalue : TOINT(floatvalue));
    break;
  case VAR_FLOATPTR:
    store_float(p->retdetails.address.offset, vartype==VAR_INTWORD ? TOFLOAT(intvalue) : floatvalue);
    break;
  case VAR_DOLSTRPTR:
    if (stringvalue.stringlen>0) memmove(&basicvars.offbase[p->retdetails.address.offset], stringvalue.stringaddr, stringvalue.stringlen);
    if (vartype==VAR_STRINGDOL) {	/* Local var was a normal string variable */
      basicvars.offbase[p->retdetails.address.offset+stringvalue.stringlen] = CR;	/* So add a 'CR' at the end of the string */
    }
    free_string(stringvalue);
    break;
  case VAR_INTARRAY: case VAR_FLOATARRAY: case VAR_STRARRAY:	/* 'RETURN' dest is array - Do nothing */
    break;
  default:
    error(ERR_BROKEN, __LINE__, "stack");
  }
}
Ejemplo n.º 26
0
extra_descr_data::~extra_descr_data()
{
    free_string(description);
    is_free = true;
    free_string(keyword);
}
Ejemplo n.º 27
0
/* Verifies that the file and the signature exists, and does a signature check
 * afterwards. If any error is to be considered a verify failure, then
 * print_errors should be set to true.
 *
 * returns: true if able to validate the signature, false otherwise */
bool signature_verify(const char *file, const char *sig_file, bool print_errors)
{
	int ret;
	bool result = false;
	struct stat st;
	char *errorstr = NULL;

	int data_fd = -1;
	size_t data_len;
	unsigned char *data = NULL;
	BIO *data_BIO = NULL;

	int sig_fd = -1;
	size_t sig_len;
	unsigned char *sig = NULL;
	BIO *sig_BIO = NULL;

	PKCS7 *p7 = NULL;
	BIO *verify_BIO = NULL;

	/* get the signature */
	sig_fd = open(sig_file, O_RDONLY);
	if (sig_fd == -1) {
		string_or_die(&errorstr, "Failed open %s: %s\n", sig_file, strerror(errno));
		goto error;
	}
	if (fstat(sig_fd, &st) != 0) {
		string_or_die(&errorstr, "Failed to stat %s file\n", sig_file);
		goto error;
	}
	sig_len = st.st_size;
	sig = mmap(NULL, sig_len, PROT_READ, MAP_PRIVATE, sig_fd, 0);
	if (sig == MAP_FAILED) {
		string_or_die(&errorstr, "Failed to mmap %s signature\n", sig_file);
		goto error;
	}
	sig_BIO = BIO_new_mem_buf(sig, sig_len);
	if (!sig_BIO) {
		string_or_die(&errorstr, "Failed to read %s signature into BIO\n", sig_file);
		goto error;
	}

	/* the signature is in DER format, so d2i it into verification pkcs7 form */
	p7 = d2i_PKCS7_bio(sig_BIO, NULL);
	if (p7 == NULL) {
		string_or_die(&errorstr, "NULL PKCS7 File\n");
		goto error;
	}

	/* get the data to be verified */

	data_fd = open(file, O_RDONLY);
	if (data_fd == -1) {
		string_or_die(&errorstr, "Failed open %s\n", file);
		goto error;
	}
	if (fstat(data_fd, &st) != 0) {
		string_or_die(&errorstr, "Failed to stat %s\n", file);
		goto error;
	}
	data_len = st.st_size;
	data = mmap(NULL, data_len, PROT_READ, MAP_PRIVATE, data_fd, 0);
	if (data == MAP_FAILED) {
		string_or_die(&errorstr, "Failed to mmap %s\n", file);
		goto error;
	}
	data_BIO = BIO_new_mem_buf(data, data_len);
	if (!data_BIO) {
		string_or_die(&errorstr, "Failed to read %s into BIO\n", file);
		goto error;
	}

	/* munge the signature and data into a verifiable format */
	verify_BIO = PKCS7_dataInit(p7, data_BIO);
	if (!verify_BIO) {
		string_or_die(&errorstr, "Failed PKCS7_dataInit()\n");
		goto error;
	}

	/* Verify the signature, outdata can be NULL because we don't use it */
	ret = PKCS7_verify(p7, x509_stack, store, verify_BIO, NULL, 0);
	if (ret == 1) {
		result = true;
	} else {
		string_or_die(&errorstr, "Signature check failed!\n");
	}

error:
	if (!result && print_errors) {
		error("Signature check error\n%s", errorstr);
		ERR_print_errors_fp(stderr);
	}

	free_string(&errorstr);

	if (sig) {
		munmap(sig, sig_len);
	}
	if (sig_fd >= 0) {
		close(sig_fd);
	}
	if (data) {
		munmap(data, data_len);
	}
	if (data_fd >= 0) {
		close(data_fd);
	}
	if (sig_BIO) {
		BIO_free(sig_BIO);
	}
	if (data_BIO) {
		BIO_free(data_BIO);
	}
	if (verify_BIO) {
		BIO_free(verify_BIO);
	}
	if (p7) {
		PKCS7_free(p7);
	}

	return result;
}
Ejemplo n.º 28
0
lookup_data::~lookup_data()
{
    free_string(buf);
}
Ejemplo n.º 29
0
static void f_ultraparse( INT32 args )
{
  FD f = -1;
  int lines=0, cls, c=0, my_fd=1, tzs=0, state=0, next;
  unsigned char *char_pointer=0;
  /* array with offsets for fields in the string buffer */
  int buf_points[16];
  INT32 v=0, offs0=0, len=0, bytes=0, gotdate=0;
  INT32 last_hour=0, last_date=0, last_year=0, last_month=0,
    this_date=0, broken_lines=0, tmpinteger=0, field_position=0;
  time_t start;
  unsigned char *read_buf;
  struct svalue *statfun, *daily, *pagexts=0, *file,  *refsval, *log_format;
  unsigned char *buf;
  char *field_buf;
#ifdef BROKEN_LINE_DEBUG
  INT32 broken_line_pos=0;
  unsigned char *broken_line;
#endif
  INT32 *state_list, *save_field_num, *field_endings, num_states;

  char *notref = 0;
  INT32 state_pos=0, bufpos=0, i, fieldnum=0;
  struct pike_string *url_str = 0,  *ref_str = 0, *rfc_str = 0, *hst_str = 0, *tmpagent = 0;
  struct svalue *url_sval;
  ONERROR unwind_protect;
  unsigned INT32 hits_per_hour[24];
  unsigned INT32 hosts_per_hour[24];
  unsigned INT32 pages_per_hour[24];
  unsigned INT32 sessions_per_hour[24];
  double kb_per_hour[24];
  unsigned INT32 session_length[24];
  /*  struct mapping *unique_per_hour  = allocate_mapping(1);*/
  struct mapping *hits_per_error  = allocate_mapping(10);
  struct mapping *error_urls      = allocate_mapping(10);
  struct mapping *error_refs      = allocate_mapping(10);
  struct mapping *user_agents     = allocate_mapping(10);
  struct mapping *directories     = allocate_mapping(20);
  struct mapping *referrers       = allocate_mapping(1);
  struct mapping *refsites        = allocate_mapping(1);
  struct mapping *referredto      = allocate_mapping(1);
  struct mapping *pages           = allocate_mapping(1);
  struct mapping *hosts           = allocate_mapping(1);
  struct mapping *hits            = allocate_mapping(1);
  struct mapping *session_start   = allocate_mapping(1);
  struct mapping *session_end     = allocate_mapping(1);
  struct mapping *hits20x    	  = allocate_mapping(300);
  struct mapping *hits302    	  = allocate_mapping(2);
  struct mapping *sites    	  = allocate_mapping(1);
  struct mapping *domains    	  = allocate_mapping(1);
  struct mapping *topdomains   	  = allocate_mapping(1);
  struct mapping *tmpdest = NULL;
  /*  struct mapping *hits30x     = allocate_mapping(2);*/
  
  if(args>6 && sp[-1].type == T_INT) {
    offs0 = sp[-1].u.integer;
    pop_n_elems(1);
    --args;
  }
  if(args>5 && sp[-1].type == T_STRING) {
    notref = sp[-1].u.string->str;
    pop_n_elems(1);
    --args;
  }
  lmu = 0;
  get_all_args("UltraLog.ultraparse", args, "%*%*%*%*%*", &log_format, &statfun, &daily, &file,
	       &pagexts);
  if(log_format->type != T_STRING) 
    Pike_error("Bad argument 1 to Ultraparse.ultraparse, expected string.\n");
  if(statfun->type != T_FUNCTION)  
    Pike_error("Bad argument 2 to Ultraparse.ultraparse, expected function.\n");
  if(daily->type != T_FUNCTION)    
    Pike_error("Bad argument 3 to Ultraparse.ultraparse, expected function.\n");
  if(pagexts->type != T_MULTISET)  
    Pike_error("Bad argument 5 to Ultraparse.ultraparse, expected multiset.\n");
  
  if(file->type == T_OBJECT)
  {
    f = fd_from_object(file->u.object);
    
    if(f == -1)
      Pike_error("UltraLog.ultraparse: File is not open.\n");
    my_fd = 0;
  } else if(file->type == T_STRING &&
	    file->u.string->size_shift == 0) {
    do {
      f=fd_open(file->u.string->str, fd_RDONLY, 0);
    } while(f < 0 && errno == EINTR);
    
    if(errno < 0)
      Pike_error("UltraLog.ultraparse(): Failed to open file for reading (errno=%d).\n",
	    errno);
  } else 
    Pike_error("Bad argument 4 to UltraLog.ultraparse, expected string or object .\n");

  state_list = malloc((log_format->u.string->len +3) * sizeof(INT32));
  save_field_num = malloc((log_format->u.string->len +3) * sizeof(INT32));
  field_endings = malloc((log_format->u.string->len +3) * sizeof(INT32));

  num_states = parse_log_format(log_format->u.string, state_list, field_endings, save_field_num);
  if(num_states < 1)
  {
    free(state_list);
    free(save_field_num);
    free(field_endings);
    Pike_error("UltraLog.ultraparse(): Failed to parse log format.\n");
  }
  
  fd_lseek(f, offs0, SEEK_SET);
  read_buf = malloc(READ_BLOCK_SIZE+1);
  buf = malloc(MAX_LINE_LEN+2);
#ifdef BROKEN_LINE_DEBUG
  broken_line = malloc(MAX_LINE_LEN*10);
#endif
  MEMSET(hits_per_hour, 0, sizeof(hits_per_hour));
  MEMSET(hosts_per_hour, 0, sizeof(hosts_per_hour));
  MEMSET(session_length, 0, sizeof(session_length));
  MEMSET(pages_per_hour, 0, sizeof(pages_per_hour));
  MEMSET(sessions_per_hour, 0, sizeof(sessions_per_hour));
  MEMSET(kb_per_hour, 0, sizeof(kb_per_hour));

  /*url_sval.u.type = TYPE_STRING;*/
  BUFSET(0);
  field_position = bufpos;
  buf_points[0] = buf_points[1] = buf_points[2] = buf_points[3] = 
    buf_points[4] = buf_points[5] = buf_points[6] = buf_points[7] = 
    buf_points[8] = buf_points[9] = buf_points[10] = buf_points[11] = 
    buf_points[12] = buf_points[13] = buf_points[14] = buf_points[15] = 0;
  while(1) {
    /*    THREADS_ALLOW();*/
    do {
      len = fd_read(f, read_buf, READ_BLOCK_SIZE);
    } while(len < 0 && errno == EINTR);
    /*    THREADS_DISALLOW();*/
    if(len <= 0)  break; /* nothing more to read or error. */
    offs0 += len;
    char_pointer = read_buf+len - 1;
    while(len--) {
      c = char_pointer[-len]; 
      cls = char_class[c];
#if 0
      fprintf(stdout, "DFA(%d:%d): '%c' (%d) ", state, state_pos, c, (int)c);
      switch(cls) {
       case CLS_WSPACE: fprintf(stdout, "CLS_WSPACE\n"); break;
       case CLS_CRLF: fprintf(stdout, "CLS_CRLF\n"); break;
       case CLS_TOKEN: fprintf(stdout, "CLS_TOKEN\n"); break;
       case CLS_DIGIT: fprintf(stdout, "CLS_DIGIT\n"); break;
       case CLS_QUOTE: fprintf(stdout, "CLS_QUOTE\n"); break;
       case CLS_LBRACK: fprintf(stdout, "CLS_LBRACK\n"); break;
       case CLS_RBRACK: fprintf(stdout, "CLS_RBRACK\n"); break;
       case CLS_SLASH: fprintf(stdout, "CLS_SLASH\n"); break;
       case CLS_COLON: fprintf(stdout, "CLS_COLON\n"); break;
       case CLS_HYPHEN: fprintf(stdout, "CLS_HYPHEN/CLS_MINUS\n"); break;
       case CLS_PLUS: fprintf(stdout, "CLS_PLUS\n"); break;
       default: fprintf(stdout, "??? %d ???\n", cls);
      }
#endif
#ifdef BROKEN_LINE_DEBUG
      broken_line[broken_line_pos++] = c;
#endif
      if(cls == field_endings[state_pos]) {
	/* Field is done. Nullify. */
      process_field:
	/*	printf("Processing field %d of %d\n", state_pos, num_states);*/
	switch(save_field_num[state_pos]) {
	 case DATE:
	 case HOUR:
	 case MINUTE:
	 case UP_SEC:
	 case CODE:
	   /*	  BUFSET(0);*/
	  tmpinteger = 0;
	  for(v = field_position; v < bufpos; v++) {
	    if(char_class[buf[v]] == CLS_DIGIT)
	      tmpinteger = tmpinteger*10 + (buf[v]&0xf);
	    else {
	      goto skip;
	      
	    }
	  }
	  BUFPOINT = tmpinteger;
	  break;
	  
	 case YEAR:
	  tmpinteger = 0;
	  for(v = field_position; v < bufpos; v++) {
	    if(char_class[buf[v]] == CLS_DIGIT)
	      tmpinteger = tmpinteger*10 + (buf[v]&0xf);
	    else {
	      goto skip;
	    }
	  }
	  if(tmpinteger < 100) {
	    if(tmpinteger < 60)
	      tmpinteger += 2000;
	    else
	      tmpinteger += 1900;
	  }
	  BUFPOINT = tmpinteger;	  
	  break;

	 case BYTES:
	  v = field_position;
	  switch(char_class[buf[v++]]) {
	   case CLS_QUESTION:
	   case CLS_HYPHEN:
	    if(v == bufpos)
	      tmpinteger = 0;
	    else {
	      goto skip;
	    }
	    break;
	   case CLS_DIGIT:
	    tmpinteger = (buf[field_position]&0xf);
	    for(; v < bufpos; v++) {
	      if(char_class[buf[v]] == CLS_DIGIT)
		tmpinteger = tmpinteger*10 + (buf[v]&0xf);
	      else {
		goto skip;
	      }		
	    }
	    /*	    printf("Digit: %d\n", tmpinteger);*/
	    break;
	   default:
	    goto skip;
	  }
	  BUFPOINT = tmpinteger;
	  /*	  bufpos++;*/
	  break;	  
	 case MONTH:
	  /* Month */
	  /*	  BUFSET(0);*/
	  /*	  field_buf = buf + field_positions[state_pos];*/
	  switch(bufpos - field_position)
	  {
	   case 2:
	    tmpinteger = 0;
	    for(v = field_position; v < bufpos; v++) {
	      if(char_class[buf[v]] == CLS_DIGIT)
		tmpinteger = tmpinteger*10 + (buf[v]&0xf);
	      else {
		goto skip;
	      }
	    }
	    break;

	   case 3:
	    switch(((buf[field_position]|0x20)<<16)|((buf[field_position+1]|0x20)<<8)|
		   (buf[field_position+2]|0x20))
	    {
	     case ('j'<<16)|('a'<<8)|'n': tmpinteger = 1;   break;
	     case ('f'<<16)|('e'<<8)|'b': tmpinteger = 2;   break;
	     case ('m'<<16)|('a'<<8)|'r': tmpinteger = 3;   break;
	     case ('a'<<16)|('p'<<8)|'r': tmpinteger = 4;   break;
	     case ('m'<<16)|('a'<<8)|'y': tmpinteger = 5;   break;
	     case ('j'<<16)|('u'<<8)|'n': tmpinteger = 6;   break;
	     case ('j'<<16)|('u'<<8)|'l': tmpinteger = 7;   break;
	     case ('a'<<16)|('u'<<8)|'g': tmpinteger = 8;   break;
	     case ('s'<<16)|('e'<<8)|'p': tmpinteger = 9;   break;
	     case ('o'<<16)|('c'<<8)|'t': tmpinteger = 10;  break;
	     case ('n'<<16)|('o'<<8)|'v': tmpinteger = 11;  break;
	     case ('d'<<16)|('e'<<8)|'c': tmpinteger = 12;  break;
	    }
	    break;

	   default:
	    goto skip;
	  }
	  /*printf("Month: %0d\n", mm);*/

	  if(tmpinteger < 1 || tmpinteger > 12)
	    goto skip; /* Broken Month */
	  BUFPOINT = tmpinteger;
	  /*	  bufpos++;*/
	  break;
	  
	 case ADDR:
	 case REFER:
	 case AGENT:
	 case TZ:
	 case METHOD:
	 case URL:
	 case RFC:
	 case PROTO:
	  BUFSET(0);
	  SETPOINT();
	  /*	  printf("Field %d, pos %d, %s\n", save_field_num[state_pos],BUFPOINT,*/
	  /*		 buf + BUFPOINT);	 */
	  break;
	  
	}	  
	state_pos++;
	field_position = bufpos;
	if(cls != CLS_CRLF)		  
	  continue;
      } else if(cls != CLS_CRLF) {
	BUFSET(c);
	continue;
      } else {
	/*	printf("Processing last field (%d).\n", state_pos);*/
	goto process_field; /* End of line - process what we got */
      }
      /*	printf("%d %d\n", state_pos, num_states);*/
      /*      buf_points[8] = buf_points[9] = buf_points[10] = buf_points[11] = buf;*/
      /*      buf_points[12] = buf_points[13] = buf_points[14] = buf_points[15] = buf;*/
#if 0
      if(!((lines+broken_lines)%100000)) {
	push_int(lines+broken_lines);
	push_int((int)((float)offs0/1024.0/1024.0));
	apply_svalue(statfun, 2);
	pop_stack();
	/*printf("%5dk lines, %5d MB\n", lines/1000, (int)((float)offs0/1024.0/1024.0));*/
      }
#endif
      if(state_pos < num_states)
      {
#ifdef BROKEN_LINE_DEBUG
	broken_line[broken_line_pos] = 0;
	printf("too few states (pos=%d): %s\n", state_pos, broken_line);
#endif
	broken_lines++;
	goto ok;
      }
      
#define yy 	buf_points[YEAR] 
#define mm 	buf_points[MONTH] 
#define dd 	buf_points[DATE] 
#define h  	buf_points[HOUR] 
#define m  	buf_points[MINUTE] 
#define s  	buf_points[UP_SEC] 
#define v  	buf_points[CODE] 
#define bytes	buf_points[BYTES] 

      this_date = (yy*10000) + (mm*100) + dd;
      if(!this_date) {
	broken_lines++;
	goto ok;
      }
#if 1
      if(!last_date) { /* First loop w/o a value.*/
	last_date = this_date;
	last_hour = h;
      } else {
	if(last_hour != h ||
	   last_date != this_date)
	{
	  pages_per_hour[last_hour] +=
	    hourly_page_hits(hits20x, pages, hits, pagexts->u.multiset, 200);
	  /*	    pages_per_hour[last_hour] +=*/
	  /*	      hourly_page_hits(hits304, pages, hits, pagexts->u.multiset, 300);*/
	  
	  /*	    printf("%5d %5d for %d %02d:00\n",*/
	  /*		   pages_per_hour[last_hour], hits_per_hour[last_hour],*/
	  /*last_date, last_hour);*/
	  if(m_sizeof(session_start)) {
	    summarize_sessions(last_hour, sessions_per_hour,
			       session_length, session_start, session_end);
	    free_mapping(session_start); 
	    free_mapping(session_end); 
	    session_start = allocate_mapping(1);
	    session_end   = allocate_mapping(1);
	  }
	  hosts_per_hour[last_hour] += m_sizeof(sites);
	  do_map_addition(hosts, sites);
	  free_mapping(sites);
	  sites = allocate_mapping(100);
	  last_hour = h;
	  free_mapping(hits20x); /* Reset this one */
	  /*	    free_mapping(hits304);  Reset this one */
	  /*	    hits304   = allocate_mapping(2);*/
	  hits20x   = allocate_mapping(2);
	}
#if 1
	if(last_date != this_date) {
	  /*	  printf("%d   %d\n", last_date, this_date);*/
	  tmpdest = allocate_mapping(1);
	  summarize_refsites(refsites, referrers, tmpdest);
	  free_mapping(referrers);
	  referrers = tmpdest;

	  tmpdest = allocate_mapping(1);
	  clean_refto(referredto, tmpdest, pagexts->u.multiset);
	  free_mapping(referredto);
	  referredto = tmpdest;
	  
	  summarize_directories(directories, pages);
	  summarize_directories(directories, hits);

	  tmpdest = allocate_mapping(1);
	  http_decode_mapping(user_agents, tmpdest);
	  free_mapping(user_agents);
	  user_agents = tmpdest;

	  tmpdest = allocate_mapping(1);
	  summarize_hosts(hosts, domains, topdomains, tmpdest);
	  free_mapping(hosts);
	  hosts = tmpdest;
#if 1
	  push_int(last_date / 10000);
	  push_int((last_date % 10000)/100);
	  push_int((last_date % 10000)%100);
	  push_mapping(pages);
	  push_mapping(hits);
	  push_mapping(hits302);
	  push_mapping(hits_per_error);
	  push_mapping(error_urls);
	  push_mapping(error_refs);
	  push_mapping(referredto);
	  push_mapping(refsites); 
	  push_mapping(referrers); 
	  push_mapping(directories); 
	  push_mapping(user_agents); 
	  push_mapping(hosts); 
	  push_mapping(domains); 
	  push_mapping(topdomains); 
	  for(i = 0; i < 24; i++) {
	    push_int(sessions_per_hour[i]);
	  }
	  f_aggregate(24);
	  for(i = 0; i < 24; i++) {
	    push_int(hits_per_hour[i]);
	    hits_per_hour[i] = 0;
	  }
	  f_aggregate(24);
	  for(i = 0; i < 24; i++) {
	    push_int(pages_per_hour[i]);
	    pages_per_hour[i] = 0;
	  }
	  f_aggregate(24);
	  for(i = 0; i < 24; i++) {
	    /* KB per hour.*/
	    push_float(kb_per_hour[i]);
	    kb_per_hour[i] = 0.0;
	  }
	  f_aggregate(24);
	  for(i = 0; i < 24; i++) {
	    push_float(sessions_per_hour[i] ?
		       ((float)session_length[i] /
			(float)sessions_per_hour[i]) / 60.0 : 0.0);
	    sessions_per_hour[i] = 0;
	    session_length[i] = 0;
	  }
	  f_aggregate(24);
	  for(i = 0; i < 24; i++) {
	    push_int(hosts_per_hour[i]);
	    hosts_per_hour[i] = 0;
	  }
	  f_aggregate(24);
	  apply_svalue(daily, 23);
	  pop_stack();
#else
	  free_mapping(error_refs);
	  free_mapping(referredto); 
	  free_mapping(refsites); 
	  free_mapping(directories); 
	  free_mapping(error_urls);
	  free_mapping(hits);
	  free_mapping(hits_per_error);
	  free_mapping(pages);
	  free_mapping(hosts);
	  free_mapping(domains);
	  free_mapping(topdomains);
	  free_mapping(referrers); 
	  free_mapping(hits302);
#endif
	  user_agents 	 = allocate_mapping(10);
	  hits302 	 = allocate_mapping(1);
	  hits_per_error = allocate_mapping(10);
	  error_urls     = allocate_mapping(10);
	  error_refs     = allocate_mapping(10);
	  directories    = allocate_mapping(20);
	  referrers      = allocate_mapping(1);
	  referredto     = allocate_mapping(1);
	  refsites       = allocate_mapping(1);
	  pages  	 = allocate_mapping(1);
	  hits 	         = allocate_mapping(1);
	  sites	         = allocate_mapping(1);
	  hosts	         = allocate_mapping(1);
	  domains	 = allocate_mapping(1);
	  topdomains     = allocate_mapping(1);
	  last_date = this_date;
	}
#endif
      }
#endif
#if 1
      process_session(buf+buf_points[ADDR], h*3600+m*60+s, h, 
		      sessions_per_hour, session_length, session_start,
		      session_end, sites);
      url_str = make_shared_binary_string((char *)(buf + buf_points[URL]),
					  strlen((char *)(buf + buf_points[URL])));
#if 1
      switch(v) {
      /* Do error-code specific logging. Error urls that are
	   specially treated do not include auth required, service
	   unavailable etc. They are only included in the return
	   code summary.
	*/
       case 200: case 201: case 202: case 203: 
       case 204: case 205: case 206: case 207:
       case 304:
	mapaddstr(hits20x, url_str);
	DO_REFERRER();
	break;

       case 300: case 301: case 302:
       case 303: case 305:
	mapaddstr(hits302, url_str);
	DO_REFERRER();
	break;

       case 400: case 404: case 405: case 406: case 408:
       case 409: case 410: case 411: case 412: case 413:
       case 414: case 415: case 416: case 500: case 501:
	DO_ERREF();
	map2addint(error_urls, v, url_str);
	break;
      }
      /*rfc_str = http_decode_string(buf + buf_points[RFC]);*/
      /*hst_str = make_shared_binary_string(buf, strlen(buf));*/
#endif	
      free_string(url_str);
      mapaddint(hits_per_error, v);
      kb_per_hour[h] += (float)bytes / 1024.0;
      hits_per_hour[h]++;
      /*#endif*/
      if(strlen((char *)(buf + buf_points[AGENT]))>1) {
	/* Got User Agent */
	tmpagent = make_shared_string((char *)(buf + buf_points[AGENT]));
	mapaddstr(user_agents, tmpagent);
	free_string(tmpagent);
      }
#endif
      lines++;
#if 0
      printf("%s  %s  %s\n%s  %s  %s\n%04d-%02d-%02d  %02d:%02d:%02d  \n%d   %d\n",
	     buf + buf_points[ADDR], buf + buf_points[REFER], buf + buf_points[ RFC ],
	     buf + buf_points[METHOD], buf + buf_points[ URL ], buf + buf_points[PROTO],
	     yy, mm, dd, h, m, s, v, bytes);
      /*      if(lines > 10)
	      exit(0);*/
#endif
    ok:
      gotdate = /* v = bytes =h = m = s = tz = tzs = dd = mm = yy =  */
	buf_points[0] = buf_points[1] = buf_points[2] = buf_points[3] = 
	buf_points[4] = buf_points[5] = buf_points[6] = buf_points[7] = 
	/*buf_points[8] = buf_points[9] = buf_points[10] =*/
	buf_points[11] = 
	buf_points[12] = buf_points[13] = buf_points[14] = buf_points[15] = 
	bufpos = state_pos = 0;
      field_position = 1;
#ifdef BROKEN_LINE_DEBUG
      broken_line_pos = 0;
#endif
      BUFSET(0);
      
    }    
  }  
 cleanup:
  free(save_field_num);
  free(state_list);
  free(field_endings);
  free(buf);
  push_int(lines);
  push_int((int)((float)offs0 / 1024.0/1024.0));
  push_int(1);
  apply_svalue(statfun, 3);
  pop_stack();
  free(read_buf);
#ifdef BROKEN_LINE_DEBUG
  free(broken_line);
#endif
  if(my_fd)
    /* If my_fd == 0, the second argument was an object and thus we don't
     * want to free it.
     */
    fd_close(f);
  /*  push_int(offs0);  */
  /*  printf("Done: %d %d %d ", yy, mm, dd);*/
  if(yy && mm && dd) { 
    /*    printf("\nLast Summary for %d-%02d-%02d %02d:%02d\n", yy, mm, dd, h, m);*/
    pages_per_hour[last_hour] += 
      hourly_page_hits(hits20x, pages, hits, pagexts->u.multiset, 200);
    if(m_sizeof(session_start)) {
      summarize_sessions(last_hour, sessions_per_hour,
			 session_length, session_start, session_end);
    }
    hosts_per_hour[last_hour] += m_sizeof(sites);
    do_map_addition(hosts, sites);
    free_mapping(sites);
	  
    tmpdest = allocate_mapping(1);
    summarize_refsites(refsites, referrers, tmpdest);
    free_mapping(referrers);
    referrers = tmpdest;
    summarize_directories(directories, pages);
    summarize_directories(directories, hits);
    tmpdest = allocate_mapping(1);
    clean_refto(referredto, tmpdest, pagexts->u.multiset);
    free_mapping(referredto);
    referredto = tmpdest;

    tmpdest = allocate_mapping(1);
    http_decode_mapping(user_agents, tmpdest);
    free_mapping(user_agents);
    user_agents = tmpdest;

    tmpdest = allocate_mapping(1);
    summarize_hosts(hosts, domains, topdomains, tmpdest);
    free_mapping(hosts);
    hosts = tmpdest;

    push_int(yy);
    push_int(mm);
    push_int(dd);
    push_mapping(pages);
    push_mapping(hits);
    push_mapping(hits302);
    push_mapping(hits_per_error);
    push_mapping(error_urls);
    push_mapping(error_refs);
    push_mapping(referredto); 
    push_mapping(refsites); 
    push_mapping(referrers); 
    push_mapping(directories); 
    push_mapping(user_agents); 
    push_mapping(hosts); 
    push_mapping(domains); 
    push_mapping(topdomains); 

    for(i = 0; i < 24; i++) {  push_int(sessions_per_hour[i]);  }
    f_aggregate(24);

    for(i = 0; i < 24; i++) {  push_int(hits_per_hour[i]);      }
    f_aggregate(24);

    for(i = 0; i < 24; i++) {  push_int(pages_per_hour[i]);     }
    f_aggregate(24);
    
    for(i = 0; i < 24; i++) {  push_float(kb_per_hour[i]);      }
    f_aggregate(24);

    for(i = 0; i < 24; i++) {
      push_float(sessions_per_hour[i] ?
		 ((float)session_length[i] /
		  (float)sessions_per_hour[i]) / 60.0 : 0.0);
    }
    f_aggregate(24);

    for(i = 0; i < 24; i++) {
      push_int(hosts_per_hour[i]);
      hosts_per_hour[i] = 0;
    }
    f_aggregate(24);

    apply_svalue(daily, 23);
    pop_stack();
  } else {
    free_mapping(error_refs);
    free_mapping(referredto); 
    free_mapping(refsites); 
    free_mapping(directories); 
    free_mapping(error_urls);
    free_mapping(hits);
    free_mapping(hits_per_error);
    free_mapping(pages);
    free_mapping(referrers); 
    free_mapping(hits302); 
    free_mapping(user_agents); 
    free_mapping(hosts);
    free_mapping(domains);
    free_mapping(topdomains);
  }
  free_mapping(hits20x); 
  free_mapping(session_start); 
  free_mapping(session_end); 
  /*  free_mapping(hits30x); */
  printf("\nTotal lines: %d, broken lines: %d, mapping lookups: %d\n\n", lines,
	 broken_lines, lmu);
  fflush(stdout);
  pop_n_elems(args);  
  push_int(offs0);
  return; 
      
 skip:
  broken_lines++;
  while(1) 
  {
    while(len--) {
#ifdef BROKEN_LINE_DEBUG
      broken_line[broken_line_pos] = char_pointer[-len];
#endif
      if(char_class[char_pointer[-len]] == CLS_CRLF) {
#ifdef BROKEN_LINE_DEBUG
	broken_line[broken_line_pos] = 0;
	printf("Broken Line (pos=%d): %s\n", state_pos, broken_line);
#endif
	goto ok;
      }
    }
    do {
      len = fd_read(f, read_buf, READ_BLOCK_SIZE);
    } while(len < 0 && errno == EINTR);
    if(len <= 0)
      break; /* nothing more to read. */
    offs0 += len;
    char_pointer = read_buf+len - 1;
  }
  goto cleanup;
}
Ejemplo n.º 30
0
/*
 * Split a unquoted string around whitespace produced by parameter
 * expansion.
 *
 * @s:               The string to split. It will be freed or transferred
 *                   to @out_list.
 *
 * @out_list:        An empty list into which the split strings will be written.
 *                   If the string is empty or is entirely whitespace produced
 *                   by parameter expansion, then the resulting list will remain
 *                   empty.  Otherwise, the string will have one or more strings
 *                   written to it, and they will have the same flags as the
 *                   original string except for the following exceptions:
 *                         All strings except the first will have
 *                         STRING_FLAG_PRECEDING_WHITESPACE set.  The first will
 *                         have STRING_FLAG_PRECEDING_WHITESPACE set if and only
 *                         if @leading_whitespace is set to %true.
 *
 * @param_char_map:  A map from character position to booleans
 *                   that indicate whether the character was produced by
 *                   parameter expansion (1) or not (0).  NULL indicates that
 *                   all characters were produced by parameter or alias
 *                   expansion.
 *
 * Returns %true if the string has trailing whitespace that was produced by
 * parameter expansion; %false otherwise.
 */
static bool
split_string_around_whitespace(struct string *s, struct list_head *out_list,
			       const unsigned char *param_char_map)
{
	const char *chars;
	struct string *s2;
	size_t i;
	bool leading_whitespace = false;
	bool trailing_whitespace = false;

	chars = s->chars;
	i = 0;
	for (;;) {
		/* skip leading whitespace produced by parameter expansion  */
		size_t j = i;
		while (isspace(chars[i]) &&
		       (!param_char_map || param_char_map[i] != 0))
		{
			if (i == 0)
				leading_whitespace = true;
			i++;
		}

		if (chars[i] == '\0') {
			/* end of string: set trailing_whitespace if there was
			 * at least 1 parameter-expanded whitespace character at
			 * the end of the string.  Also, free @s before
			 * returning, since it's no longer needed. */
			trailing_whitespace = (i != j);
			free_string(s);
			break;
		}
		/* j is set the index of the next character that is not a
		 * parameter-expanded whitespace character */
		j = i;

		/* skip non-whitespace and whitespace not produced by parameter
		 * expansion */
		while (chars[i] != '\0' &&
		       (!isspace(chars[i]) || (param_char_map && !param_char_map[i])))
		{
			i++;
		}

		if (j == 0 && i == s->len) {
			/* Add entire string and return. */
			list_add_tail(&s->list, out_list);
			trailing_whitespace = false;
			break;
		} else {
			/* Create a new substring and append it to the list of
			 * split strings.
			 *
			 * STRING_FLAG_PRECEDING_WHITESPACE is set unless the
			 * substring occurs at the very beginning of the
			 * original string with no preceding whitespace. */
			s2 = new_string_with_data(&chars[j], i - j);
			s2->flags = s->flags;
			if (i != 0 || leading_whitespace)
				s2->flags |= STRING_FLAG_PRECEDING_WHITESPACE;
			list_add_tail(&s2->list, out_list);
		}
	}
	return trailing_whitespace;
}