Exemple #1
0
int vph_read_string(FILE *f,char *s)
{
	int cnt,i,err;
	char shortstr[2]=" ";
	int length;
	
	assert(f);
	assert(s);
	
	err = vph_read_int(f,&length);			
	if (err != 0)
		{
			log_output(vphlog,"Failure to read string length");
			return 1;
		}
	if (length==0)
		log_output(vphlog,"[string has zero length]");
	s[0] = 0;
	for (i=0; i<length; i++)
		{
			cnt = fread(shortstr,1,1,f);
			if (cnt != 1)
				{
					log_output(vphlog,"Failure to read string body (%s)", s);
					return 1;
				}
			strcat(s, shortstr);
		}
	return 0;
}
/**
 * send a command to the device
 * 
 * \param conn the connection to the device
 * \param command the command to send
 * \return 0 on success, -1 else. errno will be set accordingly
 */
int sendCommand(struct USBConnection *conn, unsigned char command)
{
    if (conn != NULL) {
        if (write(conn->fd, &command, 1) != 1) {
            log_output(LOG_ERR, "Could not write to device. %s\n", strerror(errno));
            return -1;
        }
        return 0;
    }
    log_output(LOG_ERR, "Write to device failed. Connection is invalid.\n");
    return -1;
}
Exemple #3
0
struct queue *service_dispatch(struct monitor *monitor, struct queue *q) {
	if (!q) {
		q = worker_queue_pop();
		if (!q) return 0;
	}

	uint32_t handle = queue_handle(q);
	struct service *s = service_grab(handle);
	if (!s) {
		queue_release(q, queue_message_dtor, (void *)(uintptr_t)handle);
		return worker_queue_pop();
	}
	struct message m;
	if (!queue_pop(q, &m)) {
		service_release(handle);
		return worker_queue_pop();
	}
	int overload = queue_overload(q);
	if (overload)
		service_log(handle, "service may overload, message queue length = %d\n", overload);
	monitor_trigger(monitor, m.source, handle);
	if (s->logfile)
		log_output(s->logfile, &m);
	s->module.dispatch(s->handle, s->ud, &m);
	service_alloc(m.data, 0);
	monitor_trigger(monitor, 0, 0);
	struct queue *next = worker_queue_pop();
	if (next) {
		worker_queue_push(q);
		q = next;
	}
	service_release(handle);
	return q;
}
Exemple #4
0
void vph_report_float_array(float *array, int length)
{
	int i;

	assert(array);
	assert(length>0);
	for (i=0; i<=length-ROWLENGTH; i+=ROWLENGTH)
		{
			log_output(vphlog," %f %f %f",array[i],array[i+1],array[i+2]);
		}
	i=length%ROWLENGTH;
	switch (i)
	{
		case (0): break;
		case (1): log_output(vphlog," %f",array[i]); break;
		case (2): log_output(vphlog," %f %f",array[i],array[i+1]); break;
		default : assert(0);
	}
}
void executeProgram(char *program, struct SystemState *state)
{
    pid_t child;
    if (state != NULL) {
        child = fork();
        if (child == 0) {
            setEnvList("UVR_INPUT", state->inputs);
            setEnvList("UVR_OUTPUT", state->outputs);
            setEnvList("UVR_HEATREG", state->heatRegisters);
            log_output(LOG_DEBUG, "Executing %s\n", program);
            system(program);
            log_output(LOG_DEBUG, "%s finished\n", program);
            exit(0);
        }
        else {
            waitpid(child, NULL, 0); // sleep until the child returns
            log_output(LOG_DEBUG, "Child returned\n");
        }
    }
}
/**
 * read a set of data into the buffer. This function reads as long as the buffer
 * is not filled to the amount needed or an error occurs.
 * 
 * \return the number of bytes read on success, <0 else. errno will be set accordingly
 */
int readBuffer(struct USBConnection *conn, unsigned char *buffer)
{
    int ret = 0;
    int numBytes = 0;
    int bytesToRead = 115;
    while (bytesToRead != numBytes) {
        ret = read(conn->fd, buffer+numBytes, bytesToRead-numBytes); // 115 would be if two UVR1611 are connected
        if (ret <= 0) {
            return ret;
        }
        numBytes += ret;
        switch (buffer[0]) {
            case GET_CURRENT_DATA:
                // this means that we don't have new data
                log_output(LOG_DEBUG, "No new data currently. (read %d bytes)\n", ret);
                errno = EAGAIN;
                return -1;
            case UVR1611:
                switch (conn->uvr_mode) {
                    case 0xA8:
                        if (bytesToRead == 115) {
                            bytesToRead = 57; // 57 bytes are to be read in this mode
                        }
                        break;
                    default:
                        log_output(LOG_ERR, "Unsupported mode %x\n", conn->uvr_mode);
                        errno = EINVAL;
                        return -1;
                }
                break;
            default:
                log_output(LOG_ERR, "Unsupported device %x\n", buffer[0]);
                errno = EINVAL;
                return -1;
        }
    }
    return numBytes;
}
Exemple #7
0
int vphmain( const char* vphfile, const char* outfile )
{
	FILE *f;
	int err;

	vphlog = log_open(outfile);
	if (vphlog == NULL)
		{
			printf("VPH -- Failure to open output log %s\n",outfile);
			return 1;
		}

	f = fopen(vphfile,"rb");
	if (f==NULL)
		{
			log_output(vphlog,"VPH: cant open input file%s\n",vphfile);
			log_close(&vphlog);
			return 1;
		}	
	
	log_output(vphlog,"VPH SCANNER:  file=%s",vphfile);

	err = vph_parse(f);
	if (err != 0)
		{
			log_output(vphlog,"vph_parse() returned an error %d",err);
		}

	if (fclose(f)!=0)
		{
			log_output(vphlog,"PATHENV: couldn't close output file %s\n",vphfile);
			log_close(&vphlog);
			return 1;
		}
	log_close(&vphlog);

	return 0;
}			
Exemple #8
0
void main()
{
//	WDTCTL = WDTPW + WDTHOLD;
    wdt_set_timeout_to_3p2s();
    wdt_set_enable(1);
    log_init_op(3);
    log_output("//Program Begin!!!\r\n");
     while(1)
     {
    	 wdt_keep_alive();
      __delay_cycles(1048576*4);
     }
       
}
Exemple #9
0
static void
tracker_log_handler (const gchar    *domain,
                     GLogLevelFlags  log_level,
                     const gchar    *message,
                     gpointer        user_data)
{
	/* Unless enabled, we don't log to file by default */
	if (use_log_files) {
		log_output (domain, log_level, message);
	}

	/* Now show the message through stdout/stderr as usual */
	g_log_default_handler (domain, log_level, message, user_data);
}
int
d_undead_lord(struct command *c)
{
	int where = subloc(c->who);
	int aura = c->a;
	int undead;
	int ret;
	int rating;

	if (!may_cookie_npc(c->who, where, item_undead_cookie))
		return FALSE;

	if (!charge_aura(c->who, aura))
		return FALSE;

	undead = do_cookie_npc(c->who, where, item_undead_cookie, c->who);

	if (undead == 0)
	{
		log_output(LOG_CODE, "d_undead_lord: why not?");
		wout(c->who, "Unable to summon a demon lord.");
		return FALSE;
	}

	switch (aura)
	{
	case 3:		rating = 100;	break;
	case 4:		rating = 150;	break;
	case 5:		rating = 190;	break;
	case 6:		rating = 220;	break;
	case 7:		rating = 240;	break;
	case 8:		rating = 250;	break;

	default:
		assert(FALSE);
	}

	p_char(undead)->attack = rating;
	p_char(undead)->defense = rating;

	set_loyal(undead, LOY_summon, 5);

	wout(c->who, "Summoned %s.", box_name(undead));
	wout(where, "%s has summoned %s.",
				box_name(c->who),
				liner_desc(undead));

	return TRUE;
}
void __libc_free(void* p)
{
    if (!origin_libc_free) {
        load_libc_free();
    }

    origin_libc_free(p);
    if (depth > 0|| malloc_wapper_logfd == -1) {
        return;
    }

    ++depth;
    log_output(is_out_free_bt, &loghead_build_libc_free, p, 0);
    --depth;
}
Exemple #12
0
/*
 * Log <fmt> and the subsequent parameters through <logger>, *without* any
 * prefixes. Useful to continue a previous log message.
 */
