コード例 #1
0
ファイル: ami-rexx.c プロジェクト: CrashSerious/PiUAE
struct MsgPort *CreatePort (STRPTR name, LONG pri)
{
    struct MsgPort *port = NULL;
    UBYTE portsig;

    if ((BYTE)(portsig = AllocSignal (-1)) >= 0) {
	if (!(port = PPCAllocMem (sizeof (struct MsgPort), MEMF_CLEAR | MEMF_PUBLIC)))
	    FreeSignal(portsig);
	else {
	    port->mp_Node.ln_Type = NT_MSGPORT;
	    port->mp_Node.ln_Pri  = pri;
	    port->mp_Node.ln_Name = name;
	    /* done via AllocMem
	     * port->mp_Flags = PA_SIGNAL;
	     */
	    port->mp_SigBit  = portsig;
	    port->mp_SigTask = FindTask (NULL);
	    NEWLIST (&port->mp_MsgList);
	    if (port->mp_Node.ln_Name)
		AddPort(port);
	}
    }
    return port;
}
コード例 #2
0
ファイル: debug.c プロジェクト: samskivert/garshneblanker
int main( void )
{
	struct Process *Proc = ( struct Process * )FindTask( 0L );
	BlankMsg *FreeMsg;
	LONG ReturnVal = 0;
	
	if( Proc->pr_CLI )
	{
		STRPTR Str = BADDR((( struct CommandLineInterface * )
							BADDR( Proc->pr_CLI ))->cli_CommandName );
		CopyMem( Str + 1, PrefsPath, *Str );
		PrefsPath[*Str] = '\0';
		strcat( PrefsPath, ".prefs" );
	}
	
	IntuitionBase = OpenLibrary( "intuition.library", 37L );
	GfxBase = OpenLibrary( GRAPHICSNAME, 37L );
	GarshnelibBase = OpenLibrary( "Garshnelib.library", 37L );
	
	if( IntuitionBase && GfxBase && GarshnelibBase )
	{
		ClientPort = CreateMsgPort();
		TimerPort = CreateMsgPort();
		
		if( ClientPort && TimerPort )
		{
			TimeOutIO = ( struct timerequest * )
				CreateExtIO( TimerPort, sizeof( struct timerequest ));
			
			if( TimeOutIO && !OpenDevice( "timer.device", UNIT_VBLANK,
										 ( struct IORequest * )TimeOutIO, 0L ))
			{
				ClientPort->mp_Node.ln_Name = PortName;
				ClientPort->mp_Node.ln_Pri = 0L;
				AddPort( ClientPort );
				CurPrefs = LoadPrefs( PrefsPath );
				
				CurrentTime( &InitSecs, &InitMicros );
				RangeSeed = InitSecs + InitMicros;
				
				Blank( CurPrefs );

				while( FreeMsg = ( BlankMsg * )GetMsg( ClientPort ))
				{
					if( FreeMsg->bm_Type & BF_REPLY )
						FreeVec( FreeMsg );
					else
					{
						FreeMsg->bm_Type |= BF_REPLY;
						ReplyMsg(( struct Message * )FreeMsg );
					}
				}
				
				if( CurPrefs )
					FreeVec( CurPrefs );
			
				if( !PortRemoved )
					RemPort( ClientPort );
			}
			
			if( TimeOutIO )
			{
				if( TimeOutIO->tr_node.io_Device )
					CloseDevice(( struct IORequest * )TimeOutIO );
				DeleteExtIO(( struct IORequest * )TimeOutIO );
			}
		}
		else
		{
			Complain( "ClientPort or TimerPort failed to open." );
			ReturnVal = 2;
		}

		if( ClientPort )
		{
			BlankMsg *TmpMsg;
			while( TmpMsg = ( BlankMsg * )GetMsg( ClientPort ))
			{
				TmpMsg->bm_Flags |= BF_REPLY;
				ReplyMsg(( struct Message * )TmpMsg );
			}
			DeleteMsgPort( ClientPort );
		}

		if( TimerPort )
			DeleteMsgPort( TimerPort );
	}
	else
	{
		Complain( "A library failed to open." );
		ReturnVal = 1;
	}
	
	if( GarshnelibBase )
		CloseLibrary( GarshnelibBase );
	
	if( GfxBase )
		CloseLibrary( GfxBase );
	
	if( IntuitionBase )
		CloseLibrary( IntuitionBase );
	
	return ReturnVal;
}
コード例 #3
0
bool Frontend::RPC( const HTTPRequest &request, const std::string &cat, const std::string &action )
{
  if( cat == "port" )
  {
    int port_id;
    if( !request.GetParam( "port_id", port_id ))
      return false;

    LockPorts( );
    std::map<int, Port *>::iterator it = ports.find( port_id );
    if( it == ports.end( ))
    {
      LogError( "Port %d not found", port_id );
      return false;
    }
    bool ret = it->second->RPC( request, cat, action );
    UnlockPorts( );
    return ret;
  }

  if( action == "create_port" )
  {
    int port_num;
    if( !request.GetParam( "port_num", port_num ))
      return false;
    std::string name;
    if( !request.GetParam( "name", name ))
      return false;
    int source_id;
    if( !request.GetParam( "source_id", source_id ))
      return false;

    Port *port = AddPort( name, port_num );
    if( port == NULL )
    {
      request.NotFound( "Port with number %d already exists", port_num );
      return false;
    }

    Source *source = TVDaemon::Instance( )->GetSource( source_id );
    if( !source )
      LogError( "Source not found: %d", source_id );
    else
    {
      source->AddPort( port );
      port->SetSource( source );
    }
    request.Reply( HTTP_OK, port->GetKey( ));
    return true;
  }

  if( action == "delete_port" )
  {
    int port_id;
    if( !request.GetParam( "port_id", port_id ))
      return false;
    LockPorts( );
    std::map<int, Port *>::iterator it = ports.find( port_id );
    if( it == ports.end( ))
    {
      LogError( "Port not found: %d", port_id );
      UnlockPorts( );
      return false;
    }
    it->second->Delete( );
    delete it->second;
    ports.erase( it );
    UnlockPorts( );

    return true;
  }

  request.NotFound( "RPC unknown action: '%s'", action.c_str( ));
  return false;
}
コード例 #4
0
ファイル: Ser.c プロジェクト: jayminer81/NiKom
void main(int argc,char *argv[]) {
    int going=TRUE,forsok=2,car=1,x,connectbps, i, tmp;
    struct NodeType *nt;
    char *tmppscreen,commandstring[100], configname[50] = "NiKom:DatoCfg/SerNode.cfg";
    FILE *fil;
    if(argc>1) for(x=1; x<argc; x++) {
            if(argv[x][0]=='-') {
                if(argv[x][1]=='G') getty=TRUE;
                else if(argv[x][1]=='B') gettybps=atoi(&argv[x][2]);
                else if(argv[x][1]=='C') connectbps = atoi(&argv[x][2]);
            } else strcpy(configname,argv[x]);
        }
    if(!(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0)))
        cleanup(ERROR,"Kunde inte öppna intuition.library\n");
    if(!(UtilityBase=OpenLibrary("utility.library",37L)))
        cleanup(ERROR,"Kunde inte öppna utility.library\n");
    if(!(NiKomBase=OpenLibrary("nikom.library",0L)))
        cleanup(ERROR,"Kunde inte öppna nikom.library\n");
    if(!initnode(NODSER)) cleanup(ERROR,"Kunde inte registrera noden i Servern\n");
    if(!(nikomnodeport = CreateMsgPort()))
        cleanup(ERROR,"Kunde inte skapa NiKomNode-porten");
    sprintf(nikomnodeportnamn,"NiKomNode%d",nodnr);
    nikomnodeport->mp_Node.ln_Name = nikomnodeportnamn;
    nikomnodeport->mp_Node.ln_Pri = 1;
    AddPort(nikomnodeport);
    sprintf(rexxportnamn,"NiKomPreRexx%d",nodnr);
    if(!(rexxport=(struct MsgPort *)CreateMsgPort()))
        cleanup(ERROR,"Kunde inte öppna RexxPort\n");
    rexxport->mp_Node.ln_Name=rexxportnamn;
    rexxport->mp_Node.ln_Pri=50;
    AddPort(rexxport);
    if(!(RexxSysBase=(struct RsxLib *)OpenLibrary("rexxsyslib.library",0L)))
        cleanup(ERROR,"Kunde inte öppna rexxsyslib.library\n");
    getnodeconfig(configname);
    if(pubscreen[0]=='-') tmppscreen=NULL;
    else tmppscreen=pubscreen;
    if(!(NiKwind=openmywindow(tmppscreen)))
        cleanup(ERROR,"Kunde inte öppna fönstret\n");
    if(getty) dtespeed = gettybps;
    else dtespeed = highbaud;
    if(!OpenIO(NiKwind)) cleanup(ERROR,"Couldn't setup IO");
    strcpy(Servermem->nodid[nodnr],nodid);
    conreqtkn();
    serreqtkn();
    Delay(50);
    for(;;) {
        inloggad=-1;
        Servermem->idletime[nodnr] = time(NULL);
        Servermem->inloggad[nodnr]=-1;
        if(getty) Servermem->connectbps[nodnr] = connectbps;
        else waitconnect();
        Servermem->idletime[nodnr] = time(NULL);
        Servermem->inloggad[nodnr]=-2; /* Sätt till <Uppringd> för att även hantera -getty-fallet */
reloginspec:
        updateinactive();
        Servermem->inne[nodnr].flaggor = Servermem->cfg.defaultflags;
        if(!getty) Delay(100);
        Servermem->inne[nodnr].rader=0;
        Servermem->inne[nodnr].chrset = CHRS_LATIN1;
        sendfile("NiKom:Texter/Inlogg.txt");
        if(Servermem->cfg.ar.preinlogg) sendrexx(Servermem->cfg.ar.preinlogg);
        car=TRUE;
        Servermem->inne[nodnr].chrset = 0;
        memset(commandhistory,0,1000);
        going=1;
        while(going && going<=Servermem->cfg.logintries) {
            putstring("\r\nNamn: ",-1,0);
            if(getstring(EKO,40,NULL)) {
                car=FALSE;
                break;
            }
            if(!stricmp(inmat,Servermem->cfg.ny)
                    && !(Servermem->cfg.cfgflags & NICFG_CLOSEDBBS)) {
                tmp = RegisterNewUser();
                if(tmp == 2) {
                    goto panik;
                }
                car = tmp ? 0 : 1;
                going=FALSE;
            } else if((inloggad=parsenamn(inmat))>=0) {
                if(readuser(inloggad,&Servermem->inne[nodnr])) {
                    puttekn("Error reading user data.\r\n", -1);
                    goto panik;
                }
                // TODO: Extract password loop. Should be identical to in NiKomCon.c
                forsok=2;
                while(forsok) {
                    puttekn("\r\nLösen: ",-1);
                    if(Servermem->inne[nodnr].flaggor & STAREKOFLAG)
                    {
                        if(getstring(STAREKO,15,NULL)) {
                            car=FALSE;
                            break;
                        }
                    }
                    else
                    {
                        if(getstring(EJEKO,15,NULL)) {
                            car=FALSE;
                            break;
                        }
                    }
                    if(CheckPassword(inmat, Servermem->inne[nodnr].losen))
                    {
                        forsok=FALSE;
                        going=FALSE;
                    } else forsok--;
                }
                if(going && (Servermem->cfg.logmask & LOG_FAILINLOGG)) {
                    LogEvent(USAGE_LOG, WARN, "Nod %d, %s angivet som namn, fel lösen.",
                             nodnr, getusername(inloggad));
                }
                if(going) going++;
            } else if(inloggad==-1) puttekn("\r\nHittar ej namnet\r\n",-1);
        }
        if(!car) {
            if(getty) cleanup(OK,"");
            disconnect();
            continue;
        }
        if(going) {
            putstring("\n\n\rTyvärr. Du har försökt maximalt antal gånger att logga in. Kopplar ned.\n\r",-1,0);
            goto panik;      /* Urrk vad fult. :-) */
        }
        Servermem->inloggad[nodnr]=inloggad;
        Servermem->idletime[nodnr] = time(NULL);
        if((nt = selectNodeType()) == NULL) {
            goto panik;
        }
        abortinactive();
        abortserial();

        sprintf(commandstring,"%s -N%d -B%d %s",nt->path,nodnr,dtespeed,configname);
        CloseConsole();
        CloseWindow(NiKwind);
        NiKwind = NULL;
        RemPort(nikomnodeport);

        i = 0;
        if(Servermem->connectbps[nodnr] > 0)
        {
            while(Servermem->info.bps[i] != Servermem->connectbps[nodnr] && Servermem->info.bps[i] > 0 && i<49)
                i++;

            if(i<49)
            {
                if(Servermem->info.bps[i] == Servermem->connectbps[nodnr])
                    Servermem->info.antbps[i]++;
                else
                {
                    Servermem->info.bps[i] = Servermem->connectbps[nodnr];
                    Servermem->info.antbps[i]++;
                }
            }

            if(!(fil = fopen("NiKom:datocfg/sysinfo.dat","w")))
            {
                /* putstring("Kunde inte spara nya sysinfo.dat..\n",-1,0); */
            }

            if(fwrite((void *)&Servermem->info,sizeof(Servermem->info),1,fil) != 1)
            {
                /* putstring("Kunde inte skriva till nya sysinfo.dat....\n",-1,0); */
            }
            fclose(fil);
        }

        nodestate = SystemTags(commandstring, SYS_UserShell, TRUE, TAG_DONE);
        AddPort(nikomnodeport);
        if(!getty || (nodestate & NIKSTATE_RELOGIN)) {
            if(!(NiKwind = openmywindow(tmppscreen))) cleanup(ERROR,"Kunde inte öppna fönstret\n");
            OpenConsole(NiKwind);
        }
        serreqtkn();
        if(nodestate & NIKSTATE_RELOGIN) goto reloginspec;
panik:
        Delay(hangupdelay);
        if(getty) cleanup(OK,"");
        disconnect();
    }
}
コード例 #5
0
bool JaRuleDevice::StartHook() {
  AddPort(m_port.release());
  return true;
}
コード例 #6
0
BOOL CEnumerateSerial::EnumeratePorts()
{
  int SPDRPlist[] = {
    SPDRP_DEVICEDESC, SPDRP_FRIENDLYNAME, SPDRP_MFG, 
    SPDRP_LOCATION_INFORMATION, SPDRP_PHYSICAL_DEVICE_OBJECT_NAME, 
    -1};

  // Clear anything from previous enumerate...
  ResetPortList();

  // Dynamically get pointers to device installation library (setupapi.dll)
  // in case it isn't installed...
  //   SetupDiOpenDevRegKey
  //   SetupDiEnumDeviceInfo
  //   SetupDiDestroyDeviceInfoList
  //   SetupDiGetClassDevs
  //   SetupDiClassGuidsFromName
  //   SetupDiGetDeviceRegistryProperty 
  CLoadLib setupAPI(_T("SETUPAPI.DLL"));
  if (setupAPI == NULL) return FALSE;

#define SETUPPROC(x,y) x* lpfn##x = reinterpret_cast<x*>(GetProcAddress(setupAPI,y))
  SETUPPROC(SETUPDIOPENDEVREGKEY,"SetupDiOpenDevRegKey");
  SETUPPROC(SETUPDIENUMDEVICEINFO, "SetupDiEnumDeviceInfo");
  SETUPPROC(SETUPDIDESTROYDEVICEINFOLIST, "SetupDiDestroyDeviceInfoList");
#if defined _UNICODE
  SETUPPROC(SETUPDIGETCLASSDEVS, "SetupDiGetClassDevsW");
  SETUPPROC(SETUPDICLASSGUIDSFROMNAME, "SetupDiClassGuidsFromNameW");
  SETUPPROC(SETUPDIGETDEVICEREGISTRYPROPERTY, "SetupDiGetDeviceRegistryPropertyW");
#else
  SETUPPROC(SETUPDIGETCLASSDEVS, "SetupDiGetClassDevsA");
  SETUPPROC(SETUPDICLASSGUIDSFROMNAME, "SetupDiClassGuidsFromNameA");
  SETUPPROC(SETUPDIGETDEVICEREGISTRYPROPERTY, "SetupDiGetDeviceRegistryPropertyA");
#endif  
                       
  if ((lpfnSETUPDIOPENDEVREGKEY == NULL) || 
      (lpfnSETUPDIENUMDEVICEINFO == NULL) || 
      (lpfnSETUPDIGETDEVICEREGISTRYPROPERTY == NULL) ||
      (lpfnSETUPDIGETCLASSDEVS == NULL) || 
      (lpfnSETUPDICLASSGUIDSFROMNAME == NULL) || 
      (lpfnSETUPDIDESTROYDEVICEINFOLIST == NULL))
  {
    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    return FALSE;
  }
  
  // First need to convert the name "Ports" to a GUID using SetupDiClassGuidsFromName...
  DWORD dwGuids = 0;
  lpfnSETUPDICLASSGUIDSFROMNAME(_T("Ports"), NULL, 0, &dwGuids);
  if (dwGuids == 0) return FALSE;

  // Allocate the needed memory...
  CHeapPtr<GUID> GuidArray;
  GUID *pGuids = (GUID*)GuidArray.Allocate(sizeof(GUID) * dwGuids);
  if (pGuids==NULL) {
    SetLastError(ERROR_OUTOFMEMORY);
    return FALSE;
  }

  // Call the function again...
  if (!lpfnSETUPDICLASSGUIDSFROMNAME(_T("Ports"), pGuids, dwGuids, &dwGuids))
    return FALSE;

  // Now create a "device information set" which is required to enumerate all the ports...
  HDEVINFO hDevInfoSet = lpfnSETUPDIGETCLASSDEVS(pGuids, NULL, NULL, DIGCF_PRESENT);
  if (hDevInfoSet == INVALID_HANDLE_VALUE)
    return FALSE;

  // Finally do the enumeration...
  int nIndex = 0;
  SP_DEVINFO_DATA devInfo;
  CHeapPtr<TCHAR> tempstr(256);
  CSerialPortInfo *portinfo = NULL;

  // Enumerate the current device...
  devInfo.cbSize = sizeof(SP_DEVINFO_DATA);
  while (lpfnSETUPDIENUMDEVICEINFO(hDevInfoSet, nIndex, &devInfo))
  {
    portinfo = NULL;

    // Get the registry key which stores the ports settings...
    HKEY hDeviceKey = lpfnSETUPDIOPENDEVREGKEY(hDevInfoSet, &devInfo, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_QUERY_VALUE);
    if (hDeviceKey) {
      tempstr.FillZero();
      DWORD dwSize = tempstr.SizeOf(); 
      DWORD dwType = 0;

      // Read name of port.  If formatted as "COMxx" then allocate a port slot...
  	  if ((RegQueryValueEx(hDeviceKey, _T("PortName"), NULL, &dwType, reinterpret_cast<LPBYTE>((TCHAR*)tempstr), &dwSize) == ERROR_SUCCESS) && (dwType == REG_SZ))
        if (_tcslen(tempstr) > 3)
          if ((_tcsnicmp(tempstr, _T("COM"), 3) == 0) && IsNumber(&(tempstr[3])))
            portinfo = AddPort(_ttoi(&(tempstr[3])));

      // Close the key now that we are finished with it...
      RegCloseKey(hDeviceKey);
    }

    // If a serial port, then try getting additional useful descriptive info...
    if (portinfo) {
      for (int i=0; SPDRPlist[i]>=0; i++) {
        tempstr.FillZero(); 
        DWORD dwSize = tempstr.SizeOf(); 
        DWORD dwType = 0;
        if (lpfnSETUPDIGETDEVICEREGISTRYPROPERTY(hDevInfoSet, &devInfo, SPDRPlist[i], &dwType, reinterpret_cast<PBYTE>((TCHAR*)tempstr), dwSize, &dwSize) && (dwType == REG_SZ))
          switch (SPDRPlist[i]) {
            case SPDRP_MFG : portinfo->SetManufacturer(tempstr); break;
            case SPDRP_DEVICEDESC : portinfo->SetDeviceDesc(tempstr); break;
            case SPDRP_FRIENDLYNAME : portinfo->SetFriendlyName(tempstr); break;
            case SPDRP_LOCATION_INFORMATION : portinfo->SetLocationInfo(tempstr); break;
            case SPDRP_PHYSICAL_DEVICE_OBJECT_NAME : portinfo->SetPhysLocation(tempstr); break;
          }
      }

      // Get COM port properties...
      HANDLE hPort = ::CreateFile(portinfo->GetPortDeviceName(), GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
      if (hPort != INVALID_HANDLE_VALUE) {
        COMMPROP cp;
        GetCommProperties(hPort, &cp);
        portinfo->SetCommProp(cp);
        TRACE ("Port %d:  CommProp: maxbaud=%08x  settablebaud=%08x\n",portinfo->GetPortNum(),cp.dwMaxBaud,cp.dwSettableBaud);
        CloseHandle(hPort);
      }
    }
    
    ++nIndex;
  }

  // Free up the "device information set" now that we are finished with it
  lpfnSETUPDIDESTROYDEVICEINFOLIST(hDevInfoSet);


  // Return the success indicator
  return TRUE;
}
コード例 #7
0
int main(void)
{
    struct TrackedResources *crs = NULL;
    struct TrackedResources *start_rs = NULL;
    BOOL quitme = FALSE;
    int numlines = 30;
    struct Task *this;
    ULONG  portsig;
    struct MsgPort *port;

    this = FindTask(NULL);

    port = CreateMsgPort();
    if (!port)
	return 2;
    port->mp_Node.ln_Name = "LeakWatch";
    port->mp_Node.ln_Pri  = 0;
    AddPort(port);

    portsig = 1L << port->mp_SigBit;

    open_libs();

    FPuts(Output(), "LeakWatch running, CTRL-C to exit, CTRL-E to watch for leaks since beginning, CTRL-F to watch for leaks since last CTRL-F, CTRL-D for an usage snapshot\n");

    crs = NewResourcesState();
    if (NULL == crs)
	quitme = TRUE;
    else
	start_rs = CopyResourcesState(crs);

    while(!quitme)
    {
	ULONG signals;

	signals = Wait(portsig | SIGBREAKF_CTRL_F | SIGBREAKF_CTRL_E | SIGBREAKF_CTRL_D | SIGBREAKF_CTRL_C);

	if (signals & SIGBREAKF_CTRL_D)
	{
	    struct TrackedResources *tr;

	    tr = NewResourcesState();
	    if (NULL == tr)
	    {
		quitme = TRUE;
		break;
	    }
	    DisplayResourcesState(tr, numlines);
	    DeleteResourcesState(tr);
	}
	if (signals & SIGBREAKF_CTRL_E)
	{
	    struct ResourceDiff *rd = NULL;

	    DeleteResourcesState(crs);
	    crs = NewResourcesState();
	    if (NULL == crs)
	    {
		quitme = TRUE;
		break;
	    }
	    /*  DisplayResourcesState(crs); */ /* only for debug */
	    rd = NewStateDiff(start_rs, crs);
	    DisplayStateDiff(rd, numlines);
	    DeleteStateDiff(rd);
	}
	if (signals & SIGBREAKF_CTRL_F)
	{
	    struct TrackedResources *ors = crs;
	    struct ResourceDiff *rd = NULL;

	    crs = NewResourcesState();
	    if (NULL == crs)
	    {
		quitme = TRUE;
		break;
	    }
	    rd = NewStateDiff(ors, crs);
	    DisplayStateDiff(rd, numlines);
	    DeleteStateDiff(rd);
	    DeleteResourcesState(ors);
	}
	if (signals & SIGBREAKF_CTRL_C)
	{
	    quitme = TRUE;
	}
	if (signals & portsig)
	{
	    struct Message *msg;

	    while((msg = (struct Message *)GetMsg(port)))
	    {
		D(bug("Received watch message.\n"));

		ReplyMsg(msg);
	    }

	}
    } /* while(!quitme) */

    DeleteResourcesState(crs);
    DeleteResourcesState(start_rs);

    close_libs();

    if (port)
    {
	RemPort(port);
    	DeleteMsgPort(port);
    }
    return 0;
}
コード例 #8
0
ファイル: NiKomCon.c プロジェクト: punktniklas/NiKom
void main(int argc, char **argv) {
  int going = TRUE, forsok = 2,car = 1, tmp, ch;
  long tid;
  char tellstr[100],*tmppscreen, titel[80];

  NewList((struct List *)&aliaslist);
  NewList((struct List *)&edit_list);
  if(!(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0)))
    cleanup(EXIT_ERROR,"Kunde inte öppna intuition.library\n");
  if(!(UtilityBase=OpenLibrary("utility.library",37L)))
    cleanup(EXIT_ERROR,"Kunde inte öppna utility.library\n");
  if(!(LocaleBase=OpenLibrary("locale.library",38L)))
    cleanup(EXIT_ERROR,"Kunde inte öppna locale.library\n");
  if(!(NiKomBase=OpenLibrary("nikom.library",0L)))
    cleanup(EXIT_ERROR,"Kunde inte öppna nikom.linbrary");
  getnodeconfig("NiKom:Datocfg/ConNode.cfg");
  if(!(initnode(NODCON))) cleanup(EXIT_ERROR,"Kunde inte registrera noden i Servern\n");
  if(!(nikomnodeport = CreateMsgPort()))
    cleanup(EXIT_ERROR,"Kunde inte skapa NiKomNode-porten");
  sprintf(nikomnodeportnamn,"NiKomNode%d",nodnr);
  nikomnodeport->mp_Node.ln_Name = nikomnodeportnamn;
  nikomnodeport->mp_Node.ln_Pri = 1;
  AddPort(nikomnodeport);
  sprintf(rexxportnamn,"NiKomRexx%d",nodnr);
  if(!(rexxport=(struct MsgPort *)CreateMsgPort()))
    cleanup(EXIT_ERROR,"Kunde inte öppna RexxPort\n");
  rexxport->mp_Node.ln_Name=rexxportnamn;
  rexxport->mp_Node.ln_Pri=50;
  AddPort(rexxport);
  if(!(RexxSysBase=(struct RsxLib *)OpenLibrary("rexxsyslib.library",0L)))
    cleanup(EXIT_ERROR,"Kunde inte öppna rexxsyslib.library\n");
  if(pubscreen[0]=='-') tmppscreen=NULL;
  else tmppscreen=pubscreen;
  if(!(NiKwind=(struct Window *)OpenWindowTags(NULL,WA_Left,xpos,
                                               WA_Top,ypos,
                                               WA_Width,xsize,
                                               WA_Height,ysize,
                                               WA_IDCMP,IDCMP_CLOSEWINDOW,
                                               WA_MinWidth,50,
                                               WA_MinHeight,10,
                                               WA_MaxWidth,~0,
                                               WA_MaxHeight,~0,
                                               WA_SizeGadget,TRUE,
                                               WA_SizeBBottom, TRUE,
                                               WA_DragBar,TRUE,
                                               WA_DepthGadget,TRUE,
                                               WA_CloseGadget,TRUE,
                                               WA_SimpleRefresh,TRUE,
                                               WA_ScreenTitle,"NiKomCon",
                                               WA_AutoAdjust,TRUE,
                                               WA_PubScreenName,tmppscreen,
                                               TAG_DONE)))
    cleanup(EXIT_ERROR,"Kunde inte öppna fönstret\n");
  if(!OpenIO(NiKwind)) cleanup(EXIT_ERROR,"Kunde inte öppna IO\n");
  strcpy(Servermem->nodid[nodnr],nodid);
  sprintf(titel,"Nod #%d CON: <Ingen inloggad>",nodnr);
  SetWindowTitles(NiKwind,titel,(UBYTE *)-1L);
  Servermem->connectbps[nodnr] = -1;
  conreqtkn();
  do {
    Servermem->idletime[nodnr] = time(NULL);
    memset(commandhistory,0,1024);
    Servermem->inne[nodnr].rader=0;
    sendfile("NiKom:Texter/Inlogg.txt");
    if(Servermem->cfg.ar.preinlogg) sendautorexx(Servermem->cfg.ar.preinlogg);
    going=TRUE;
    while(going) {
      Servermem->idletime[nodnr] = time(NULL);
      puttekn("\r\nNamn: ",-1);
      getstring(EKO,40,NULL);
      if(!stricmp(inmat,Servermem->cfg.ny)) {
        tmp = RegisterNewUser();
        if(tmp == 2) {
          goto panik;
        }
        car = tmp ? 0 : 1;
        going=FALSE;
      }
      else if((inloggad=parsenamn(inmat))>=0) {
        if(readuser(inloggad,&Servermem->inne[nodnr])) {
          puttekn("Error reading user data.\r\n", -1);
          goto panik;
        }
        // TODO: Extract password loop. Should be identical to in PreNode/Ser.c
        forsok=2;
        while(forsok) {
          puttekn("\r\nLösen: ",-1);
          if(Servermem->inne[nodnr].flaggor & STAREKOFLAG)
            getstring(STAREKO,15,NULL);
          else
            getstring(EJEKO,15,NULL);
          if(CheckPassword(inmat, Servermem->inne[nodnr].losen)) {
            forsok=FALSE;
            going=FALSE;
          } else {
            forsok--;
          }
        }
      } else if(inloggad==-1) puttekn("\r\nHittar ej namnet\r\n",-1);
    }
    sprintf(titel,"Nod #%d CON: %s #%d",nodnr,Servermem->inne[nodnr].namn,inloggad);
    SetWindowTitles(NiKwind,titel,(UBYTE *)-1L);
    if(!ReadUnreadTexts(&Servermem->unreadTexts[nodnr], inloggad)) {
      puttekn("Error reading unread text info.\r\n", -1);
      LogEvent(SYSTEM_LOG, ERROR,
               "Can't read unread text info for user %d", inloggad);
      goto panik;
    }
    Servermem->inloggad[nodnr]=inloggad;
    Servermem->idletime[nodnr] = time(NULL);
    if(getft("NiKom:Texter/Bulletin.txt")>Servermem->inne[nodnr].senast_in) sendfile("NiKom:Texter/Bulletin.txt");

    connection();

    if(Servermem->cfg.logmask & LOG_UTLOGG) {
      LogEvent(USAGE_LOG, INFO, "%s loggar ut från nod %d",
               getusername(inloggad), nodnr);
    }
    if(Servermem->say[nodnr]) displaysay();
    if(Servermem->cfg.ar.utlogg) sendautorexx(Servermem->cfg.ar.utlogg);
    sendfile("NiKom:Texter/Utlogg.txt");
    sprintf(titel,"Nod #%d CON: <Ingen inloggad>",nodnr);
    SetWindowTitles(NiKwind,titel,(UBYTE *)-1L);
    Servermem->inloggad[nodnr]=-1;
    
    Servermem->action[nodnr]=0;
    time(&tid);
    Servermem->inne[nodnr].senast_in=tid;
    Servermem->inne[nodnr].tot_tid+=(tid-logintime);
    Servermem->inne[nodnr].loggin++;
    Servermem->info.inloggningar++;
    Servermem->inne[nodnr].defarea=area2;
    writeuser(inloggad,&Servermem->inne[nodnr]);
    WriteUnreadTexts(&Servermem->unreadTexts[nodnr], inloggad);
    writesenaste();
    freealiasmem();
    sprintf(tellstr,"loggade just ut från nod %d",nodnr);
    tellallnodes(tellstr);
  panik:
    nodestate = 0;
    puttekn("\r\n\nEn inloggning till? (J/n)",-1);
  } while((ch = GetChar()) != 'n' && ch != 'N');
  cleanup(EXIT_OK,"");
}
コード例 #9
0
ファイル: NiKomSer.c プロジェクト: punktniklas/NiKom
void main(int argc,char *argv[]) {
  int x;
  long tid;
  char tellstr[100],*tmppscreen, titel[80], configname[50] = "NiKom:DatoCfg/SerNode.cfg";
  if(argc>1) for(x=1;x<argc;x++) {
      if(argv[x][0]=='-') {
        if(argv[x][1]=='B') dtespeed=atoi(&argv[x][2]);
        else if(argv[x][1]=='N') nodnr = atoi(&argv[x][2]);
      } else strcpy(configname,argv[x]);
    }
  if(nodnr==-1) {
    printf("NiKomSer måste startas från prenoden.\n");
    exit(10);
  }
  NewList((struct List *)&aliaslist);
  NewList((struct List *)&edit_list);
  if(!(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0)))
    cleanup(EXIT_ERROR,"Kunde inte öppna intuition.library\n");
  if(!(UtilityBase=OpenLibrary("utility.library",37L)))
    cleanup(EXIT_ERROR,"Kunde inte öppna utility.library\n");
  if(!(LocaleBase=OpenLibrary("locale.library",38L)))
    cleanup(EXIT_ERROR,"Kunde inte öppna locale.library\n");
  if(!(NiKomBase=OpenLibrary("nikom.library",0L)))
    cleanup(EXIT_ERROR,"Kunde inte öppna nikom.library\n");

  initnode(NODSPAWNED);
  if(!(nikomnodeport = CreateMsgPort()))
    cleanup(EXIT_ERROR,"Kunde inte skapa NiKomNode-porten");
  sprintf(nikomnodeportnamn,"NiKomNode%d",nodnr);
  nikomnodeport->mp_Node.ln_Name = nikomnodeportnamn;
  nikomnodeport->mp_Node.ln_Pri = 1;
  AddPort(nikomnodeport);
  sprintf(rexxportnamn,"NiKomRexx%d",nodnr);
  if(!(rexxport=(struct MsgPort *)CreateMsgPort()))
    cleanup(EXIT_ERROR,"Kunde inte öppna RexxPort\n");
  rexxport->mp_Node.ln_Name=rexxportnamn;
  rexxport->mp_Node.ln_Pri = 50;
  AddPort(rexxport);
  if(!(RexxSysBase=(struct RsxLib *)OpenLibrary("rexxsyslib.library",0L)))
    cleanup(EXIT_ERROR,"Kunde inte öppna rexxsyslib.library\n");
  getnodeconfig(configname);
  if(pubscreen[0]=='-') tmppscreen=NULL;
  else tmppscreen=pubscreen;
  if(!(NiKwind=(struct Window *)OpenWindowTags(NULL,WA_Left,xpos,
                                               WA_Top,ypos,
                                               WA_Width,xsize,
                                               WA_Height,ysize,
                                               WA_IDCMP,IDCMP_CLOSEWINDOW,
                                               WA_MinWidth,50,
                                               WA_MinHeight,10,
                                               WA_MaxWidth,~0,
                                               WA_MaxHeight,~0,
                                               WA_SizeGadget,TRUE,
                                               WA_SizeBBottom, TRUE,
                                               WA_DragBar,TRUE,
                                               WA_DepthGadget,TRUE,
                                               WA_CloseGadget,TRUE,
                                               WA_SimpleRefresh,TRUE,
                                               WA_ScreenTitle,"NiKomSer",
                                               WA_AutoAdjust,TRUE,
                                               WA_PubScreenName,tmppscreen,
                                               TAG_DONE)))
    cleanup(EXIT_ERROR,"Kunde inte öppna fönstret\n");
  if(!OpenIO(NiKwind)) cleanup(EXIT_ERROR,"Kunde inte öppna IO\n");
  inloggad=Servermem->inloggad[nodnr];
  conreqtkn();
  serreqtkn();
  UpdateInactive();
  sprintf(titel,"Nod #%d SER: %s #%d",nodnr,Servermem->inne[nodnr].namn,inloggad);
  SetWindowTitles(NiKwind,titel,(char *)-1L);
  if(!ReadUnreadTexts(&Servermem->unreadTexts[nodnr], inloggad)) {
    puttekn("Error reading unread text info.\r\n", -1);
    LogEvent(SYSTEM_LOG, ERROR,
             "Can't read unread text info for user %d", inloggad);
    cleanup(EXIT_ERROR, "Error reading unread text info.\n");
  }
  if(getft("NiKom:Texter/Bulletin.txt")>Servermem->inne[nodnr].senast_in) {
    sendfile("NiKom:Texter/Bulletin.txt");
  }

  connection();

  if(nodestate & NIKSTATE_NOCARRIER) {
    conputtekn("\nCarrier dropped\n",-1);
    if(Servermem->cfg.logmask & LOG_CARDROPPED) {
      LogEvent(USAGE_LOG, WARN, "%s släpper carriern (nod %d)",
               getusername(inloggad), nodnr);
    }
    if(Servermem->cfg.ar.cardropped) sendautorexx(Servermem->cfg.ar.cardropped);
  } else {
    if(nodestate & NIKSTATE_AUTOLOGOUT) {
      puttekn("\n\n\r*** Automagisk utloggning ***\n\n\r",-1);
    } else if(nodestate & NIKSTATE_INACTIVITY) {
      puttekn("\n\n\r*** Utloggning p.g.a inaktivitet ***\n\n\r",-1);
    }
    radcnt=-174711;
    if(Servermem->say[nodnr]) displaysay();
    if(Servermem->cfg.ar.utlogg) sendautorexx(Servermem->cfg.ar.utlogg);
    sendfile("NiKom:Texter/Utlogg.txt");
  }
  Servermem->inloggad[nodnr]=-1;
  if(Servermem->cfg.logmask & LOG_UTLOGG) {
    LogEvent(USAGE_LOG, INFO, "%s loggar ut från nod %d",
             getusername(inloggad), nodnr);
  }
  Servermem->action[nodnr]=0;
  time(&tid);
  Servermem->inne[nodnr].senast_in=tid;
  Servermem->inne[nodnr].tot_tid+=(tid-logintime);
  Servermem->inne[nodnr].loggin++;
  Servermem->info.inloggningar++;
  Servermem->inne[nodnr].defarea=area2;
  writeuser(inloggad,&Servermem->inne[nodnr]);
  WriteUnreadTexts(&Servermem->unreadTexts[nodnr], inloggad);
  writesenaste();
  AbortInactive();
  freealiasmem();
  sprintf(tellstr,"loggade just ut från nod %d",nodnr);
  tellallnodes(tellstr);

  if(nodestate & NIKSTATE_NOCARRIER) {
    nodestate &= ~NIKSTATE_RELOGIN;
  }
  nodestate &= (NIKSTATE_RELOGIN | NIKSTATE_CLOSESER | NIKSTATE_NOANSWER);
  cleanup(nodestate,"");
}
コード例 #10
0
ファイル: amSupport.c プロジェクト: bovine/dnetc-client-base
int amigaInit(int *argc, char **argv[])
{
   int done = TRUE;

   #if !defined(__POWERUP__) && !defined(__amigaos4__) && !defined(__MORPHOS__)
   if (!MemInit()) return FALSE;
   #endif

   #ifdef __OS3PPC__
   /*
   ** PPC
   */

   /* Set the priority of the PPC 68k mirror main task */
   #ifdef CHANGE_MIRROR_TASK_PRI
   Old68kMirrorPri = SetTaskPri(FindTask(NULL), 2);
   #endif

   #ifdef __POWERUP__
   /*
   ** PowerUp
   */
   /* Requires ppc.library 46.30 (or PPCLibEmu), due to timer/signal bugs */
   #define PPCINFOTAG_EMULATION (TAG_USER + 0x1f0ff)
   if (PPCGetAttr(PPCINFOTAG_EMULATION) == 'WARP') {
      if (!((PPCVersion() == 46 && PPCRevision() >= 29) || PPCVersion() > 46)) {
         printf("Requires PPCLibEmu 0.8a or higher!\n");
         done = FALSE;
      }
   }
   else {
      if (!((PPCVersion() == 46 && PPCRevision() >= 30) || PPCVersion() > 46)) {
         printf("Requires ppc.library 46.30 or higher!\n");
         done = FALSE;
      }
   }
   if (done) {
      if (PPCGetTaskAttr(PPCTASKTAG_STACKSIZE) < 200000) {
         printf("Please increase stack size to at least 200000 bytes!\n");
         done = FALSE;
      }
   }
   if (done) {
      done = ((PPCLibBase = OpenLibrary("ppc.library",46)) != NULL);
   }
   if (done) {
      struct TagItem tags[2] = { {PPCPORTTAG_NAME, (ULONG)"dnetc"}, {TAG_END,0} };
      void *port;
      if (!(port = PPCObtainPort(tags))) {
         done = FALSE;
         if ((TriggerPort = PPCCreatePort(tags))) {
            done = TRUE;
         }
      }
      else {
         PPCReleasePort(port);
      }
   }
   #else
   /*
   ** WarpOs
   */
   if (!FindPortPPC("dnetc")) {
      if ((TriggerPort = CreateMsgPortPPC())) {
         TriggerPort->mp_Port.mp_Node.ln_Name = "dnetc";
         TriggerPort->mp_Port.mp_Node.ln_Pri = 0;
         AddPortPPC(TriggerPort);
      }
      else {
         done = FALSE;
      }
   }
   #endif

   #else
   /*
   ** 68K / OS4 / MorphOS
   */

   struct MsgPort *portexists;

   Forbid();

   portexists = FindPort("dnetc");
   if (!portexists) {
      if ((TriggerPort = CreateMsgPort())) {
         TriggerPort->mp_Node.ln_Name = "dnetc";
         TriggerPort->mp_Node.ln_Pri = 0;
         AddPort(TriggerPort);
      }
      else {
         done = FALSE;
      }
   }

   Permit();
   #endif

   if (!TimerBase && done) done = GlobalTimerInit();

   if (!done) amigaExit();

   #ifndef NO_GUI
   /* Workbench startup */
   if (done && *argc == 0) {
      struct WBStartup *wbs = (struct WBStartup *)*argv;
      struct WBArg *arg = wbs->sm_ArgList;
      static char *newargv[1];
      newargv[0] = (char *)arg->wa_Name;

      *argc = 1;
      *argv = newargv;

      if (wbs->sm_NumArgs > 1) {
         /* Started via a project icon */
         arg = &wbs->sm_ArgList[1];
      }

      if (!(amigaGUIInit((char *)wbs->sm_ArgList->wa_Name,arg))) {
         if (!(amigaOpenNewConsole("CON://630/300/distributed.net client/CLOSE/WAIT"))) {
            done = FALSE;
         }
      }
   }
   #endif

   #if USE_RESETHANDLER
   if (done) {
      add_resethandler();
   }
   #endif

   return(done);
}
コード例 #11
0
ファイル: enumser.cpp プロジェクト: ied/olswinloader
BOOL CEnumerateSerial::EnumeratePorts()
{
  int SPDRPlist[] = {
    SPDRP_HARDWAREID, SPDRP_DEVICEDESC, SPDRP_FRIENDLYNAME, SPDRP_MFG,
    SPDRP_LOCATION_INFORMATION, SPDRP_PHYSICAL_DEVICE_OBJECT_NAME, 
    -1};

  // Clear anything from previous enumerate...
  ResetPortList();

  // First need to convert the name "Ports" to a GUID using SetupDiClassGuidsFromName...
  DWORD dwGuids = 0;
  SetupDiClassGuidsFromName(_T("Ports"), NULL, 0, &dwGuids);
  if (dwGuids == 0) return FALSE;

  // Allocate the needed memory...
  CHeapPtr<GUID> GuidArray;
  GUID *pGuids = (GUID*)GuidArray.Allocate(sizeof(GUID) * dwGuids);
  if (pGuids==NULL) {
    SetLastError(ERROR_OUTOFMEMORY);
    return FALSE;
  }

  // Call the function again...
  if (!SetupDiClassGuidsFromName(_T("Ports"), pGuids, dwGuids, &dwGuids))
    return FALSE;

  // Now create a "device information set" which is required to enumerate all the ports...
  HDEVINFO hDevInfoSet = SetupDiGetClassDevs(pGuids, NULL, NULL, DIGCF_PRESENT);
  if (hDevInfoSet == INVALID_HANDLE_VALUE)
    return FALSE;

  // Finally do the enumeration...
  int nIndex = 0;
  SP_DEVINFO_DATA devInfo;
  CHeapPtr<TCHAR> tempstr(1000);
  CSerialPortInfo *portinfo = NULL;

  // Enumerate the current device...
  devInfo.cbSize = sizeof(SP_DEVINFO_DATA);
  while (SetupDiEnumDeviceInfo(hDevInfoSet, nIndex, &devInfo))
  {
    portinfo = NULL;

    // Get the registry key which stores the ports settings...
    HKEY hDeviceKey = SetupDiOpenDevRegKey(hDevInfoSet, &devInfo, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_QUERY_VALUE);
    if (hDeviceKey) {
      tempstr.FillZero();
      DWORD dwSize = tempstr.SizeOf(); 
      DWORD dwType = 0;

      // Read name of port.  If formatted as "COMxx" then allocate a port slot...
  	  if ((RegQueryValueEx(hDeviceKey, _T("PortName"), NULL, &dwType, reinterpret_cast<LPBYTE>((TCHAR*)tempstr), &dwSize) == ERROR_SUCCESS) && (dwType == REG_SZ))
        if (_tcslen(tempstr) > 3)
          if ((_tcsnicmp(tempstr, _T("COM"), 3) == 0) && IsNumber(&(tempstr[3])))
            portinfo = AddPort(_ttoi(&(tempstr[3])));

      // Close the key now that we are finished with it...
      RegCloseKey(hDeviceKey);
    }

    // If a serial port, then try getting additional useful descriptive info...
    if (portinfo) {
      for (int i=0; SPDRPlist[i]>=0; i++) {
        tempstr.FillZero(); 
        DWORD dwSize = tempstr.SizeOf(); 
        DWORD dwType = 0;
        if (SetupDiGetDeviceRegistryProperty(hDevInfoSet, &devInfo, SPDRPlist[i], &dwType, reinterpret_cast<PBYTE>((TCHAR*)tempstr), dwSize, &dwSize) && ((dwType == REG_SZ) || (dwType == REG_MULTI_SZ)))
          switch (SPDRPlist[i]) {
            case SPDRP_MFG : portinfo->SetManufacturer(tempstr); break;
            case SPDRP_HARDWAREID : portinfo->SetHardwareID(tempstr); break;
            case SPDRP_DEVICEDESC : portinfo->SetDeviceDesc(tempstr); break;
            case SPDRP_FRIENDLYNAME : portinfo->SetFriendlyName(tempstr); break;
            case SPDRP_LOCATION_INFORMATION : portinfo->SetLocationInfo(tempstr); break;
            case SPDRP_PHYSICAL_DEVICE_OBJECT_NAME : portinfo->SetPhysLocation(tempstr); break;
          }
      }

      // Get COM port properties...
      HANDLE hPort = ::CreateFile(portinfo->GetPortDeviceName(), GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
      if (hPort != INVALID_HANDLE_VALUE) {
        COMMPROP cp;
        GetCommProperties(hPort, &cp);
        portinfo->SetCommProp(cp);
        TRACE ("Port %d:  CommProp: maxbaud=%08x  settablebaud=%08x\n",portinfo->GetPortNum(),cp.dwMaxBaud,cp.dwSettableBaud);
        CloseHandle(hPort);
      }
    }
    
    ++nIndex;
  }

  // Free up the "device information set" now that we are finished with it
  SetupDiDestroyDeviceInfoList(hDevInfoSet);

  // Return the success indicator
  return TRUE;
}
コード例 #12
0
// Save filetypes
short filetype_save(config_filetypes_data *data)
{
	Cfg_FiletypeList *list;
	Cfg_Filetype *type;
	short ret=1;
	struct MsgPort *port;
	
	// Open a port to stop dopus re-reading
	if ((port=CreateMsgPort()))
	{
		port->mp_Node.ln_Name="FILETYPE LOCK";
		AddPort(port);
	}

	// Go through filetype lists
	for (list=(Cfg_FiletypeList *)data->list_list.lh_Head;
		list->node.ln_Succ;
		list=(Cfg_FiletypeList *)list->node.ln_Succ)
	{
		// Has this list been modified?
		if (list->flags&FTLISTF_CHANGED)
		{
			// Clear flag
			list->flags&=~FTLISTF_CHANGED;

			// Is the list empty?
			if (IsListEmpty(&list->filetype_list))
			{
				// Valid list path?
				if (list->path[0])
				{
					// Try to delete list
					if (!DeleteFile(list->path))
						ret=0;
				}
			}

			// Otherwise
			else
			{
				short err;

				// Valid list path?
				if (!list->path[0])
				{
					char *ptr;

					// Build path from name of first filetype
					type=(Cfg_Filetype *)list->filetype_list.lh_Head;

					// Storage or normal?
					if (list->flags&FTLISTF_STORE)
						strcpy(list->path,"dopus5:Filetypes/Storage/");
					else
						strcpy(list->path,"dopus5:Filetypes/");

					// Check name for / characters
					for (ptr=type->type.name;*ptr;ptr++)
						if (*ptr=='/') *ptr='\\';

					// Add name
					strcat(list->path,type->type.name);
				}

				// Store?
				else
				if (list->flags&FTLISTF_STORE)
				{
					char buf[256];

					// Build storage filename
					lsprintf(buf,"dopus5:Storage/Filetypes/%s",FilePart(list->path));

					// Delete existing stored filetype
					DeleteFile(buf);

					// Move file to storage
					if (Rename(list->path,buf))
					{
						// Get names for icon
						strcat(list->path,".info");
						strcat(buf,".info");

						// Delete existing stored filetype
						DeleteFile(buf);

						// Move icon
						Rename(list->path,buf);

						// Clear .info suffix
						buf[strlen(buf)-5]=0;

						// Use path to save
						strcpy(list->path,buf);
					}

					// Clear flag
					list->flags&=~FTLISTF_STORE;
				}

				// Success by default
				ret=1;

				// Save filetype list
				while ((err=SaveFiletypeList(list,list->path))>0)
				{
					// Show error
					if (!(ret=error_saving(err,data->window)))
						break;
				}

				// Failed?
				if (!ret)
				{
		 			// Set change flag again
					list->flags|=FTLISTF_CHANGED;
					break;
				}
			}
		}
	}

	// Remove lock port
	if (port)
	{
		RemPort(port);
		DeleteMsgPort(port);
	}

	return ret;
}
コード例 #13
0
ファイル: NiKomCon.c プロジェクト: dblarsson/NiKom
void main(int argc, char **argv) {
	int going=TRUE,forsok=2,car=1;
	long tid;
	char tellstr[100],*tmppscreen, titel[80];
	UBYTE tillftkn;
	NewList((struct List *)&aliaslist);
	NewList((struct List *)&edit_list);
	if(!(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0)))
		cleanup(ERROR,"Kunde inte öppna intuition.library\n");
	if(!(UtilityBase=OpenLibrary("utility.library",37L)))
		cleanup(ERROR,"Kunde inte öppna utility.library\n");
	if(!(NiKomBase=OpenLibrary("nikom.library",0L)))
		cleanup(ERROR,"Kunde inte öppna nikom.linbrary");
	getnodeconfig("NiKom:Datocfg/ConNode.cfg");
	if(!(initnode(NODCON))) cleanup(ERROR,"Kunde inte registrera noden i Servern\n");
	if(!(nikomnodeport = CreateMsgPort()))
		cleanup(ERROR,"Kunde inte skapa NiKomNode-porten");
	sprintf(nikomnodeportnamn,"NiKomNode%d",nodnr);
	nikomnodeport->mp_Node.ln_Name = nikomnodeportnamn;
	nikomnodeport->mp_Node.ln_Pri = 1;
	AddPort(nikomnodeport);
	sprintf(rexxportnamn,"NiKomRexx%d",nodnr);
	if(!(rexxport=(struct MsgPort *)CreateMsgPort()))
		cleanup(ERROR,"Kunde inte öppna RexxPort\n");
	rexxport->mp_Node.ln_Name=rexxportnamn;
	rexxport->mp_Node.ln_Pri=50;
	AddPort(rexxport);
	if(!(RexxSysBase=(struct RsxLib *)OpenLibrary("rexxsyslib.library",0L)))
		cleanup(ERROR,"Kunde inte öppna rexxsyslib.library\n");
	if(pubscreen[0]=='-') tmppscreen=NULL;
	else tmppscreen=pubscreen;
	if(!(NiKwind=(struct Window *)OpenWindowTags(NULL,WA_Left,xpos,
																	  WA_Top,ypos,
																	  WA_Width,xsize,
																	  WA_Height,ysize,
																	  WA_IDCMP,IDCMP_CLOSEWINDOW,
																	  WA_MinWidth,50,
																	  WA_MinHeight,10,
																	  WA_MaxWidth,~0,
																	  WA_MaxHeight,~0,
																	  WA_SizeGadget,TRUE,
																	  WA_SizeBBottom, TRUE,
																	  WA_DragBar,TRUE,
																	  WA_DepthGadget,TRUE,
																	  WA_CloseGadget,TRUE,
																	  WA_SimpleRefresh,TRUE,
																	  WA_ScreenTitle,"NiKom © Tomas Kärki 1996-1998",
																	  WA_AutoAdjust,TRUE,
																	  WA_PubScreenName,tmppscreen,
																	  TAG_DONE)))
		cleanup(ERROR,"Kunde inte öppna fönstret\n");
	if(!OpenIO(NiKwind)) cleanup(ERROR,"Kunde inte öppna IO\n");
	if(!getkeyfile())
		cleanup(ERROR,"Korrupt nyckelfil\n");
	strcpy(Servermem->nodid[nodnr],nodid);
	sprintf(titel,"Nod #%d CON: <Ingen inloggad>",nodnr);
	SetWindowTitles(NiKwind,titel,(UBYTE *)-1L);
	Servermem->connectbps[nodnr] = -1;
	conreqtkn();
do
{
	memset(commandhistory,0,1024);
	Servermem->inne[nodnr].rader=0;
	sendfile("NiKom:Texter/Inlogg.txt");
	if(Servermem->cfg.ar.preinlogg) sendrexx(Servermem->cfg.ar.preinlogg);
	going=TRUE;
	while(going) {
		puttekn("\r\nNamn: ",-1);
		getstring(EKO,40,NULL);
		if(!stricmp(inmat,Servermem->cfg.ny))
		{
/*			if(!reggadnamn[0] && ((struct ShortUser *)Servermem->user_list.mlh_TailPred)->nummer >= 4)
				puttekn("\n\n\rDenna demoversion av NiKom kan hantera maximalt 5 användare.\n\r",-1);
			else { Versionen är nu obegränsad 970930! */
				if((car=nyanv())==2) goto panik;
				going=FALSE;
/*			} */
		}
		else if((inloggad=parsenamn(inmat))>=0) {
			readuser(inloggad,&Servermem->inne[nodnr]);
			forsok=2;
			while(forsok) {
				puttekn("\r\nLösen: ",-1);
				if(Servermem->inne[nodnr].flaggor & STAREKOFLAG)
					getstring(STAREKO,15,NULL);
				else
					getstring(EJEKO,15,NULL);
				if(CheckPassword(inloggad, inmat))
				{
					forsok=FALSE;
					going=FALSE;
				} else forsok--;
			}
		} else if(inloggad==-1) puttekn("\r\nHittar ej namnet\r\n",-1);
	}
	sprintf(titel,"Nod #%d CON: %s #%d",nodnr,Servermem->inne[nodnr].namn,inloggad);
	SetWindowTitles(NiKwind,titel,(UBYTE *)-1L);
	readuserbitmap(inloggad,Servermem->bitmaps[nodnr],0,temppek);
	Servermem->inloggad[nodnr]=inloggad;
	Servermem->idletime[nodnr] = time(NULL);
	if(getft("NiKom:Texter/Bulletin.txt")>Servermem->inne[nodnr].senast_in) sendfile("NiKom:Texter/Bulletin.txt");
	connection();
	if(Servermem->cfg.logmask & LOG_UTLOGG) {
		sprintf(outbuffer,"%s loggar ut från nod %d",getusername(inloggad),nodnr);
		logevent(outbuffer);
	}
	if(Servermem->say[nodnr]) displaysay();
	if(Servermem->cfg.ar.utlogg) sendrexx(Servermem->cfg.ar.utlogg);
	sendfile("NiKom:Texter/Utlogg.txt");
	sprintf(titel,"Nod #%d CON: <Ingen inloggad>",nodnr);
	SetWindowTitles(NiKwind,titel,(UBYTE *)-1L);
	SaveProgramCategory(inloggad);
	Servermem->inloggad[nodnr]=-1;

	Servermem->action[nodnr]=0;
	Servermem->inne[nodnr].textpek=textpek;
	time(&tid);
	Servermem->inne[nodnr].senast_in=tid;
	Servermem->inne[nodnr].tot_tid+=(tid-logintime);
	Servermem->inne[nodnr].loggin++;
	Servermem->info.inloggningar++;
	Servermem->inne[nodnr].defarea=area2;
	writeuser(inloggad,&Servermem->inne[nodnr]);
	writeuserbitmap(inloggad,Servermem->bitmaps[nodnr],0,temppek);
	writesenaste();
	freealiasmem();
	sprintf(tellstr,"loggade just ut från nod %d",nodnr);
	tellallnodes(tellstr);
panik:
	puttekn("\r\n\nEn inloggning till? (J/n)",-1);
	} while((tillftkn=gettekn())!='n' && tillftkn!='N');
	cleanup(OK,"");
}
コード例 #14
0
int main(int argc, char* argv[])
{
    struct MsgPort *port1;
    struct Task *t;

    port1=CreateMsgPort();
    if(port1!=NULL)
    {
	port1->mp_Node.ln_Name="message test port";

	Forbid();
	if(FindPort(port1->mp_Node.ln_Name)==NULL)
	{
	    AddPort(port1);
	    Permit();

	    t=(struct Task *)AllocMem(sizeof(struct Task), MEMF_PUBLIC|MEMF_CLEAR);
	    if(t!=NULL)
	    {
		UBYTE *s;
		s=(UBYTE *)AllocMem(STACKSIZE, MEMF_PUBLIC|MEMF_CLEAR);
		if(s!=NULL)
		{
		    t->tc_Node.ln_Type=NT_TASK;
		    t->tc_Node.ln_Pri=1;
		    t->tc_Node.ln_Name="new task";
		    t->tc_SPLower=s;
		    t->tc_SPUpper=s+STACKSIZE;
#if AROS_STACK_GROWS_DOWNWARDS
		    t->tc_SPReg=(UBYTE *)t->tc_SPUpper-SP_OFFSET;
#else
		    t->tc_SPReg=(UBYTE *)t->tc_SPLower-SP_OFFSET;
#endif
		    NEWLIST(&t->tc_MemEntry);
		    AddTask(t,&entry,NULL);

		    Wait(1<<port1->mp_SigBit);
		    if(port1->mp_MsgList.lh_Head->ln_Succ!=NULL)
		    {
			int i;
			for(i=0;i<10;i++)
			{
			    struct Message *msg;

			    WaitPort(port1);
			    msg=GetMsg(port1);
			    printf("%d\n",(int)msg->mn_Node.ln_Name);
			    ReplyMsg(msg);
			}

			Wait(1<<port1->mp_SigBit);
			RemTask(t);
		    }
		    FreeMem(s,STACKSIZE);
		}
		FreeMem(t,sizeof(struct Task));
	    }
	    RemPort(port1);
	}else
	    Permit();
	DeleteMsgPort(port1);
    }
    return 0;
}