Esempio n. 1
0
File: wad.c Progetto: samboy/Oblige
//
// ReadWadFile
//
glbsp_ret_e ReadWadFile(const char *filename)
{
  int check;
  char *read_msg;

  // open input wad file & read header
  in_file = fopen(filename, "rb");

  if (! in_file)
  {
    if (errno == ENOENT)
      SetErrorMsg("Cannot open WAD file: %s", filename); 
    else
      SetErrorMsg("Cannot open WAD file: %s [%s]", filename, 
          strerror(errno));

    return GLBSP_E_ReadError;
  }
  
  if (! ReadHeader(filename))
  {
    fclose(in_file);
    return GLBSP_E_ReadError;
  }

  PrintMsg("Opened %cWAD file : %s\n", (wad.kind == IWAD) ? 'I' : 'P', 
      filename); 
  PrintVerbose("Reading %d dir entries at 0x%X\n", wad.num_entries, 
      wad.dir_start);

  // read directory
  ReadDirectory();

  DisplayOpen(DIS_FILEPROGRESS);
  DisplaySetTitle("glBSP Reading Wad");
  
  read_msg = UtilFormat("Reading: %s", filename);

  DisplaySetBarText(1, read_msg);
  DisplaySetBarLimit(1, CountLumpTypes(LUMP_READ_ME, LUMP_READ_ME));
  DisplaySetBar(1, 0);

  UtilFree(read_msg);

  cur_comms->file_pos = 0;

  // now read lumps
  check = ReadAllLumps();

  if (check != wad.num_entries)
    InternalError("Read directory count consistency failure (%d,%d)",
      check, wad.num_entries);
  
  wad.current_level = NULL;

  DisplayClose();

  return GLBSP_E_OK;
}
Esempio n. 2
0
EFFECTGETARGS(frame,tags,PPTBase,EffectBase)
{
    struct convargs args = {0}, *saved;
    PERROR res;
    ULONG *rxargs;
    STRPTR buffer;

    SetDefaults(&args);

    if( saved = GetOptions(MYNAME) ) {
        args = *saved;
    }

    buffer = (STRPTR) TagData( PPTX_ArgBuffer, tags );

    rxargs = (ULONG *)TagData( PPTX_RexxArgs, tags );
    if(rxargs) {
        if( (res = LoadConvFilter( PPTBase, (UBYTE *)rxargs[0], &args )) != PERR_OK ) {
            SetErrorMsg(frame,"Couldn't open the specified convolution file");
            return PERR_FILEREAD;
        }
        strncpy( args.name, FilePart( (UBYTE *)rxargs[0] ), 40 );
    }

    if( (res = GetConvArgs( frame, tags, PPTBase, &args )) == PERR_OK ) {
        SaveConvFilter( PPTBase, TEMPFILENAME, &args );
        SPrintF( buffer, "FILE %s", TEMPFILENAME );
    }

    return res;
}
Esempio n. 3
0
EFFECTEXEC(frame,tags,PPTBase,EffectBase)
{
    struct Library *UtilityBase = PPTBase->lb_Utility;
    struct DosLibrary *DOSBase  = PPTBase->lb_DOS;
    FRAME *newframe = NULL;
    struct convargs args = {0}, *saved;
    PERROR res;
    ULONG *rxargs;

    SetDefaults(&args);

    if( saved = GetOptions(MYNAME) ) {
        args = *saved;
    }

    rxargs = (ULONG *)TagData( PPTX_RexxArgs, tags );
    if(rxargs) {
        if( (res = LoadConvFilter( PPTBase, (UBYTE *)rxargs[0], &args )) != PERR_OK ) {
            SetErrorMsg(frame,"Couldn't open the specified convolution file");
            return NULL;
        }
        strncpy( args.name, FilePart( (UBYTE *)rxargs[0] ), 40 );
    } else {
        res = GetConvArgs( frame, tags, PPTBase, &args );
    }

    if( res == PERR_OK ) {
        /*
         *  Make the actual convolution
         */

        if(newframe = DupFrame( frame, DFF_COPYDATA )) {
            res = DoConvolute( frame, newframe, &args, PPTBase );
            if(res != PERR_OK) {
                RemFrame(newframe);
                newframe = NULL;
                SetErrorCode( frame, res );
            }
        } else {
            SetErrorMsg(frame,"Unable to duplicate frame");
        }

        PutOptions(MYNAME,&args,sizeof(struct convargs));
    }

    return newframe;
}
Esempio n. 4
0
 bool Entry()
 {
     GITObjRef dobj(cam->m_gitEntry);
     // ... set the Connected property to true....
     if (!dobj.PutProp(L"Connected", true))
     {
         SetErrorMsg(ExcepMsg(dobj.Excep()));
         return true;
     }
     return false;
 }
Esempio n. 5
0
 bool Entry()
 {
     bool err = pPointingSource->SlewToCoordinatesAsync(ra, dec);
     if (err)
     {
         SetErrorMsg(_("Slew failed!"));
         return true;
     }
     while (pPointingSource->Slewing())
     {
         wxMilliSleep(500);
         if (IsCanceled())
         {
             pPointingSource->AbortSlew();
             SetErrorMsg(_("Slew was canceled"));
             break;
         }
     }
     return false;
 }