void logAppend(Logger *logger, const char *fmt, ...)
{
    va_list ap;

    pthread_mutex_lock(&logger->access);

    bufClear(&logger->scratch);

    va_start(ap, fmt);
    bufAddV(&logger->scratch, fmt, ap);
    va_end(ap);

    log_output(logger);

    pthread_mutex_unlock(&logger->access);
}
void* __libc_malloc(size_t size)
{
    if (!origin_libc_malloc) {
        load_libc_malloc();
    }

    void* result = origin_libc_malloc(size);
    if (depth > 0|| malloc_wapper_logfd == -1) {
        return result;
    }

    ++depth;
    log_output(1, &loghead_build_libc_malloc, result, size);
    --depth;

    return result;
}
Exemple #14
0
/*
 * Send out a logging message using <fmt> and the subsequent parameters through
 * <logger>. <file>, <line> and <func> are filled in by the logWrite macro,
 * which should be used to call this function.
 */
void _logWrite(Logger *logger,
        const char *file, int line, const char *func, const char *fmt, ...)
{
    va_list ap;

    pthread_mutex_lock(&logger->access);

    bufClear(&logger->scratch);

    log_write_prefixes(logger, file, line, func);

    va_start(ap, fmt);
    bufAddV(&logger->scratch, fmt, ap);
    va_end(ap);

    log_output(logger);

    pthread_mutex_unlock(&logger->access);
}
Exemple #15
0
int main(int argc, const char* argv[]){
	if ( argc != 2 ){
		fprintf(stderr,
		        "usage: %s FILENAME\n"
		        "       %s - > FILENAME\n"
		        "\n"
		        "First form read FILENAME as input and tries to read it as an IPC command.\n"
		        "Second form generates a sample IPC command (machine specific) and writes on stdout.\n"
		        , argv[0], argv[0]);
		return 1;
	}

	log_output(output);

	if ( argv[1][0] != '-' ){
		read_ipc(argv[1]);
	} else {
		write_ipc();
	}

	return 0;
}
/**
 * read the current data values from the device
 * 
 * \return a pointer to the sensor list on success, NULL otherwise. errno will be set accordingly.
 * \note if the sensor list is no longer needed, release it using freeSensorList()
 */