Esempio n. 6
0
 bool Entry()
 {
     GITObjRef scope(sa->m_gitEntry);
     // ... set the Connected property to true....
     if (!scope.PutProp(sa->dispid_connected, true))
     {
         SetErrorMsg(ExcepMsg(scope.Excep()));
         return true;
     }
     return false;
 }
Esempio n. 7
0
bool CScriptState::LoadScript(const char* filename)
{
	assert(m_pState);

	if(luaL_loadfile(m_pState, filename)!=0) {
		SetErrorMsg(-1);
		lua_pop(m_pState, 1);
		return false;
	}

	return true;
}
Esempio n. 8
0
bool CScriptState::Call(const char* funcname)
{
	assert(m_pState);

	lua_getglobal(m_pState, funcname);
	if(lua_pcall(m_pState, 1, 0, 0)!=0) {
		SetErrorMsg(-1);
		return false;
	}

	return true;
}
Esempio n. 9
0
File: wad.c Progetto: samboy/Oblige
//
// WriteWadFile
//
glbsp_ret_e WriteWadFile(const char *filename)
{
  int check1, check2;
  char *write_msg;

  PrintMsg("\n");
  PrintMsg("Saving WAD as %s\n", filename);

  RecomputeDirectory();

  // create output wad file & write the header
  out_file = fopen(filename, "wb");

  if (! out_file)
  {
    SetErrorMsg("Cannot create WAD file: %s [%s]", filename,
        strerror(errno));

    return GLBSP_E_WriteError;
  }

  WriteHeader();

  DisplayOpen(DIS_FILEPROGRESS);
  DisplaySetTitle("glBSP Writing Wad");
  
  write_msg = UtilFormat("Writing: %s", filename);

  DisplaySetBarText(1, write_msg);
  DisplaySetBarLimit(1, CountLumpTypes(LUMP_IGNORE_ME, 0));
  DisplaySetBar(1, 0);

  UtilFree(write_msg);

  cur_comms->file_pos = 0;

  // now write all the lumps to the output wad
  check1 = WriteAllLumps();

  DisplayClose();

  // finally, write out the directory
  check2 = WriteDirectory();

  if (check1 != wad.num_entries || check2 != wad.num_entries)
    InternalError("Write directory count consistency failure (%d,%d,%d)",
      check1, check2, wad.num_entries);

  return GLBSP_E_OK;
}
Esempio n. 10
0
File: wad.c Progetto: samboy/Oblige
//
// ReadHeader
//
// Returns TRUE if successful, or FALSE if there was a problem (in
// which case the error message as been setup).
//
static int ReadHeader(const char *filename)
{
  size_t len;
  raw_wad_header_t header;

  len = fread(&header, sizeof(header), 1, in_file);

  if (len != 1)
  {
    SetErrorMsg("Trouble reading wad header for %s [%s]", 
      filename, strerror(errno));

    return FALSE;
  }

  if (! CheckMagic(header.type))
  {
    SetErrorMsg("%s does not appear to be a wad file (bad magic)", 
        filename);

    return FALSE;
  }

  wad.kind = (header.type[0] == 'I') ? IWAD : PWAD;
  
  wad.num_entries = UINT32(header.num_entries);
  wad.dir_start   = UINT32(header.dir_start);

  // initialise stuff
  wad.dir_head = NULL;
  wad.dir_tail = NULL;
  wad.current_level = NULL;
  wad.level_names = NULL;
  wad.num_level_names = 0;

  return TRUE;
}
Esempio n. 11
0
int LameFileDecoder::Open(SampleContainer& samples, SampleContext& context)
{
	m_pFile = _tfopen(SampleParams::GetInputFile(context), _T("rb"));
	if(m_pFile == NULL)
	{
		SetErrorMsg(context, _T("[Open]: failed open file %s"), SampleParams::GetInputFile(context));
		return -1;
	}

	int ret = m_pDecoder->Init();
	if(ret != 0)
	{
		return ret;
	}

	int nRead;
	while( (nRead = fread(m_mp3buf, 1, MP3_BUFFER_SIZE, m_pFile)) > 0 )
	{
		//parse mp3 file header until get the struct data
		ret = ParseMpegHeader(m_mp3buf, nRead, &m_mp3data, &samples);

		//negative value indicates error
		if(ret < 0)
		{
			return ret;
		}

		//found mp3 struct data
		if(ret > 0)
		{
			break;
		}
		//0 indicates no error and mp3 struct data
	}

	return 0;
}
Esempio n. 12
0
EFFECTEXEC(frame,tags,PPTBase,EffectBase)
{
    ULONG sig, rc, *args;
    BOOL quit = FALSE, reallyrexx = FALSE;
    FRAME *newframe = NULL, *with = NULL;
    struct gFixRectMessage gfr = {0};
    ULONG fc, wc;
    struct Values *av;

    D(bug(MYNAME": Exec()\n"));

    /*
     *  Defaults
     */
    v.ratio = 128;
    v.method = Direct;
    v.bounds.Top = v.bounds.Left = ~0;
    v.bounds.Width = 200; v.bounds.Height = 100;
    v.tile = FALSE;

    if( av = GetOptions(MYNAME) ) {
        v = *av;
    }

    /*
     *  Copy to local variables
     */

    BGUIBase        = PPTBase->lb_BGUI;
    IntuitionBase   = (struct IntuitionBase *)PPTBase->lb_Intuition;
    DOSBase         = PPTBase->lb_DOS;
    SysBase         = PPTBase->lb_Sys;

    /*
     *  Parse AREXX message, which has to exist.
     *  BUG: If necessary, should wait for D&D from the main window.
     *  BUG: Should make sanity checks!
     */

    args = (ULONG *) TagData( PPTX_RexxArgs, tags );

    if( args ) {

        /* WITH */
        if( args[0] ) {
            with = FindFrame( (ID) PEEKL(args[0]) );
            if(!with) {
                SetErrorMsg(frame,"Unknown frame ID for WITH parameter");
                return NULL;
            }
        }

        /* TOP */
        if( args[1] ) {
            gfr.y = (WORD) PEEKL(args[1]);
            reallyrexx = TRUE;
        }

        /* LEFT */
        if( args[2] ) {
            gfr.x = (WORD) PEEKL(args[2]);
            reallyrexx = TRUE;
        }

        /* METHOD */
        if( args[3] ) {
            int i;

            for( i = 0; method_labels[i]; i++ ) {
                if(stricmp( method_labels[i], (char *)args[3] ) == 0 ) {
                    v.method = i;
                    reallyrexx = TRUE;
                    break;
                }
            }
        }

        /* RATIO */
        if( v.method == Mix ) {
            if( args[4] ) {
                v.ratio = PEEKL( args[4] );
            } else {
                SetErrorCode(frame,PERR_INVALIDARGS);
            }
        }

        /* TILE */
        if( args[5] ) {
            v.tile = TRUE;
        } else {
            v.tile = FALSE;
        }

    } else {
        SetErrorMsg(frame,"Image compositing can be used with Drag&Drop (or REXX) only");
        return NULL;
    }

    /*
     *  Make some sanity checks
     */

    if( frame->pix->width < with->pix->width ||
        frame->pix->height < with->pix->height ) {
            SetErrorMsg(frame,"You cannot composite a larger picture on a smaller one!");
            return NULL;
        }

    fc = frame->pix->colorspace;
    wc = with->pix->colorspace;

    if( ! (wc == fc || (fc == CS_ARGB && wc == CS_RGB) || (fc == CS_RGB && wc == CS_ARGB ))) {
        SetErrorMsg(frame, "Only images of the same color space can be composited");
        return NULL;
    }

    gfr.dim.Left   = 0;
    gfr.dim.Top    = 0;
    gfr.dim.Height = with->pix->height;
    gfr.dim.Width  = with->pix->width;

    /*
     *  Open window and start parsing
     */

    if( reallyrexx == FALSE ) {
        if( GimmeWindow(frame, with, PPTBase) ) {
            ULONG sigmask, gimask = 0L;

            GetAttr( WINDOW_SigMask, Win, &sigmask );

            StartInput(frame, GINP_FIXED_RECT, (struct PPTMessage *) &gfr);

            gimask = (1 << PPTBase->mport->mp_SigBit);

            while( !quit ) {
                sig = Wait( sigmask|gimask|SIGBREAKF_CTRL_C|SIGBREAKF_CTRL_F );

                if( sig & SIGBREAKF_CTRL_C ) {
                    D(bug("BREAK!\n"));
                    SetErrorCode( frame, PERR_BREAK );
                    quit = TRUE;
                    break;
                }

                if( sig & SIGBREAKF_CTRL_F ) {
                    WindowToFront(win);
                    ActivateWindow(win);
                }

                if( sig & gimask ) {
                    struct gFixRectMessage *pmsg;

                    if(pmsg = (struct gFixRectMessage *)GetMsg( PPTBase->mport )) {
                        if( pmsg->msg.code == PPTMSG_FIXED_RECT ) {
                            D(bug("User picked a point @ (%d,%d)\n",pmsg->x, pmsg->y));
                            gfr.x = pmsg->x; gfr.y = pmsg->y;
                            // SetGadgetAttrs( ( struct Gadget *)OKButton, win, NULL, GA_Disabled, FALSE );
                        }
                        ReplyMsg( (struct Message *)pmsg );
                    }
                }

                if( sig & sigmask ) {
                    while( (rc = HandleEvent( Win )) != WMHI_NOMORE ) {
                        ULONG t;

                        switch(rc) {
                            case GID_OK:
                                GetAttr( CYC_Active, Method, (ULONG *)&v.method );
                                GetAttr( SLIDER_Level, Ratio, &v.ratio );

                                /*
                                 *  Save the window attributes for later retrieval.
                                 */

                                GetAttr( WINDOW_Bounds, Win, (ULONG *) &v.bounds );
                                GetAttr( GA_Selected, Tile, &t );

                                StopInput( frame );
                                v.tile = (BOOL) t;

                                WindowClose(Win);
                                newframe = DoComposite( frame, with, &gfr, v.method,
                                                        (WORD) v.ratio, v.tile, PPTBase );
                                quit = TRUE;
                                break;

                            case GID_CANCEL:
                                quit = TRUE;
                                StopInput( frame );
                                break;
                        }
                    }
                }
            }
        }
    } else {
        /* gfr is already set up */
        newframe = DoComposite( frame, with, &gfr,
                                v.method, (WORD) v.ratio, v.tile,
                                PPTBase );
    }

    if(Win) DisposeObject(Win);

    if( newframe ) {
        PutOptions( MYNAME, &v, sizeof(struct Values) );
    }

    D(bug("Returning %08X...\n",newframe));
    return newframe;
}
Esempio n. 13
0
glbsp_ret_e GlbspCheckInfo(nodebuildinfo_t *info,
    volatile nodebuildcomms_t *comms)
{
  cur_comms = comms;
  SetErrorMsg("(Unknown Problem)");

  info->same_filenames = FALSE;
  info->missing_output = FALSE;

  if (!info->input_file || info->input_file[0] == 0)
  {
    SetErrorMsg("Missing input filename !");
    return GLBSP_E_BadArgs;
  }

  if (CheckExtension(info->input_file, "gwa"))
  {
    SetErrorMsg("Input file cannot be GWA (contains nothing to build)");
    return GLBSP_E_BadArgs;
  }

  if (!info->output_file || info->output_file[0] == 0)
  {
    GlbspFree(info->output_file);
    info->output_file = GlbspStrDup(ReplaceExtension(
          info->input_file, "gwa"));

    info->gwa_mode = TRUE;
    info->missing_output = TRUE;
  }
  else  /* has output filename */
  {
    if (CheckExtension(info->output_file, "gwa"))
      info->gwa_mode = TRUE;
  }

  if (UtilStrCaseCmp(info->input_file, info->output_file) == 0)
  {
    info->load_all = TRUE;
    info->same_filenames = TRUE;
  }

  if (info->no_prune && info->pack_sides)
  {
    info->pack_sides = FALSE;
    SetErrorMsg("-noprune and -packsides cannot be used together");
    return GLBSP_E_BadInfoFixed;
  }

  if (info->gwa_mode && info->force_normal)
  {
    info->force_normal = FALSE;
    SetErrorMsg("-forcenormal used, but GWA files don't have normal nodes");
    return GLBSP_E_BadInfoFixed;
  }
 
  if (info->no_normal && info->force_normal)
  {
    info->force_normal = FALSE;
    SetErrorMsg("-forcenormal and -nonormal cannot be used together");
    return GLBSP_E_BadInfoFixed;
  }
 
  if (info->factor <= 0 || info->factor > 32)
  {
    info->factor = DEFAULT_FACTOR;
    SetErrorMsg("Bad factor value !");
    return GLBSP_E_BadInfoFixed;
  }

  if (info->spec_version <= 0 || info->spec_version > 5)
  {
    info->spec_version = 2;
    SetErrorMsg("Bad GL-Nodes version number !");
    return GLBSP_E_BadInfoFixed;
  }
  else if (info->spec_version == 4)
  {
    info->spec_version = 5;
    SetErrorMsg("V4 GL-Nodes is not supported");
    return GLBSP_E_BadInfoFixed;
  }

  if (info->block_limit < 1000 || info->block_limit > 64000)
  {
    info->block_limit = DEFAULT_BLOCK_LIMIT;
    SetErrorMsg("Bad blocklimit value !");
    return GLBSP_E_BadInfoFixed;
  }

  return GLBSP_E_OK;
}
Esempio n. 14
0
File: djvu.c Progetto: jalkanen/ppt
/*
    Format can be any of CSF_* - flags
*/
IOSAVE(fh,format,frame,tags,PPTBase,IOModuleBase)
{
    D(bug("IOSave(type=%08X)\n",format));
    SetErrorMsg(frame,"This is just a test");
    return PERR_UNKNOWNTYPE;
}
bool MySQLDAImpl::Exec( Context &context, ParameterMapper *in, ResultMapper *out)
{
	StartTrace(MySQLDAImpl.Exec);

	MYSQL mysql, *sock;
	MYSQL_RES *res;

	mysql_init(&mysql);

	// make connection
	// mysql, localhost or other host, loginname,
	String dataBase;
	in->Get("Database", dataBase, context);

	String user("No user specified!");
	in->Get("MySQLUser", user, context);

	String pw("No password specified!");
	in->Get("MySQLPW", pw, context);

	TraceAny(fConfig, "config");
	String host("localhost");
	in->Get("Host", host, context);
	long port = 3306L;
	in->Get("Port", port, context);

	Trace("trying connect to DB:[" << dataBase << "], with user@host:port [" << user << "@" << host << ":" << port << "], and pass:[" << pw << "]");
	if (!(sock = mysql_real_connect(&mysql, host, user, pw, dataBase, port, NULL, 0))) {
		SetErrorMsg("Couldn't connect to mySQL engine!", &mysql, context, out);
		return false;
	}

	// first part of transaction, assemble query from arguments
	String theQuery;
	OStringStream os(theQuery);
	in->Get("SQL", os, context);
	os.flush();
	SubTrace (Query, "QUERY IS:" << theQuery );

	bool result = true;
	if (mysql_query(sock, theQuery)) {
		SetErrorMsg("Query failed", sock, context, out);
		result = false;
	} else {
		if (!(res = mysql_store_result(sock))) {
			// No results -- was INSERT or UPDATE etc
			Anything queryResults;
			out->Put("QueryResult", queryResults, context);
		} else {
			// process result- res fields are placed into anything...
			long num_fields = mysql_num_fields(res);
			Trace("Number of fields:" << num_fields);
			MYSQL_FIELD *fields = mysql_fetch_fields(res);

			// fill rows
			Anything theSet;
			MYSQL_ROW myRow;
			long rowNum = 0;
			while ( (myRow = mysql_fetch_row(res) ) ) {
				Anything newRow;

				for (long i = 0; i < num_fields; i++) {
					String fieldName = fields[i].name;
					newRow[fieldName] = myRow[i];					// assume only char *
				}
				TraceAny(newRow, "Row");
				Anything rowNumber = rowNum++;
				theSet[rowNumber.AsString("X")] = newRow;
			}
			TraceAny(theSet, "The Set");

			if (!Lookup("NoQueryCount", 0L)) {
				out->Put("QueryCount", rowNum, context);
			}
			out->Put("QueryResult", theSet, context);
		}
		mysql_free_result(res);
	}

	mysql_close(sock);
	if (mysql_errno(sock)) {
		SetErrorMsg("close failed !", sock, context, out);
		result = false;
	}

	return result;
}
Esempio n. 16
0
File: djvu.c Progetto: jalkanen/ppt
IOLOAD(fh,frame,tags,PPTBase,IOModuleBase)
{
    D(bug("IOLoad()\n"));
    SetErrorMsg(frame,"This is just a test");
    return PERR_ERROR;
}
Esempio n. 17
0
int Handler::HandleError(const char *msg)
{
    if (m_iErrFunc <= 0)
        return 0;

    m_Handling = true;
    m_pTrace = NULL;
    m_FmtCache.clear();

    Debugger *pDebugger = (Debugger *)m_pAmx->userdata[UD_DEBUGGER];

    int error = m_pAmx->error;

    static char _buffer[512];
    if (pDebugger)
    {
        pDebugger->SetTracedError(error);
        m_pTrace = pDebugger->GetTraceStart();
        pDebugger->FormatError(_buffer, sizeof(_buffer)-1);
        m_FmtCache.assign(_buffer);
        pDebugger->BeginExec();
    } else {
        Debugger::FmtGenericMsg(m_pAmx, error, _buffer, sizeof(_buffer)-1);
        m_FmtCache.assign(_buffer);
    }

    SetErrorMsg(msg);

    cell hea_addr, *phys_addr, result;

    amx_PushString(m_pAmx, &hea_addr, &phys_addr, msg, 0, 0);
    amx_Push(m_pAmx, pDebugger ? 1 : 0);
    amx_Push(m_pAmx, error);
    int err = amx_Exec(m_pAmx, &result, m_iErrFunc);
    if (err != AMX_ERR_NONE)
    {
        //handle this manually.
        if (pDebugger)
        {
            pDebugger->SetTracedError(err);
            pDebugger->DisplayTrace(msg);
        } else {
            if (GetLastMsg())
                AMXXLOG_Error("%s", GetLastMsg());
            Debugger::GenericMessage(m_pAmx, err);
        }
        AMXXLOG_Error("[AMXX] NOTE: Runtime failures in an error filter are not good!");
    }

    if (pDebugger)
        pDebugger->EndExec();

    amx_Release(m_pAmx, hea_addr);

    m_Handling = false;
    m_pTrace = NULL;
    m_FmtCache.clear();

    if (err != AMX_ERR_NONE || !result)
        return 0;

    return result;
}
void DeleteFileOrFolderReq(RequestPacket* req,
void* args, ResponsePacket* resp) {
    SetErrorMsg(0,"",resp);
}
Esempio n. 19
0
/*
 * lnd_name:lljz_net_disk_name
*/
void CreateFolderReq(RequestPacket* req,
void* args, ResponsePacket* resp) {
    Document req_doc;
/*
    Document resp_doc;
    Document::AllocatorType& resp_allocator=resp_doc.GetAllocator();
    StringBuffer resp_buffer;
    Writer<StringBuffer> resp_writer(resp_buffer);
    Value resp_json(kObjectType);
    Value resp_error_msg(kStringType);
*/

    TBSYS_LOG(DEBUG,"-------data:%s",req->data_);
    req_doc.Parse(req->data_);
    
    if (!CheckAuth(req,resp))
        return;

    if (!req_doc.HasMember("folder_name") 
        || !req_doc["folder_name"].IsString() 
        || !req_doc["folder_name"].GetStringLength()) {
        SetErrorMsg(35001,"folder_name is invalid",resp);
        return;        
    }

    const char* folder_name=req_doc["folder_name"].GetString();
    char value[200];
    char file_name[200];
    int file_n=0;
    int num=GetCharCount(folder_name, '/')+1;
    int i=0;
    //  /a/b//c//d
    for (i=0;i<num;i++) {
        GetStrValue(folder_name, '/', i+1, value);
        if (value[0]=='\0')
            continue;
        sprintf(file_name,"%s",value);
        file_n++;
    }
    if (0==file_n) {
        SetErrorMsg(35003,"path of new folder is invalid",resp);
        return;
    }

    RedisClient* file_rc=g_file_redis->GetRedisClient();
    char cmd[512];
    redisReply* reply;
    int cmd_ret;
    //是否存在根目录,父目录,新目录
    char father_name[200];
    sprintf(father_name,"folder_%s",req_doc["account"].GetString());
    sprintf(cmd,"HGET %s %c_%s", father_name,0x02,"create_time");
    cmd_ret=Rhget(file_rc,cmd,reply);
    if (FAILED_NOT_ACTIVE==cmd_ret) {//网络错误
        g_file_redis->ReleaseRedisClient(file_rc,cmd_ret);
        SetErrorMsg(35002,"redis database server is busy",resp);
        return;
    } else if (FAILED_ACTIVE==cmd_ret) {//没有父目录
        //记录异常日志
        g_file_redis->ReleaseRedisClient(file_rc,cmd_ret);
        SetErrorMsg(35003,"path of root folder does not exist",resp);
        return;
    }

    int counter=0;
    for (i=0;i<num;i++) {
        GetStrValue(folder_name, '/', i+1, value);
        if (value[0]=='\0')
            continue;
        counter++;
        if (counter>=file_n)
            break;
        sprintf(cmd,"HGET %s %s", father_name,value);
        cmd_ret=Rhget(file_rc,cmd,reply,false);
        if (FAILED_NOT_ACTIVE==cmd_ret) {//网络错误
            g_file_redis->ReleaseRedisClient(file_rc,cmd_ret);
            SetErrorMsg(35002,"redis database server is busy",resp);
            return;
        } else if (FAILED_ACTIVE==cmd_ret) {//没有父目录
            //记录异常日志
            g_file_redis->ReleaseRedisClient(file_rc,cmd_ret);
            freeReplyObject(reply);
            SetErrorMsg(35003,"path of parent folder does not exist",resp);
            return;
        }
        //
        if (0==reply->len) {
            //记录异常日志
            g_file_redis->ReleaseRedisClient(file_rc,cmd_ret);
            freeReplyObject(reply);
            SetErrorMsg(35003,"path of parent folder does not exist",resp);
            return;
        }
        sprintf(father_name,"%s",reply->str);
        freeReplyObject(reply);
    }

    //增加新文件夹,lnd_name不能冲突
    //取得file_id
    sprintf(cmd,"SPOP file_id_sets_%s",
        req_doc["account"].GetString());
    cmd_ret=Rspop(file_rc,cmd,reply,false);
    if (FAILED_NOT_ACTIVE==cmd_ret) {//网络错误
        g_file_redis->ReleaseRedisClient(file_rc,cmd_ret);
        SetErrorMsg(35002,"get file_id fail,redis database server is busy",resp);
        return;
    } else if (FAILED_ACTIVE==cmd_ret) {
        //记录异常日志
        g_file_redis->ReleaseRedisClient(file_rc,cmd_ret);
        freeReplyObject(reply);
        SetErrorMsg(35006,"get file_id fail,file_id is used out",resp);
        return;
    }

    //在父目录增加记录
    char lnd_name[512];
    sprintf(lnd_name,"%d%c%s%c%s", 0,0x01,
        req_doc["account"].GetString(),0x01,reply->str);
    freeReplyObject(reply);
    sprintf(cmd,"HSETNX %s %s %s",father_name,file_name, lnd_name);
    cmd_ret=Rhsetnx(file_rc,cmd,reply);
    if (FAILED_NOT_ACTIVE==cmd_ret) {//网络错误
        g_file_redis->ReleaseRedisClient(file_rc,false);
        SetErrorMsg(35002,"redis database server is busy",resp);
        return;
    } else if (FAILED_ACTIVE==cmd_ret) {
        //记录异常日志
        g_file_redis->ReleaseRedisClient(file_rc,true);
        SetErrorMsg(35006,"create folder fail,folder has existed",resp);
        return;
    }

    //为新文件夹增加hash表
    sprintf(cmd,"HSETNX %s %c_create_time %lld",
        lnd_name,0x02, tbsys::CTimeUtil::getTime());
    cmd_ret=Rhsetnx(file_rc,cmd,reply);
    if (FAILED_NOT_ACTIVE==cmd_ret) {//网络错误
        g_file_redis->ReleaseRedisClient(file_rc,false);
        SetErrorMsg(35002,"create folder fail,redis database server is busy",resp);
        return;
    } else if (FAILED_ACTIVE==cmd_ret) {
        //记录异常日志
        g_file_redis->ReleaseRedisClient(file_rc,true);
        SetErrorMsg(35006,"file_id has used,redis database server status error",resp);
        return;
    }
    g_file_redis->ReleaseRedisClient(file_rc,true);

    SetErrorMsg(0,"",resp);
}
Esempio n. 20
0
glbsp_ret_e GlbspParseArgs(nodebuildinfo_t *info, 
    volatile nodebuildcomms_t *comms,
    const char ** argv, int argc)
{
  const char *opt_str;
  int num_files = 0;
  int got_output = FALSE;

  cur_comms = comms;
  SetErrorMsg("(Unknown Problem)");

  while (argc > 0)
  {
    if (argv[0][0] != '-')
    {
      // --- ORDINARY FILENAME ---

      if (got_output)
      {
        SetErrorMsg("Input filenames must precede the -o option");
        cur_comms = NULL;
        return GLBSP_E_BadArgs;
      }

      if (CheckExtension(argv[0], "gwa"))
      {
        SetErrorMsg("Input file cannot be GWA (contains nothing to build)");
        cur_comms = NULL;
        return GLBSP_E_BadArgs;
      }

      if (num_files >= 1)
      {
        AddExtraFile(info, GlbspStrDup(argv[0]));
      }
      else
      {
        GlbspFree(info->input_file);
        info->input_file = GlbspStrDup(argv[0]);
      }

      num_files++;

      argv++; argc--;
      continue;
    }

    // --- AN OPTION ---

    opt_str = &argv[0][1];

    // handle GNU style options beginning with '--'
    if (opt_str[0] == '-')
      opt_str++;

    if (UtilStrCaseCmp(opt_str, "o") == 0)
    {
      if (got_output)
      {
        SetErrorMsg("The -o option cannot be used more than once");
        cur_comms = NULL;
        return GLBSP_E_BadArgs;
      }

      if (num_files >= 2)
      {
        SetErrorMsg("Cannot use -o with multiple input files.");
        cur_comms = NULL;
        return GLBSP_E_BadArgs;
      }

      if (argc < 2 || argv[1][0] == '-')
      {
        SetErrorMsg("Missing filename for the -o option");
        cur_comms = NULL;
        return GLBSP_E_BadArgs;
      }

      GlbspFree(info->output_file);
      info->output_file = GlbspStrDup(argv[1]);

      got_output = TRUE;

      argv += 2; argc -= 2;
      continue;
    }

    if (UtilStrCaseCmp(opt_str, "factor") == 0 ||
        UtilStrCaseCmp(opt_str, "c") == 0)
    {
      if (argc < 2)
      {
        SetErrorMsg("Missing factor value");
        cur_comms = NULL;
        return GLBSP_E_BadArgs;
      }

      info->factor = (int) strtol(argv[1], NULL, 10);

      argv += 2; argc -= 2;
      continue;
    }

    if (tolower(opt_str[0]) == 'v' && isdigit(opt_str[1]))
    {
      info->spec_version = (opt_str[1] - '0');

      argv++; argc--;
      continue;
    }

    if (UtilStrCaseCmp(opt_str, "maxblock") == 0 ||
        UtilStrCaseCmp(opt_str, "b") == 0)
    {
      if (argc < 2)
      {
        SetErrorMsg("Missing maxblock value");
        cur_comms = NULL;
        return GLBSP_E_BadArgs;
      }

      info->block_limit = (int) strtol(argv[1], NULL, 10);

      argv += 2; argc -= 2;
      continue;
    }

    HANDLE_BOOLEAN2("q",  "quiet",      quiet)
    HANDLE_BOOLEAN2("f",  "fast",       fast)
    HANDLE_BOOLEAN2("w",  "warn",       mini_warnings)
    HANDLE_BOOLEAN2("p",  "pack",       pack_sides)
    HANDLE_BOOLEAN2("n",  "normal",     force_normal)
    HANDLE_BOOLEAN2("xr", "noreject",   no_reject)
    HANDLE_BOOLEAN2("xp", "noprog",     no_progress)

    HANDLE_BOOLEAN2("m",  "mergevert",   merge_vert)
    HANDLE_BOOLEAN2("u",  "prunesec",    prune_sect)
    HANDLE_BOOLEAN2("y",  "windowfx",    window_fx)
    HANDLE_BOOLEAN2("s",  "skipselfref", skip_self_ref)
    HANDLE_BOOLEAN2("xu", "noprune",     no_prune)
    HANDLE_BOOLEAN2("xn", "nonormal",    no_normal)

    // to err is human...
    HANDLE_BOOLEAN("noprogress",  no_progress)
    HANDLE_BOOLEAN("packsides",   pack_sides)
    HANDLE_BOOLEAN("prunesect",   prune_sect)

    // ignore these options for backwards compatibility
    if (UtilStrCaseCmp(opt_str, "fresh") == 0 ||
        UtilStrCaseCmp(opt_str, "keepdummy") == 0 ||
        UtilStrCaseCmp(opt_str, "keepsec") == 0 ||
        UtilStrCaseCmp(opt_str, "keepsect") == 0)
    {
      argv++; argc--;
      continue;
    }

    // backwards compatibility
    HANDLE_BOOLEAN("forcegwa",    gwa_mode)
    HANDLE_BOOLEAN("forcenormal", force_normal)
    HANDLE_BOOLEAN("loadall",     load_all)

    // The -hexen option is only kept for backwards compatibility
    HANDLE_BOOLEAN("hexen", force_hexen)

    SetErrorMsg("Unknown option: %s", argv[0]);

    cur_comms = NULL;
    return GLBSP_E_BadArgs;
  }

  cur_comms = NULL;
  return GLBSP_E_OK;
}
Esempio n. 21
0
glbsp_ret_e GlbspBuildNodes(const nodebuildinfo_t *info,
    const nodebuildfuncs_t *funcs, volatile nodebuildcomms_t *comms)
{
  char *file_msg;

  glbsp_ret_e ret = GLBSP_E_OK;

  cur_info  = info;
  cur_funcs = funcs;
  cur_comms = comms;

  cur_comms->total_big_warn = 0;
  cur_comms->total_small_warn = 0;

  // clear cancelled flag
  comms->cancelled = FALSE;

  // sanity check
  if (!cur_info->input_file  || cur_info->input_file[0] == 0 ||
      !cur_info->output_file || cur_info->output_file[0] == 0)
  {
    SetErrorMsg("INTERNAL ERROR: Missing in/out filename !");
    return GLBSP_E_BadArgs;
  }

  InitDebug();
  InitEndian();
 
  if (info->missing_output)
    PrintMsg("* No output file specified. Using: %s\n\n", info->output_file);

  if (info->same_filenames)
    PrintMsg("* Output file is same as input file. Using -loadall\n\n");

  // opens and reads directory from the input wad
  ret = ReadWadFile(cur_info->input_file);

  if (ret != GLBSP_E_OK)
  {
    TermDebug();
    return ret;
  }

  if (CountLevels() <= 0)
  {
    CloseWads();
    TermDebug();

    SetErrorMsg("No levels found in wad !");
    return GLBSP_E_Unknown;
  }
   
  PrintMsg("\n");
  PrintVerbose("Creating nodes using tunable factor of %d\n", info->factor);

  DisplayOpen(DIS_BUILDPROGRESS);
  DisplaySetTitle("glBSP Build Progress");

  file_msg = UtilFormat("File: %s", cur_info->input_file);
 
  DisplaySetBarText(2, file_msg);
  DisplaySetBarLimit(2, CountLevels() * 10);
  DisplaySetBar(2, 0);

  UtilFree(file_msg);
  
  cur_comms->file_pos = 0;
  
  // loop over each level in the wad
  while (FindNextLevel())
  {
    ret = HandleLevel();

    if (ret != GLBSP_E_OK)
      break;

    cur_comms->file_pos += 10;
    DisplaySetBar(2, cur_comms->file_pos);
  }

  DisplayClose();

  // writes all the lumps to the output wad
  if (ret == GLBSP_E_OK)
  {
    ret = WriteWadFile(cur_info->output_file);

    // when modifying the original wad, any GWA companion must be deleted
    if (ret == GLBSP_E_OK && cur_info->same_filenames)
      DeleteGwaFile(cur_info->output_file);

    PrintMsg("\n");
    PrintMsg("Total serious warnings: %d\n", cur_comms->total_big_warn);
    PrintMsg("Total minor warnings: %d\n", cur_comms->total_small_warn);

    ReportFailedLevels();
  }

  // close wads and free memory
  CloseWads();

  TermDebug();

  cur_info  = NULL;
  cur_comms = NULL;
  cur_funcs = NULL;

  return ret;
}
void ModifyLoginPasswordReq(RequestPacket* req,
void* args, ResponsePacket* resp) {
    Document req_doc;
/*    Document resp_doc;
    Document::AllocatorType& resp_allocator=resp_doc.GetAllocator();
    StringBuffer resp_buffer;
    Writer<StringBuffer> resp_writer(resp_buffer);
    Value resp_json(kObjectType);
    Value resp_error_msg(kStringType);
*/
    TBSYS_LOG(DEBUG,"-------data:%s",req->data_);
    req_doc.Parse(req->data_);

    //检查account
    if (!req_doc.HasMember("account") 
        || !req_doc["account"].IsString()
        || 0==req_doc["account"].GetStringLength()) {
        SetErrorMsg(20001,"account is invalid",resp);
        return;
    }

    //检查old_password
    if (!req_doc.HasMember("old_password") 
        || !req_doc["old_password"].IsString()
        || 0==req_doc["old_password"].GetStringLength()) {
        SetErrorMsg(20001,"old_password is invalid",resp);
        return;
    }
    
    //检查new_password
    if (!req_doc.HasMember("new_password") 
        || !req_doc["new_password"].IsString()
        || 0==req_doc["new_password"].GetStringLength()) {
        SetErrorMsg(20001,"new_password is invalid",resp);
        return;
    }

    //判断账号是否存在
    RedisClient* rc=g_account_redis->GetRedisClient();
    char cmd[512];
    sprintf(cmd,"EXISTS %s", req_doc["account"].GetString());
    redisReply* reply;
    int cmd_ret=Rexists(rc,cmd,reply);
    if (FAILED_NOT_ACTIVE==cmd_ret) {
        g_account_redis->ReleaseRedisClient(rc,false);
        SetErrorMsg(20002,"redis database server is busy",resp);
        return;
    } else if (FAILED_ACTIVE==cmd_ret) {
        g_account_redis->ReleaseRedisClient(rc,true);
        SetErrorMsg(20003,"account does not exist",resp);
        return;
    }

    sprintf(cmd,"HGET %s password", req_doc["account"].GetString());
    cmd_ret=Rhget(rc,cmd,reply,false);
    if (FAILED_NOT_ACTIVE==cmd_ret) {//网络错误
        g_account_redis->ReleaseRedisClient(rc,false);
        SetErrorMsg(20002,"redis database server is busy",resp);
        return;
    } else if (FAILED_ACTIVE==cmd_ret) {//没有字段password,允许直接设置密码
    } else {
        if (0!=strcmp(req_doc["old_password"].GetString(),reply->str)) {
            g_account_redis->ReleaseRedisClient(rc,true);
            SetErrorMsg(20005,"login password is wrong",resp);
            freeReplyObject(reply);
            return;
        }
    }
    freeReplyObject(reply);
    if (0==strcmp(req_doc["old_password"].GetString(),
                req_doc["new_password"].GetString()) ) {//新密码不变
        g_account_redis->ReleaseRedisClient(rc,true);
        SetErrorMsg(0,"",resp);
        return;
    }

    sprintf(cmd,"HSET %s password %s",
        req_doc["account"].GetString(),
        req_doc["new_password"].GetString());
    cmd_ret=Rhset(rc,cmd,reply);
    if (FAILED_NOT_ACTIVE==cmd_ret) {//网络错误
        g_account_redis->ReleaseRedisClient(rc,false);
        SetErrorMsg(20006,"modify login password failed,redis database server is busy",resp);
        return;
    } else if (FAILED_ACTIVE == cmd_ret) {
        g_account_redis->ReleaseRedisClient(rc,true);
        SetErrorMsg(20006,"modify login password fail",resp);
        return;
    }

    g_account_redis->ReleaseRedisClient(rc,true);
    SetErrorMsg(0,"",resp);
}