struct SystemState *readCurrentData(struct USBConnection *conn)
{
    int ret;
    unsigned char databuffer[116]; // according to the specification there might be 115 bytes max
    if (conn == 0 || !conn->_success) {
        errno = EINVAL;
        return NULL;
    }
    sendCommand(conn, GET_CURRENT_DATA);
    // depending on the number of bytes read, different results are to be expected
    ret = readBuffer(conn, databuffer);
    if (ret > 0) {
        log_output(LOG_DEBUG, "Read buffer of size: %d\n", ret);
        switch(databuffer[0]) {
            case UVR1611:
                return parseUVR1611(databuffer);
            default:
                return NULL;
                break;
        }
    }
    return NULL;
}
Exemple #17
0
void daemonize()
{
    pid_t pid = fork();
    if (pid > 0) {
        // we're in the parent process -> exit
        exit(0);
    }
    // standard UNIX daemon setup
    umask(0);
    pid_t sid = setsid();
    if (sid < 0) {
        fprintf(stderr, "Could not get new session id");
        exit(-1);
    }
    if ((chdir("/")) < 0) {
        fprintf(stderr, "Could not change directory to /");
        exit(-1);
    }
    log_output(LOG_DEBUG, "Sucessfully daemonized reader.\n");
    // close STDIO
    close(STDIN_FILENO);
    close(STDOUT_FILENO);
    close(STDERR_FILENO);
}
Exemple #18
0
static STATUS_E bootrom_stage(COM_HANDLE com_handle,
                                const struct image *download_agent,
                                const struct image *download_agent_TCM,
                                const struct image *download_EPP,
                                const ExternalMemorySetting *externalMemorySetting,
                                int isUSB, int isNFB)
{
    STATUS_E status;
    unsigned int response;
    unsigned int size = 0;

    log_output("Connecting to BootROM... com_handle(%d)\n", com_handle);
    status = bootrom_connect(com_handle);


    if (status != S_DONE)
    {
        log_output("FAIL:Connecting to BoortRom... handle port (%d)\n",com_handle);
        log_feedback("FAIL:Connecting to BoortRom... handle port (%d)\n",com_handle);    
        return status;
    }
    log_output("SUCCESS:Connecting to BoortRom... handle port (%d)\n",com_handle);
    log_feedback("SUCCESS:Connecting to BoortRom... handle port (%d)\n",com_handle);    

    //Todo: detect bootROM connection or bootloader connection
    //Use BROM USB below
#if defined(_MSC_VER)
    if (com_change_timeout(com_handle, 500, 5000))
    {
        return S_COM_PORT_SET_TIMEOUT_FAIL;
    }
#endif


    log_output("Disabling watchdog..\n");

    status = bootrom_disable_watchdog(com_handle);
    if (status != S_DONE)
    {
        if (com_recv_dword(com_handle, &response) != COM_STATUS_DONE)
        {
            log_output("FAIL:Disabling watchdog..\n");
            log_feedback("FAIL:Disabling watchdog..\n");    
            return status;
        }
    }
    log_output("SUCCESS:Disabling watchdog..\n");
    log_feedback("SUCCESS:Disabling watchdog..\n");    


    log_output("Latching powerkey...\n");
    status = bootrom_latch_powerkey(com_handle);
    if (status != S_DONE)
    {
        log_output("FAIL:Latching powerkey...\n");
        log_feedback("FAIL:Latching powerkey...\n");    
        return status;
    }
    log_output("SUCCESS:Latching powerkey...\n");
    log_feedback("SUCCESS:Latching powerkey...\n");    

    //SetRemap for BROM
    log_output("Set Remap...\n");
    status = bootrom_SetRemap(com_handle);
    if (status != S_DONE)
    {
        log_output("FAIL:Set Remap...\n");
        log_feedback("FAIL:Set Remap...\n");    
        return status;
    }
    log_output("SUCCESS:Set Remap...\n");
    log_feedback("SUCCESS:Set Remap...\n");    

    log_output("Send EPP...\n");
    status = bootrom_SendEPP(com_handle, download_EPP, externalMemorySetting);
    if (status != S_DONE)
    {
        log_output("FAIL:Send EPP...\n");
        log_feedback("FAIL:Send EPP...\n");    
        return status;
    }
    log_output("SUCCESS:Send EPP...\n");
    log_feedback("SUCCESS:Send EPP...\n");

    log_output("Sending DA1...\n");
    status = bootrom_send_download_agent(com_handle, download_agent, isUSB);
    if (status != S_DONE)
    {
        log_output("FAIL:Sending DA1...\n");
        log_feedback("FAIL:Sending DA1...\n");    
        return status;
    }
    log_output("SUCCESS:Sending DA1...\n");
    log_feedback("SUCCESS:Sending DA1...\n");    

    if(download_agent_TCM->buf != NULL)
    {
        log_output("Sending DA2...\n");
        status = bootrom_send_download_agent(com_handle, download_agent_TCM, isUSB);
        if (status != S_DONE)
        {
            log_output("FAIL:Sending DA2...\n");
            log_feedback("FAIL:Sending DA2...\n");    
            return status;
        }
        log_output("SUCCESS:Sending DA2...\n");
        log_feedback("SUCCESS:Sending DA2...\n");    
    }

    log_output("Transferring control to DA...\n");
    status = bootrom_jump_to_download_agent(com_handle, download_agent);
    if (status != S_DONE)
    {
        log_output("FAIL:Transferring control to DA...\n");
        log_feedback("FAIL:Transferring control to DA...\n");    
        return status;
    }
    log_output("SUCCESS:Transferring control to DA...\n");
    log_feedback("SUCCESS:Transferring control to DA...\n");    

    return S_DONE;
}
Exemple #19
0
STATUS_E download_images(const struct image *download_agent,
                         const struct image *download_agent_TCM,
                         const struct image *nor_flash_table,
                         const struct image *nand_flash_table,
                         const struct image *download_EPP,
                         const struct image *bootLoader,
                         const struct image *extBootLoader,
                         const struct image *dspBootLoader,
                         const struct image *rom,
                         const struct image *secondRom,
                         const struct image *dspRom,
                         const struct image *demand_paging_rom,
                         struct image *linux_images,
                         const struct ExternalMemorySetting *externalMemorySetting,
                         unsigned int num_linux_images,
                         unsigned int bmt_address,
                         int isUSB,
                         int isNFB)
{

    COM_HANDLE com_handle = INVALID_COM_HANDLE;
    STATUS_E status;

    if(isUSB){
        int retry = 0;

        while(1)
        {
            Sleep(100);
            //if (com_open(&com_handle, 19200) == COM_STATUS_DONE)
            if (com_open(&com_handle, 115200) == COM_STATUS_DONE)
            {
                log_output("handle (%d)\n", com_handle);
                log_feedback("SUCCESS:handle port (%d)\n",com_handle);
                break;
            }else{
                log_output("faile handle (%d)\n", com_handle);
                log_feedback("FAIL:handle port (%d)\n",com_handle);
                com_close(&com_handle);
                if (++retry > 10)
                    return S_COM_PORT_OPEN_FAIL;
            }
        }

    }else{
        if (com_open(&com_handle, 115200) != COM_STATUS_DONE)
        {
            log_output("Failed to open the communication port\n");
            return S_COM_PORT_OPEN_FAIL;
        }
    }


    status = bootrom_stage(com_handle, download_agent,download_agent_TCM, download_EPP, externalMemorySetting, isUSB, isNFB);

    if (status != S_DONE)
    {
            log_output("Download failed in BootROM stage: error=%u\n", status);
            //com_close(&com_handle);
            return status;
    }

    status = da_stage(com_handle, nor_flash_table, nand_flash_table,
        bootLoader,extBootLoader,dspBootLoader, rom, secondRom, dspRom, demand_paging_rom,
        linux_images,
        num_linux_images,
        isUSB,
        isNFB,
        bmt_address);

    if (status != S_DONE)
    {
        log_output("Download failed in DA stage: error=%u\n", status);
        //com_close(&com_handle);
        //Sleep(5000);
        return status;
    }
    
    log_feedback("FINISHED UPDATE");
    log_output("FINISHED UPDATAE!\n");

    if (com_close(&com_handle) != COM_STATUS_DONE)
    {
        log_output("Failed to close the communication port\n");
        //Sleep(5000);
    }
    //Sleep(5000);

    return S_DONE;
}
Exemple #20
0
static STATUS_E da_stage(COM_HANDLE com_handle,
                         const struct image *nor_flash_table,
                         const struct image *nand_flash_table,
                         const struct image *bootLoader,
             const struct image *extBootLoader,
             const struct image *dspBootLoader,
             const struct image *rom,
                         const struct image *secondRom,
             const struct image *dspRom,
             const struct image *demand_paging_rom,
             struct image *linux_images,
             unsigned int num_linux_images,
             int isUSB,
             int isNFB,
             unsigned int bmt_address)
{
    STATUS_E status;

    // To enable hardware flow contrl, you have to
    // (1) properly configure CTS/RTS of the target hardware,
    // (2) use hardware-flow-control-enabled Download Agent, and
    // (3) uncomment the following lines

    //if (com_enable_hardware_flow_control(com_handle) != COM_STATUS_DONE)
    //{
    //    log_output("Failed to enable HW flow control "
    //               "on the communication port\n");
    //    return S_UNDEFINED_ERROR;
    //}

    unsigned char response = 0;
    unsigned int errorCode =0;
    int eraseHB = 0;

    log_output("Connecting to DA...\n");
    status = da_connect(com_handle, nor_flash_table, nand_flash_table, isUSB, bmt_address);

    if (status != S_DONE)
    {
        log_output("FAIL:Connecting to DA...\n");
        log_feedback("FAIL:Connecting to DA...\n");    
        return status;
    }
    log_output("SUCCESS:Connecting to DA...\n");
    log_feedback("SUCCESS:Connecting to DA...\n");    

    //CMD_GetFATRanges

    if(isNFB)
    {
        //Format CBR before writing
        log_output("Formatting CBR...\n");
        status = SV5_CMD_FormatCBR(com_handle);
        if(status != 0)
        {
            log_output("FAIL:Formatting CBR...\n");
            log_feedback("FAIL:Formatting CBR...\n");    
            return status;
        }
        log_output("SUCCESS:Formatting CBR...\n");
        log_feedback("SUCCESS:Formatting CBR...\n");    
    
        //Write Boot loader
        //Assume bootloader full download if bootLoader != NULL
        //or no bootloader download
        if(bootLoader != NULL)
        {
            log_output("Write Boot loader...\n");
            status = da_write_boot_loader(com_handle, bootLoader, extBootLoader, dspBootLoader);
            if (status != S_DONE)
            {
                log_output("FAIL:Write Boot loader...\n");
                log_feedback("FAIL:Write Boot loader...\n");
                return status;
            }
            log_output("SUCCESS:Write Boot loader...\n");
            log_feedback("SUCCESS:Write Boot loader...\n");
        }
        else
        {
            // Bypass check boot loader feature
            // only check target is not empty
            log_output("Get boot loader feature...\n");
            status = SV5_CMD_CheckBootLoaderFeature_CheckLoadType(com_handle, bootLoader, FEATURE_CHECK_WITH_ARM_BL);
            if (status != S_DONE)
            {
                log_output("FAIL:Get boot loader feature...\n");
                log_feedback("FAIL:Get boot loader feature...\n");
                return status;
            }
            log_output("SUCCESS:Get boot loader feature...\n");
            log_feedback("SUCCESS:Get boot loader feature...\n");
        }

//======================================================
        //Send NFB write image
        if( (rom != NULL && rom->buf) ||
            (secondRom != NULL && secondRom->buf) ||
            (dspRom != NULL && dspRom->buf) ||
            (demand_paging_rom != NULL && demand_paging_rom->buf))
        {
            log_output("Write NFB images...\n");
                status = da_write_NFB_images(com_handle,
                                rom,
                                secondRom,
                                dspRom,
                                demand_paging_rom);
                if (status != S_DONE)
                {
                log_output("FAIL:Write NFB images...\n");
                log_feedback("FAIL:Write NFB images...\n");
                    return status;
                }
            log_output("SUCCESS:Write NFB images...\n");
            log_feedback("SUCCESS:Write NFB images...\n");
        }

/*
        status = da_FormatFAT(com_handle,
                                HW_STORAGE_NAND,
                                0,
                                NULL,
                                NULL);
        if (status != S_DONE)
        {
            return status;
        }
*/
//======================================================

//======================================================
        if(num_linux_images > 0)
        {
            // if both the ARM BL and EXT BL are downloaded, erase the HB
            if(bootLoader->buf != NULL && extBootLoader->buf != NULL)
            {
                eraseHB = 1;
            }

                //Send NFB write linux partition image
                log_output("Write linux partition images...\n");
                status = da_write_linux_images( com_handle,
                                            linux_images ,
                                            num_linux_images,
                                            eraseHB); // 1 for eraseHB
                if (status != S_DONE)
                {
                log_output("FAIL:Write linux partition images...\n");
                log_feedback("FAIL:Write linux partition images...\n");
                    return status;
                }
            log_output("SUCCESS:Write linux partition images...\n");
            log_feedback("SUCCESS:Write linux partition images...\n");
        }
//======================================================


/*
//======================================================
        //Send total format
        status = da_FormatFlash(com_handle,
                                HW_STORAGE_NAND,
                                NUTL_ERASE,
                                0,
                                0x00000000,
                                0x08000000);
//======================================================
*/
    }
    else
    {
    }

    log_output("Enable Watch Dog...\n");
    da_EnableWatchDog(com_handle, (unsigned short)(1000/15.6));

#if 0
    /* doesn't care the return code of da_EnableWatchDog ? */
    if (status != S_DONE)
    {
        log_output("FAIL:Enable Watch Dog...\n");
        log_feedback("FAIL:Enable Watch Dog...\n");
        return status;
    }
#endif
    log_output("SUCCESS:Enable Watch Dog...\n");
    log_feedback("SUCCESS:Enable Watch Dog...\n");

    return S_DONE;
}
int
d_view_aura(struct command *c)
{
	int n;
	int level;
	int first = TRUE;
	int aura = c->a;
	int where = c->d;
	char *s;
	int has_detect;
	int learned;
	char *source;

	if (!is_loc_or_ship(where))
	{
		wout(c->who, "%s is no longer a valid location.",
				box_code(where));
		return FALSE;
	}

	if (!charge_aura(c->who, aura))
		return FALSE;

	loop_char_here(where, n)
	{
		if (is_magician(n))
		{
/*
 *  Does the viewed magician have Detect ability scry?
 */

			level = char_cur_aura(n);

			if (aura <= char_abil_shroud(n))
			{
				s = "???";
				learned = FALSE;
			}
			else
			{
				s = sout("%d", level);
				learned = TRUE;
			}

			wout(c->who, "%s, current aura: %s", box_name(n), s);
			first = FALSE;

			has_detect = has_skill(n, sk_detect_abil);

			if (has_detect > exp_novice)
				source = box_name(c->who);
			else
				source = "Someone";

			if (has_detect)
				wout(n, "%s cast View aura here.", source);

			if (has_detect > exp_journeyman)
			{
			    if (learned)
			       wout(n, "Our current aura rating was learned.");
			    else
			       wout(n, "Our current aura rating was "
							"not revealed.");
			}
		}
	}
	next_char_here;

	if (first)
	{
		wout(c->who, "No mages are seen here.");
		log_output(LOG_CODE, "d_view_aura: not a mage?\n");
	}

	return TRUE;
}
Exemple #22
0
// parses vph file.  Just scans format blocks, and reports to vphlog
int vph_parse(FILE *f)
{
	int i,err;
	short header;
	long  links;
	long li;
	int num_objects;

	assert(f);

	err = vph_read_short(f,&header);
	if (err != 0)
		{
			log_output(vphlog,"Failure to read Header");
			return 1;
		}
	log_output(vphlog,"Header = %d  (should be=%d)",(int)header,(int)VPH_FILE);
	
	err = vph_read_long(f,&links);
	if (err != 0)
		{
			log_output(vphlog,"Failure to read number of links");
			return 1;
		}
	log_output(vphlog,"Number of links = %ld",(long)links);
	if (links<0)
		{
			log_output(vphlog,"Failure: negative number of links");
			return 1;
		}

	{
		float matrix[12];

		log_output(vphlog,"Matrix:");
		err = vph_read_float_array(f,matrix,12);
		if (err != 0)
			{
				log_output(vphlog,"Failure to read matrix");
				return 1;
			}
		vph_report_float_array(matrix,12); 
	}

	for (li=0; li<links; li++)
		{
			char string[1024];
			int int_specifics[5];
			float specifics32[32];
			float matrix[12];
			float specifics15[32];
			short specific;

			log_output(vphlog,"link %ld",(long)li);		
			err = vph_read_string(f, string);			
			if (err != 0)
				{
					log_output(vphlog,"Failure to read string (link%ld)",(long)li);
					return 1;
				}
			log_output(vphlog,"NAME = %s", string);
	
			log_output(vphlog,"(physique specifics int*5)");
			err = vph_read_int_array(f,int_specifics,5);
			if (err != 0)
				{
					log_output(vphlog,"Failure to read int specifics index %d",err-1);
					return 1;
				}
			vph_report_int_array(int_specifics,5);
			
			log_output(vphlog,"(physique specifics float*32)");
			err = vph_read_float_array(f,specifics32,32);
			if (err != 0)
				{
					log_output(vphlog,"Failure to read specifics32 index %d",err-1);
					return 1;
				}
			vph_report_float_array(specifics32,32);
			

			log_output(vphlog,"Matrix ZM:");
			err = vph_read_float_array(f,matrix,12);
			if (err != 0)
				{
					log_output(vphlog,"Failure to read matrix index %d",err-1);
					return 1;
				}
			vph_report_float_array(matrix,12);
			
			log_output(vphlog,"(physique specifics float*15)");
			err = vph_read_float_array(f,specifics15,15);
			if (err != 0)
				{
					log_output(vphlog,"Failure to read specifics15 index %d",err-1);
					return 1;
				}
			vph_report_float_array(specifics15,15);
			
			err = vph_read_short(f,&specific);
			if (err != 0)
				{
					log_output(vphlog,"Failure to read specific short");
					return 1;
				}
			log_output(vphlog,"(physic specific short) %d  ",(int)specific);

		}


	err = vph_read_int(f,&num_objects);
	if (err != 0)
		{
			log_output(vphlog,"Failure to read num_objects");
			return 1;
		}
	log_output(vphlog,"num_objects = %d",(int)num_objects);
	if (num_objects<0)
		{
			log_output(vphlog,"num_objects < 0");
			return 1;
		}
	

	for (li=0; li<num_objects; li++)
		{
		
			long v,num_vertices;
			char string[1024];
			log_output(vphlog,"object %ld",(long)li);
					
			err = vph_read_string(f, string);			
			if (err != 0)
				{
					log_output(vphlog,"Failure to read string (object %ld)",(long)li);
					return 1;
				}
			log_output(vphlog,"NAME = %s", string);

			for (i=0; i<4; i++)
				{
					float offsetTM[3];
					log_output(vphlog,"OffsetTM Row (%d):",i);
					err = vph_read_float_array(f,offsetTM,3);
					if (err != 0)
						{
							log_output(vphlog,"Failure to read offsetTM element %d, row %d, object %ld",err-1,i,(long)li);
							return 1;
						}
					vph_report_float_array(offsetTM,3);
				}
	
			err = vph_read_long(f,&num_vertices);
			if (err != 0)
				{
					log_output(vphlog,"Failure to read number of vertices (object %ld)",(long)li);
					return 1;
				}
			log_output(vphlog,"Number of vertices = %ld",(long)num_vertices);
			if (num_vertices<0)
				{
					log_output(vphlog,"Failure: negative number of vertices");
					return 1;
				}

			for (v=0; v<num_vertices; v++)
				{
					int rigid_link;
					int deform_link;
					float rigid[3];
					float deform[3];

					err = vph_read_int(f,&rigid_link);			
					if (err != 0)
						{
							log_output(vphlog,"Failure to read rigid flag, vertex %ld, object %ld",(long)v,(long)li);
							return 1;
						}

					err = vph_read_float_array(f,rigid,3);
					if (err != 0)
						{
							log_output(vphlog,"Failure to read rigid element %d, vertex %d, object %ld",err-1,v,(long)li);
							return 1;
						}
					log_output(vphlog,"  rigid (%ld): (rigid_link=%d) %f %f %f",rigid_link,(long)v,rigid[0],rigid[1],rigid[2]);
					

					err = vph_read_int(f,&deform_link);			
					if (err != 0)
						{
							log_output(vphlog,"Failure to read deform flag, vertex %ld, object %ld",(long)v,(long)li);
							return 1;
						}

					err = vph_read_float_array(f,deform,3);
					if (err != 0)
						{
							log_output(vphlog,"Failure to read deform element %d, vertex %d, object %ld",err-1,v,(long)li);
							return 1;
						}
					log_output(vphlog,"  deform (%ld): (deform_link=%d,%s) %f %f %f",
						(long)v,
						deform_link,
						((deform_link<=0)?"rigid":"deformable"),
						rigid[0],rigid[1],rigid[2]);
					
				}	

				
		}

	return 0;
}
Exemple #23
0
static inline int analysisOneConf(const char* line, struct redirect_conf* pstRedirectConf)
{
	char buffer[BUFSIZ];
	memset(buffer, '\0', BUFSIZ);
	strcpy(buffer, line);
	int rtn_code = 0;
	//get domain
	char* str = xstrtok(buffer, " \t");
	if(NULL == str)
	{
		fprintf(g_fpLog, "get domain failure in conf=[%.*s]\n", (int)strlen(line)-1, line);
		return -1;
	}
	if(0 == strcasecmp(str, "null"))
	{
		pstRedirectConf->domain = NULL;
	}
	else
	{
		pstRedirectConf->domain = malloc(strlen(str)+1);
		strcpy(pstRedirectConf->domain, str);
	}
	//get cust
	str = xstrtok(NULL, " \t");
	if(NULL == str)
	{
		fprintf(g_fpLog, "get cult failure in conf=[%.*s]\n", (int)strlen(line)-1, line);
		return -1;
	}
	if(0 == strcasecmp(str, "null"))
	{
		pstRedirectConf->cust = NULL;
		pstRedirectConf->cust_size = 0;
	}
	else if(0 == strcasecmp(str, "none"))
	{
		pstRedirectConf->cust = NULL;
		pstRedirectConf->cust_size = -1;
	}
	else
	{
		pstRedirectConf->cust_size = strlen(str);
		pstRedirectConf->cust = malloc(pstRedirectConf->cust_size+1);
		strcpy(pstRedirectConf->cust, str);		
	}
	//get operate
	str = xstrtok(NULL, " \t\r\n");
	if(NULL == str)
	{
		fprintf(g_fpLog, "get operate failure in conf=[%.*s]\n", (int)strlen(line)-1, line);
		return -1;
	}
	char *ptr = strchr(str,':');
	if(ptr != NULL)
	{
		*ptr = 0;
		rtn_code = atoi(ptr+1);
		if( rtn_code >200 && rtn_code < 600 )
		{
			pstRedirectConf->return_code = atoi(ptr+1);
			log_output(1,"get return code in conf [%d]\n",pstRedirectConf->return_code);
		}
		else
		{
			fprintf(g_fpLog,"error:get no code or out of range[<200 >600][%d]\n",pstRedirectConf->return_code);
			pstRedirectConf->return_code = 0;       
		}
	}

#ifdef OUPENG
    if (0 == strcasecmp(str, OUPENG_FILTER_CHAR))
    {
        pstRedirectConf->operate = OUPENG_FILTER;    
    }
#endif

	if(0 == strcasecmp(str, IP_FILTER_CHAR))
	{
		pstRedirectConf->operate = IP_FILTER;
	}
	else if(0 == strcasecmp(str, IP_ABORT_FILTER_CHAR))
	{
		pstRedirectConf->operate = IP_ABORT_FILTER;
	}
	else if(0 == strcasecmp(str, TIME_FILTER_CHAR))
	{
		pstRedirectConf->operate = TIME_FILTER;
	}
	else if(0 == strcasecmp(str, TIME1_FILTER_CHAR))
	{
		pstRedirectConf->operate = TIME1_FILTER;
	}
	else if(0 == strcasecmp(str, TIME2_FILTER_CHAR))
	{
		pstRedirectConf->operate = TIME2_FILTER;
	}
	else if(0 == strcasecmp(str, IP_TIME_FILTER_CHAR))
	{
		pstRedirectConf->operate = IP_TIME_FILTER;
	}
	else if(0 == strcasecmp(str, IP_TIME_ABORT_FILTER_CHAR))
	{
		pstRedirectConf->operate = IP_TIME_ABORT_FILTER;
	}
	else if(0 == strcasecmp(str, KEY_FILTER_CHAR))
	{
	    pstRedirectConf->operate = KEY_FILTER; 
	}
	else if(0 == strcasecmp(str, REPLACE_HOST_FILTER_CHAR))
	{
		pstRedirectConf->operate = REPLACE_HOST_FILTER;
	}
	else if(0 == strcasecmp(str, DENY_FILTER_CHAR))
	{
		pstRedirectConf->operate = DENY_FILTER;
	}
	else if(0 == strcasecmp(str, BYPASS_FILTER_CHAR))
	{
		pstRedirectConf->operate = BYPASS_FILTER;
//		return 0;
	}
	else if(0 == strcasecmp(str, RID_QUESTION_FILTER_CHAR))
	{
		pstRedirectConf->operate = RID_QUESTION_FILTER;
		return 0;
	}
	else if(0 == strcasecmp(str, REPLACE_HOST_ALL_FILTER_CHAR))
	{
		pstRedirectConf->operate = REPLACE_HOST_ALL_FILTER;
	}
	else if(0 == strcasecmp(str, REPLACE_REGEX_FILTER_CHAR))
	{
		pstRedirectConf->operate = REPLACE_REGEX_FILTER;
		return analysisReplaceRegex(pstRedirectConf);
	}
#ifdef QQ_MUSIC
	/* add by xt for 64bit complie */
	else if(0 == strcasecmp(str, QQ_MUSIC_FILTER_CHAR))
	{
		pstRedirectConf->operate = QQ_MUSIC_FILTER;
		return analysisQQMusic(pstRedirectConf);
	}
#endif
#ifdef NNPAN
    /* add by chenqi for 99pan.com */
    else if (0 == strcasecmp(str, NINETY_NINE_CHAR))
    {
        pstRedirectConf->operate = NINETY_NINE_FILTER;
        return analysisNinetyNineCfg(pstRedirectConf);
    }
#endif
#ifdef NOKIA
    else if (0 == strcasecmp(str, NOKIA_FILTER_CHAR))
    {
        pstRedirectConf->operate = NOKIA_FILTER;
        return analysisNokiaCfg(pstRedirectConf); 
    }
#endif
	else if(0 == strcasecmp(str, MYSPACE_FILTER_CHAR)) {	
		pstRedirectConf->operate = MYSPACE_FILTER;
	}
	else if(0 == strcasecmp(str, SINA_FILTER_CHAR)) {
		/* add by xt for sina */
		pstRedirectConf->operate = SINA_FILTER;
	}
	else if(0 == strcasecmp(str, COOKIE_MD5_FILTER_CHAR)) {
		pstRedirectConf->operate = COOKIE_MD5_FILTER;
		return analyseCookieMd5Cfg(pstRedirectConf);
	}
	else if(0 == strcasecmp(str, QQ_TOPSTREAM_FILTER_CHAR)){
		pstRedirectConf->operate = QQ_TOPSTREAM_FILTER;
		return analyseQQTopStreamCfg(pstRedirectConf);
	}
    else if(0 == strcasecmp(str, TUDOU_FILTER_CHAR)){
        pstRedirectConf->operate = TUDOU_FILTER;
        return analyseTudouCfg(pstRedirectConf);
    }

#ifdef OUPENG
    else if (0 == strcasecmp(str, OUPENG_FILTER_CHAR))
    {
		pstRedirectConf->operate = OUPENG_FILTER;
		return analysisOupengCfg(pstRedirectConf);
    }
#endif
    else if (0 == strcasecmp(str, LONGYUAN_FILTER_CHAR))
    {
        pstRedirectConf->operate = LONGYUAN_FILTER;
        return analysisLongyuanCfg(pstRedirectConf);
    }
#ifdef DUOWAN
	/* add by Jiangbo.tian xt for 64bit complie */
	else if(0 == strcasecmp(str, DUOWAN_FILTER_CHAR))
	{
		pstRedirectConf->operate = DUOWAN_FILTER;
		return analysisDuoWanCfg(pstRedirectConf);
	}
#endif
#ifdef QQ_GREEN_MP3
	else if(0 == strcasecmp(str,QQ_GREEN_HIGH_PERFORM_CHAR))
	{
		pstRedirectConf->operate = QQ_GREEN_HIGH_PERFORM_FILTER;           
		fprintf(g_fpLog,"befor analysisQQGreenHighPerformCfg\n");
		return analysisQQGreenMP3Cfg(pstRedirectConf);
	}
#endif
#ifdef PPTV
    else if(0 == strcasecmp(str,PPTV_ANTIHIJACK_CHAR))
    {   
        pstRedirectConf->operate = PPTV_ANTIHIJACK_FILTER;    
        fprintf(g_fpLog,"befor analysisPPVodCfg\n");
        return analysisPPTVCfg(pstRedirectConf);
    }   
#endif
#ifdef SDO
	else if(0 == strcasecmp(str,SDO_CHAR))
	{
		pstRedirectConf->operate = SDO_FILTER;           
		fprintf(g_fpLog,"befor analysisSDOCfg\n");
		return analysisSDOCfg(pstRedirectConf);
	}
#endif

#ifdef OOYALA
	else if(0 == strcasecmp(str,OOYALA_FILTER_CHAR))
	{
		pstRedirectConf->operate = OOYALA_FILTER;
		fprintf(g_fpLog,"befor analysisOoyalaCfg\n");
		return analysisOoyalaCfg(pstRedirectConf);
	}
#endif

    // added for microsoft by chenqi
    else if (0 == strcasecmp(str,MICROSOFT_FILTER_CHAR))
    {    
        pstRedirectConf->operate = MICROSOFT_FILTER;
        fprintf(g_fpLog, "befor analysisMicrosoftCfg\n");
        return analysisMicrosoftCfg(pstRedirectConf);
    }    
    else if (0 == strcasecmp(str,MICROSOFT_MD5_FILTER_CHAR))
    {    
        pstRedirectConf->operate = MICROSOFT_MD5_FILTER;
        fprintf(g_fpLog, "befor analysisMicrosoftCfg_MD5\n");
        return analysisMicrosoftCfg_MD5(pstRedirectConf);
    }    
    // add end
#ifdef IQILU
    else if(0 == strcasecmp(str,IQILU_CHAR))	
        {
                pstRedirectConf->operate = IQILU_FILTER;
                fprintf(g_fpLog,"befor analysisIQILUCfg\n");
                return analysisIQILUCfg(pstRedirectConf);
        }
#endif
	else if(0 == strcasecmp(str,ICONV_FILTER_CHAR))
	{
		pstRedirectConf->operate = DECODE_FILTER;           
	}
	else if(0 == strcasecmp(str,LIGHTTPD_SECDOWNLOAD_FILTER_CHAR))
	{
        pstRedirectConf->operate = LIGHTTPD_SECDOWNLOAD_FILTER;           
    }
    else if(0 == strcasecmp(str,MFW_MUSIC_FILTER_CHAR))
    {   
        pstRedirectConf->operate = MFW_MUSIC_FILTER;    
        return analysisMFWMusicCfg(pstRedirectConf);
    }  
	else if(0 == strcasecmp(str, BOKECC_FILTER_CHAR))
	{
		pstRedirectConf->operate = BOKECC_FILTER;
		return analysisBokeccCfg(pstRedirectConf);
	}

    else if(0 == strcasecmp(str, MSN_FILTER_CHAR))
    {    
        pstRedirectConf->operate = MSN_DOWNLOAD_FILTER;
        return analysisMSNCfg(pstRedirectConf);
    }
    else if(0 == strcasecmp(str,MUSIC163_FILTER_CHAR))
    {
        pstRedirectConf->operate = MUSIC163_FILTER;           
        return analysis163MusicCfg(pstRedirectConf); 
    }
	else if(0 == strcasecmp(str, WANGLONG_FILTER_CHAR))
	{
		pstRedirectConf->operate = WANGLONG_FILTER;           
		return analysisWanglongCfg(pstRedirectConf);
		
	}
	else if (0 == strcasecmp(str, CWG_FILTER_CHAR))
	{
		pstRedirectConf->operate = CWG_FILTER;
		return analysisCWGCfg(pstRedirectConf);
	}
#ifdef BAID
    else if(0 == strcasecmp(str,BAIDU_XCODE_CHAR))
    {
        pstRedirectConf->operate = BAIDU_XCODE_FILTER;
        fprintf(g_fpLog,"befor analysisBaiduXcodeCfg\n");
        return analysisBaiduXcodeCfg(pstRedirectConf);
    }
#endif


	else
	{
		fprintf(g_fpLog, "operator error in conf=[%.*s]\n", (int)strlen(line)-1, line);;
		return -1;
	}
	//get key
	str = xstrtok(NULL, " \t");
	if(NULL == str)
	{
		fprintf(g_fpLog, "get key failure in conf=[%.*s]\n", (int)strlen(line)-1, line);
		return -1;
	}
	if(0 == strcasecmp(str, "null"))
	{
		pstRedirectConf->key = NULL;
	}
	else
	{
		pstRedirectConf->key = malloc(strlen(str)+1);
		strcpy(pstRedirectConf->key, str);
	}
	//get key2
	str = xstrtok(NULL, " \t");
	if(NULL == str)
	{
		fprintf(g_fpLog, "get key2 failure in conf=[%.*s]\n", (int)strlen(line)-1, line);
		return -1;
	}
	if(0 == strcasecmp(str, "null"))
	{
		pstRedirectConf->key2 = NULL;
	}
	else
	{
		pstRedirectConf->key2 = malloc(strlen(str)+1);
		strcpy(pstRedirectConf->key2, str);
	}
	//get md5_start
	str = xstrtok(NULL, " \t");
	if(NULL == str)
	{
		fprintf(g_fpLog, "get md5 start failure in conf=[%.*s]\n", (int)strlen(line)-1, line);
		return -1;
	}
	pstRedirectConf->md5_start = atoi(str);
	//get md5_length
	str = xstrtok(NULL, " \t");
	if(NULL == str)
	{
		fprintf(g_fpLog, "get md5 length failure in conf=[%.*s]\n", (int)strlen(line)-1, line);
		return -1;
	}
	pstRedirectConf->md5_length = atoi(str);
	//get decode
	str = xstrtok(NULL, " \t");
	if(NULL == str)
	{
		fprintf(g_fpLog, "get decode failure in conf=[%.*s]\n", (int)strlen(line)-1, line);
		return -1;
	}
	pstRedirectConf->decode = atoi(str);
	log_output(3,"get decode = %d\n",pstRedirectConf->decode);
	//get replace_host
	str = xstrtok(NULL, " \t");
	if(NULL == str)
	{
		fprintf(g_fpLog, "get replace host failure in conf=[%.*s]\n", (int)strlen(line)-1, line);
		return -1;
	}
	if(0 == strcasecmp(str, "null"))
	{
		pstRedirectConf->replace_host = NULL;
	}
	else
	{
		pstRedirectConf->replace_host = malloc(strlen(str)+1);
		strcpy(pstRedirectConf->replace_host, str);
		fprintf(g_fpLog, "get replace host %s\n", pstRedirectConf->replace_host);
	}
	//get replace_dir
	str = xstrtok(NULL, " \t");
	if(NULL == str)
	{
		fprintf(g_fpLog, "get replace dir failure in conf=[%.*s]\n", (int)strlen(line)-1, line);
		return -1;
	}
	if(0 == strcasecmp(str, "null"))
	{
		pstRedirectConf->replace_dir = NULL;
	}
	else
	{
		pstRedirectConf->replace_dir = malloc(strlen(str)+1);
		strcpy(pstRedirectConf->replace_dir, str);
	}
	//get fail_dst
	str = xstrtok(NULL, " \t\r\n");
	if(NULL == str)
	{
		fprintf(g_fpLog, "get fail dst failure in conf=[%.*s]\n", (int)strlen(line)-1, line);
		return -1;
	}
	if(0 == strcasecmp(str, "null"))
	{
		pstRedirectConf->fail_dst = NULL;
	}
	else
	{
		/* Fixed start: xin.yao, add code[401/403] for check failed */
		size_t n;
		int code = atoi(str);

		if (401 == code || 403 == code)
		{
			n = 3;
			pstRedirectConf->fail_dst_type = FAIL_DST_TYPE_CODE;
		}
		else
		{
			n = strlen(str);
			pstRedirectConf->fail_dst_type = FAIL_DST_TYPE_URL;
		}
		pstRedirectConf->fail_dst = malloc(n + 1);
		strncpy(pstRedirectConf->fail_dst, str, n);
		pstRedirectConf->fail_dst[n] = '\0';
		/* Fixed end: xin.yao */
	}
	/* get valid interval */
	if((TIME_FILTER==pstRedirectConf->operate) || 
		(TIME1_FILTER==pstRedirectConf->operate) ||	
		(TIME2_FILTER==pstRedirectConf->operate) ||	
		(IP_TIME_FILTER==pstRedirectConf->operate) || 
		(IP_TIME_ABORT_FILTER==pstRedirectConf->operate) ||
		(SINA_FILTER == pstRedirectConf->operate)||
		(LIGHTTPD_SECDOWNLOAD_FILTER ==  pstRedirectConf->operate))
	{
		pstRedirectConf->other = malloc(sizeof(struct valid_period));
		if(NULL == pstRedirectConf->other)
		{
			fprintf(g_fpLog, "cannot malloc\n");
			return -1;
		}
		struct valid_period* pstValidPeriod = (struct valid_period*)pstRedirectConf->other;
		//get seconds_before
		str = xstrtok(NULL, " \t");
		if(NULL == str)
		{
			fprintf(g_fpLog, "get seconds_before failure in conf=[%.*s]\n", (int)strlen(line)-1, line);
			return -1;
		}
		if(0 == strcasecmp(str, "null"))
		{
			pstValidPeriod->seconds_before = 360*60;
		}
		else
		{
			pstValidPeriod->seconds_before = atoi(str)*60;
		}
		//get seconds_after
		str = xstrtok(NULL, " \t\r\n");
		if(NULL == str)
		{
			fprintf(g_fpLog, "get seconds_after failure in conf=[%.*s]\n", (int)strlen(line)-1, line);
			return -1;
		}
		if(0 == strcasecmp(str, "null"))
		{
			pstValidPeriod->seconds_after = 360*60;
		}
		else
		{
			pstValidPeriod->seconds_after = atoi(str)*60;
		}
		log_output(3,"pstValidPeriod->seconds_before = %d\n",pstValidPeriod->seconds_before/60);
		log_output(3,"pstValidPeriod->seconds_after = %d\n",pstValidPeriod->seconds_after/60);

		/* add by xt for ip filter range */
		goto range_flag;
		/* end */
	}
	/* add by xt for ip filter range */
	/* get Flag */
	str = xstrtok(NULL, " \t\r\n");
	str = xstrtok(NULL, " \t\r\n");
range_flag:
	if((str = xstrtok(NULL, " \t\r\n"))) {
		if(1 == atoi(str)) 
			pstRedirectConf->range_flag = 1;
	}
	/* get cookie flag */
	if((str = xstrtok(NULL, " \t\r\n"))) 
		if(1 == atoi(str)) 
			pstRedirectConf->cookie_flag = 1;
	
	/* get cookie pass */
	if((str = xstrtok(NULL, " \t\r\n"))) 
		pstRedirectConf->cookie_pass = strtol(str, NULL, 16);
	/* end */
	return 0;
}
Exemple #24
0
int main(int argc, char *argv[]) {
    struct USBConnection *connection;
    int opt;
    int repeatCount = 0;
    char *script = NULL;
    int delay = 10;
    int daemon = 0;
    while ((opt = getopt(argc, argv, "s:d:c:Dv")) != -1) {
        switch (opt) {
            case 's':
                script = optarg;
                break;
            case 'd':
                delay = atoi(optarg);
                break;
            case 'c':
                repeatCount = atoi(optarg);
                break;
            case 'D':
                daemon = 1;
                break;
            case 'v':
                enable_debug();
                break;
            default:
                printUsage(argv[0]);
                return -1;
        }
    }
    if (optind >= argc) {
        fprintf(stderr, "Missing USB device parameter.\n");
        printUsage(argv[0]);
        return -1;
    }
    if (daemon && script == NULL) {
        fprintf(stderr, "Missing script parameter. Running the program as a daemon implies -s.\n");
        return -1;
    }
    if (daemon) {
        initlog(1);
        daemonize();
    }
    else {
        initlog(0);
    }
    log_output(LOG_DEBUG, "Opening USB device\n");
    connection = initUSBConnection(argv[optind]);
    if (connection != NULL) {
        int i;
        int increment = 1;
        log_output(LOG_INFO, "Connection initialization successful. UVR mode 0x%X\n", (unsigned int)connection->uvr_mode);
        if (repeatCount == 0) {
            increment = 0;
            repeatCount = 1; // prepare the values in a way that the loop below runs infinitely
        }
        for (i = 0; i < repeatCount; i+=increment) {
            struct SystemState *result;
            result = readCurrentData(connection);
            if (result != NULL) {
                if (script != NULL) {
                    executeProgram(script, result);
                }
                else {
                    printf("Inputs\n");
                    printValueList("S", result->inputs);
                    printf("Outputs\n");
                    printValueList("O", result->outputs);
                    printf("Heat registers\n");
                    printValueList("", result->heatRegisters);
                }
                freeSystemState(result);
                result = NULL;
            }
            sleep(delay);
        }
    }
    else {
        fprintf(stderr, "Could not initialize connection to UVR. %s\n", strerror(errno));
        cleanupUSBConnection(connection);
        return -1;
    }
    cleanupUSBConnection(connection);
    return 0;
}
/**
 * open the connection to a D-LOGG USB device on the given path
 * 
 * \param device the device path where the D-LOGG is to be found
 * \return a pointer to a USBConnection structure containing the necessary information to talk to the device. NULL, if anything failed
 *         when initializing the connection. errno is set accordingly.
 */
struct USBConnection *initUSBConnection(char const * const device)
{
    struct USBConnection *conn;
    conn = malloc(sizeof(struct USBConnection));
    if (conn != NULL) {
        conn->fd = -1;
        conn->_success = 0;
        conn->device = malloc(strlen(device)+1);
        if (conn->device != 0) {
            strcpy(conn->device, device);
            conn->fd = open(device, O_NOCTTY | O_RDWR);
            if (conn->fd >= 0) {
                log_output(LOG_DEBUG, "Successfully opened USB device\n");
                // the opening has been successful
                // -> setup the serial connection (D-LOGG is a serial connector)
                if (tcgetattr(conn->fd, &(conn->_savedattrs)) == 0) {
                    memset(&(conn->_newattrs), 0, sizeof(struct termios));
                    conn->_newattrs.c_cflag     = B115200 | CS8 | CLOCAL | CREAD;
#ifdef CRTSCTS
                    conn->_newattrs.c_cflag    |= CRTSCTS;
#endif
#ifdef CNEW_RTSCTS
                    conn->_newattrs.c_cflag    |= CNEW_RTSCTS;
#endif
                    conn->_newattrs.c_iflag     = IGNPAR;
                    conn->_newattrs.c_oflag     = 0;
                    conn->_newattrs.c_lflag     = 0;
                    conn->_newattrs.c_cc[VTIME] = 0;   /* read block infinitely */
                    conn->_newattrs.c_cc[VMIN]  = 1;   /* minimum 1 character to be read */
                    tcflush(conn->fd, TCIFLUSH);
                    if (tcsetattr(conn->fd, TCSANOW, &(conn->_newattrs)) == 0) {
                        log_output(LOG_DEBUG, "Initializing device.\n");
                        if (sendCommand(conn, GET_MODE) == 0) {
                            if (read(conn->fd, &(conn->uvr_mode), 1) == 1) {
                                conn->_success = 1;  // initialization done
                            }
                            else {
                                log_output(LOG_ERR, "Could not read device reply. %s\n", strerror(errno));
                            }
                        }
                    }
                    else {
                        log_output(LOG_ERR, "Could not setup USB device. %s\n", strerror(errno));
                    }
                }
                else {
                    log_output(LOG_ERR, "Could not get attributes of serial interface. %s\n", strerror(errno));
                }
            }
        }
    }
    else {
        log_output(LOG_ERR, "Could not allocate memory. %s\n", strerror(errno));
    }
    if (conn != NULL && !conn->_success) {
        /* somewhere along the way we couldn't successfully initialize -> clean up */
        log_output(LOG_ERR, "Could not open USB device %s. %s\n", device, strerror(errno));
        cleanupUSBConnection(conn);
        conn = NULL;
    }
    log_output(LOG_DEBUG, "Returning connection %p\n", conn);
    return conn;
}