BOOL DLLCALL findstr_in_string(const char* insearchof, char* string) { char* p; char str[256]; char search[81]; int c; int i; BOOL found=FALSE; if(string==NULL || insearchof==NULL) return(FALSE); SAFECOPY(search,insearchof); strupr(search); SAFECOPY(str,string); p=str; SKIP_WHITESPACE(p); if(*p==';') /* comment */ return(FALSE); if(*p=='!') { /* !match */ found=TRUE; p++; } truncsp(p); c=strlen(p); if(c) { c--; strupr(p); if(p[c]=='~') { p[c]=0; if(strstr(search,p)) found=!found; } else if(p[c]=='^' || p[c]=='*') { p[c]=0; if(!strncmp(p,search,c)) found=!found; } else if(p[0]=='*') { i=strlen(search); if(i<c) return(found); if(!strncmp(p+1,search+(i-c),c)) found=!found; } else if(!strcmp(p,search)) found=!found; } return(found); }
BOOL md(char *inpath) { DIR* dir; char path[MAX_PATH+1]; if(inpath[0]==0) return(FALSE); SAFECOPY(path,inpath); /* Remove trailing '.' if present */ if(path[strlen(path)-1]=='.') path[strlen(path)-1]=0; /* Remove trailing slash if present */ if(path[strlen(path)-1]=='\\' || path[strlen(path)-1]=='/') path[strlen(path)-1]=0; dir=opendir(path); if(dir==NULL) { /* lprintf("Creating directory: %s",path); */ if(MKDIR(path)) { lprintf(LOG_WARNING,"!ERROR %d creating directory: %s",errno,path); return(FALSE); } } else closedir(dir); return(TRUE); }
void DLLCALL js_PrepareToExecute(JSContext *cx, JSObject *obj, const char *filename, const char* startup_dir) { JSString* str; jsval val; if(JS_GetProperty(cx, obj, "js", &val) && JSVAL_IS_OBJECT(val)) { JSObject* js = JSVAL_TO_OBJECT(val); char dir[MAX_PATH+1]; if(filename!=NULL) { char* p; if((str=JS_NewStringCopyZ(cx, filename)) != NULL) JS_DefineProperty(cx, js, "exec_path", STRING_TO_JSVAL(str) ,NULL,NULL,JSPROP_ENUMERATE|JSPROP_READONLY); if((str=JS_NewStringCopyZ(cx, getfname(filename))) != NULL) JS_DefineProperty(cx, js, "exec_file", STRING_TO_JSVAL(str) ,NULL,NULL,JSPROP_ENUMERATE|JSPROP_READONLY); SAFECOPY(dir,filename); p=getfname(dir); *p=0; if((str=JS_NewStringCopyZ(cx, dir)) != NULL) JS_DefineProperty(cx, js, "exec_dir", STRING_TO_JSVAL(str) ,NULL,NULL,JSPROP_ENUMERATE|JSPROP_READONLY); } if(startup_dir==NULL) startup_dir=""; if((str=JS_NewStringCopyZ(cx, startup_dir)) != NULL) JS_DefineProperty(cx, js, "startup_dir", STRING_TO_JSVAL(str) ,NULL,NULL,JSPROP_ENUMERATE|JSPROP_READONLY); } #if defined(_MSC_VER) _set_invalid_parameter_handler(msvc_invalid_parameter_handler); #endif }
long DLLCALL getdirsize(const char* path, BOOL include_subdirs, BOOL subdir_only) { char match[MAX_PATH+1]; glob_t g; unsigned gi; long count=0; if(!isdir(path)) return -1; SAFECOPY(match,path); backslash(match); strcat(match,ALLFILES); glob(match,GLOB_MARK,NULL,&g); if(include_subdirs && !subdir_only) count=g.gl_pathc; else for(gi=0;gi<g.gl_pathc;gi++) { if(*lastchar(g.gl_pathv[gi])=='/') { if(!include_subdirs) continue; } else if(subdir_only) continue; count++; } globfree(&g); return(count); }
BOOL DLLCALL isdir(const char *filename) { char path[MAX_PATH+1]; char* p; struct stat st; SAFECOPY(path,filename); p=lastchar(path); if(p!=path && IS_PATH_DELIM(*p)) { /* chop off trailing slash */ #if !defined(__unix__) if(*(p-1)!=':') /* Don't change C:\ to C: */ #endif *p=0; } #if defined(__BORLANDC__) && !defined(__unix__) /* stat() doesn't work right */ if(stat(path, &st)!=0 || strchr(path,'*')!=NULL || strchr(path,'?')!=NULL) #else if(stat(path, &st)!=0) #endif return(FALSE); return(S_ISDIR(st.st_mode) ? TRUE : FALSE); }
//--------------------------------------------------------------------------- WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR cmd, int) { memset(SpyForms,0,sizeof(SpyForms)); try { Application->Initialize(); Application->Title = "Synchronet Control Panel"; Application->CreateForm(__classid(TMainForm), &MainForm); Application->CreateForm(__classid(TTelnetForm), &TelnetForm); Application->CreateForm(__classid(TFtpForm), &FtpForm); Application->CreateForm(__classid(TWebForm), &WebForm); Application->CreateForm(__classid(TMailForm), &MailForm); Application->CreateForm(__classid(TNodeForm), &NodeForm); Application->CreateForm(__classid(TStatsForm), &StatsForm); Application->CreateForm(__classid(TClientForm), &ClientForm); Application->CreateForm(__classid(TUserListForm), &UserListForm); Application->CreateForm(__classid(TEventsForm), &EventsForm); Application->CreateForm(__classid(TServicesForm), &ServicesForm); Application->CreateForm(__classid(TLoginAttemptsForm), &LoginAttemptsForm); if(cmd[0] && isdir(cmd)) SAFECOPY(MainForm->global.ctrl_dir,cmd); sbbs_get_ini_fname(MainForm->ini_file, MainForm->global.ctrl_dir, NULL /* auto-hostname */); Application->Run(); } catch (Exception &exception) { Application->ShowException(&exception); } return 0; }
BOOL DLLCALL removefiledat(scfg_t* cfg, file_t* f) { char c,str[MAX_PATH+1],ixbname[12],*ixbbuf,fname[13]; int i,file; long l,length; SAFECOPY(fname,f->name); for(i=8;i<12;i++) /* Turn FILENAME.EXT into FILENAMEEXT */ fname[i]=fname[i+1]; SAFEPRINTF2(str,"%s%s.ixb",cfg->dir[f->dir]->data_dir,cfg->dir[f->dir]->code); if((file=sopen(str,O_RDONLY|O_BINARY,SH_DENYWR))==-1) { return(FALSE); } length=(long)filelength(file); if(!length) { close(file); return(FALSE); } if((ixbbuf=(char *)malloc(length))==0) { close(file); return(FALSE); } if(lread(file,ixbbuf,length)!=length) { close(file); free((char *)ixbbuf); return(FALSE); } close(file); if((file=sopen(str,O_WRONLY|O_TRUNC|O_BINARY,SH_DENYRW))==-1) { return(FALSE); } for(l=0;l<length;l+=F_IXBSIZE) { for(i=0;i<11;i++) ixbname[i]=ixbbuf[l+i]; ixbname[i]=0; if(stricmp(ixbname,fname)) if(lwrite(file,&ixbbuf[l],F_IXBSIZE)!=F_IXBSIZE) { close(file); free((char *)ixbbuf); return(FALSE); } } free((char *)ixbbuf); close(file); SAFEPRINTF2(str,"%s%s.dat",cfg->dir[f->dir]->data_dir,cfg->dir[f->dir]->code); if((file=sopen(str,O_WRONLY|O_BINARY,SH_DENYRW))==-1) { return(FALSE); } lseek(file,f->datoffset,SEEK_SET); c=ETX; /* If first char of record is ETX, record is unused */ if(write(file,&c,1)!=1) { /* So write a D_T on the first byte of the record */ close(file); return(FALSE); } close(file); if(f->dir==cfg->user_dir) /* remove file from index */ rmuserxfers(cfg,0,0,f->name); return(TRUE); }
void x_settitle(const char *title) { struct x11_local_event ev; ev.type=X11_LOCAL_SETTITLE; SAFECOPY(ev.data.title, title); while(write(local_pipe[1], &ev, sizeof(ev))==-1); }
void x_setname(const char *name) { struct x11_local_event ev; ev.type=X11_LOCAL_SETNAME; SAFECOPY(ev.data.name, name); while(write(local_pipe[1], &ev, sizeof(ev))==-1); }
int DLLCALL glob(const char *pattern, int flags, void* unused, glob_t* glob) { struct _finddata_t ff; long ff_handle; size_t found=0; char path[MAX_PATH+1]; char* p; char** new_pathv; if(!(flags&GLOB_APPEND)) { glob->gl_pathc=0; glob->gl_pathv=NULL; } ff_handle=_findfirst((char*)pattern,&ff); while(ff_handle!=-1) { if((flags&GLOB_PERIOD || (ff.name[0]!='.' && !(ff.attrib&_A_HIDDEN))) && (!(flags&GLOB_ONLYDIR) || ff.attrib&_A_SUBDIR)) { if((new_pathv=(char**)realloc(glob->gl_pathv ,(glob->gl_pathc+1)*sizeof(char*)))==NULL) { globfree(glob); return(GLOB_NOSPACE); } glob->gl_pathv=new_pathv; /* build the full pathname */ SAFECOPY(path,pattern); p=getfname(path); *p=0; strcat(path,ff.name); if((glob->gl_pathv[glob->gl_pathc]=(char*)malloc(strlen(path)+2))==NULL) { globfree(glob); return(GLOB_NOSPACE); } strcpy(glob->gl_pathv[glob->gl_pathc],path); if(flags&GLOB_MARK && ff.attrib&_A_SUBDIR) strcat(glob->gl_pathv[glob->gl_pathc],"/"); glob->gl_pathc++; found++; } if(_findnext(ff_handle, &ff)!=0) { _findclose(ff_handle); ff_handle=-1; } } if(found==0) return(GLOB_NOMATCH); if(!(flags&GLOB_NOSORT)) { qsort(glob->gl_pathv,found,sizeof(char*),glob_compare); } return(0); /* success */ }
void sbbs_t::fileinfo(file_t* f) { char ext[513]; char tmp[512]; char path[MAX_PATH+1]; char fpath[MAX_PATH+1]; uint i,j; for(i=0;i<usrlibs;i++) if(usrlib[i]==cfg.dir[f->dir]->lib) break; for(j=0;j<usrdirs[i];j++) if(usrdir[i][j]==f->dir) break; getfilepath(&cfg,f,path); bprintf(text[FiLib],i+1,cfg.lib[cfg.dir[f->dir]->lib]->lname); bprintf(text[FiDir],j+1,cfg.dir[f->dir]->lname); bprintf(text[FiFilename],getfname(path)); SAFECOPY(fpath,path); fexistcase(fpath); if(strcmp(path,fpath) && strcmp(f->desc,getfname(fpath))) /* Different "actual" filename */ bprintf(text[FiFilename],getfname(fpath)); if(f->size!=-1L) bprintf(text[FiFileSize],ultoac(f->size,tmp)); bprintf(text[FiCredits] ,(cfg.dir[f->dir]->misc&DIR_FREE || !f->cdt) ? "FREE" : ultoac(f->cdt,tmp)); bprintf(text[FiDescription],f->desc); bprintf(text[FiUploadedBy],f->misc&FM_ANON ? text[UNKNOWN_USER] : f->uler); if(f->date) bprintf(text[FiFileDate],timestr(&f->date)); bprintf(text[FiDateUled],timestr(&f->dateuled)); bprintf(text[FiDateDled],f->datedled ? timestr(&f->datedled) : "Never"); bprintf(text[FiTimesDled],f->timesdled); if(f->size!=-1L) bprintf(text[FiTransferTime],sectostr(f->timetodl,tmp)); if(f->altpath) { if(f->altpath<=cfg.altpaths) { if(SYSOP) bprintf(text[FiAlternatePath],cfg.altpath[f->altpath-1]); } else bprintf(text[InvalidAlternatePathN],f->altpath); } CRLF; if(f->misc&FM_EXTDESC) { getextdesc(&cfg,f->dir,f->datoffset,ext); CRLF; putmsg(ext,P_NOATCODES); CRLF; } if(f->size==-1L) bprintf(text[FileIsNotOnline],f->name); if(f->opencount) bprintf(text[FileIsOpen],f->opencount,f->opencount>1 ? "s" : nulstr); }
int sbbs_t::bulkmailhdr(smb_t* smb, smbmsg_t* msg, uint usernum) { char str[256]; int i,j; ushort nettype=NET_UNKNOWN; node_t node; user_t user; smbmsg_t newmsg; user.number=usernum; if(getuserdat(&cfg, &user)!=0) return(0); if((i=smb_copymsgmem(NULL,&newmsg,msg))!=SMB_SUCCESS) return(i); SAFECOPY(str,user.alias); smb_hfield_str(&newmsg,RECIPIENT,str); if(cfg.sys_misc&SM_FWDTONET && user.misc&NETMAIL && user.netmail[0]) { bprintf(text[UserNetMail],user.netmail); smb_hfield_netaddr(&newmsg,RECIPIENTNETADDR,user.netmail,&nettype); smb_hfield_bin(&newmsg,RECIPIENTNETTYPE,nettype); } else { sprintf(str,"%u",usernum); smb_hfield_str(&newmsg,RECIPIENTEXT,str); } j=smb_addmsghdr(smb,&newmsg,SMB_SELFPACK); smb_freemsgmem(&newmsg); if(j!=SMB_SUCCESS) return(j); lncntr=0; bprintf(text[Emailing],user.alias,usernum); sprintf(str,"%s bulk-mailed %s #%d" ,useron.alias,user.alias,usernum); logline("E+",str); useron.emails++; logon_emails++; useron.etoday++; for(i=1;i<=cfg.sys_nodes;i++) { /* Tell user, if online */ getnodedat(i,&node,0); if(node.useron==usernum && !(node.misc&NODE_POFF) && (node.status==NODE_INUSE || node.status==NODE_QUIET)) { sprintf(str,text[EmailNodeMsg],cfg.node_num,useron.alias); putnmsg(&cfg,i,str); break; } } if(i>cfg.sys_nodes) { /* User wasn't online, so leave short msg */ sprintf(str,text[UserSentYouMail],useron.alias); putsmsg(&cfg,usernum,str); } return(0); }
void sbbs_t::center(char *instr) { char str[256]; int i,j; SAFECOPY(str,instr); truncsp(str); j=bstrlen(str); for(i=0;i<(cols-j)/2;i++) outchar(' '); bputs(str); CRLF; }
void parse_ini(char* program) { char section[MAX_PATH+1]; if(ini==NULL) /* no initialization file */ return; /* Read the root section of the sbbsexec.ini file */ log_level=iniGetLogLevel(ini,program,"LogLevel",log_level); if(iniGetBool(ini,program,"Debug",FALSE)) log_level=LOG_DEBUG; yield_interval=iniGetFloat(ini,program,"YieldInterval",yield_interval); hangup_supported=iniGetBool(ini,program,"CanDisconnect",hangup_supported); lprintf(LOG_INFO,"Parsed %s section of %s" ,program==ROOT_SECTION ? "root" : program ,ini_fname); /* [UART] section */ if(program==ROOT_SECTION) SAFECOPY(section,"UART"); else SAFEPRINTF(section,"%s.UART",program); virtualize_uart=iniGetBool(ini,section,"Virtualize",virtualize_uart); switch(iniGetInteger(ini,section,"ComPort",0)) { case 1: /* COM1 */ uart_irq =UART_COM1_IRQ; uart_io_base =UART_COM1_IO_BASE; break; case 2: /* COM2 */ uart_irq =UART_COM2_IRQ; uart_io_base =UART_COM2_IO_BASE; break; case 3: /* COM3 */ uart_irq =UART_COM3_IRQ; uart_io_base =UART_COM3_IO_BASE; break; case 4: /* COM4 */ uart_irq =UART_COM4_IRQ; uart_io_base =UART_COM4_IO_BASE; break; } uart_irq=(BYTE)iniGetShortInt(ini,section,"IRQ",uart_irq); uart_io_base=iniGetShortInt(ini,section,"Address",uart_io_base); lprintf(LOG_INFO,"Parsed %s section of %s" ,section ,ini_fname); }
BOOL DLLCALL putfileixb(scfg_t* cfg, file_t* f) { char str[MAX_PATH+1],fname[13]; uchar* ixbbuf; int file; long l,length; SAFEPRINTF2(str,"%s%s.ixb",cfg->dir[f->dir]->data_dir,cfg->dir[f->dir]->code); if((file=sopen(str,O_RDWR|O_BINARY,SH_DENYRW))==-1) { return(FALSE); } length=(long)filelength(file); if(length%F_IXBSIZE) { close(file); return(FALSE); } if((ixbbuf=(uchar *)malloc(length))==NULL) { close(file); return(FALSE); } if(lread(file,ixbbuf,length)!=length) { close(file); free(ixbbuf); return(FALSE); } SAFECOPY(fname,f->name); for(l=8;l<12;l++) /* Turn FILENAME.EXT into FILENAMEEXT */ fname[l]=fname[l+1]; for(l=0;l<length;l+=F_IXBSIZE) { SAFEPRINTF(str,"%11.11s",ixbbuf+l); if(!stricmp(str,fname)) break; } free(ixbbuf); if(l>=length) { close(file); return(FALSE); } lseek(file,l+11+3,SEEK_SET); write(file,&f->dateuled,4); write(file,&f->datedled,4); close(file); return(TRUE); }
BOOL DLLCALL getfileixb(scfg_t* cfg, file_t* f) { char str[MAX_PATH+1],fname[13]; uchar * ixbbuf; int file; long l,length; SAFEPRINTF2(str,"%s%s.ixb",cfg->dir[f->dir]->data_dir,cfg->dir[f->dir]->code); if((file=sopen(str,O_RDONLY|O_BINARY,SH_DENYWR))==-1) { return(FALSE); } length=(long)filelength(file); if(length%F_IXBSIZE) { close(file); return(FALSE); } if((ixbbuf=(uchar *)malloc(length))==NULL) { close(file); return(FALSE); } if(lread(file,ixbbuf,length)!=length) { close(file); free((char *)ixbbuf); return(FALSE); } close(file); SAFECOPY(fname,f->name); for(l=8;l<12;l++) /* Turn FILENAME.EXT into FILENAMEEXT */ fname[l]=fname[l+1]; for(l=0;l<length;l+=F_IXBSIZE) { SAFEPRINTF(str,"%11.11s",ixbbuf+l); if(!stricmp(str,fname)) break; } if(l>=length) { free((char *)ixbbuf); return(FALSE); } l+=11; f->datoffset=ixbbuf[l]|((long)ixbbuf[l+1]<<8)|((long)ixbbuf[l+2]<<16); f->dateuled=ixbbuf[l+3]|((long)ixbbuf[l+4]<<8) |((long)ixbbuf[l+5]<<16)|((long)ixbbuf[l+6]<<24); f->datedled=ixbbuf[l+7]|((long)ixbbuf[l+8]<<8) |((long)ixbbuf[l+9]<<16)|((long)ixbbuf[l+10]<<24); free((char *)ixbbuf); return(TRUE); }
int DLLCALL update_uldate(scfg_t* cfg, file_t* f) { char str[MAX_PATH+1],fname[13]; int i,file; long l,length; /*******************/ /* Update IXB File */ /*******************/ SAFEPRINTF2(str,"%s%s.ixb",cfg->dir[f->dir]->data_dir,cfg->dir[f->dir]->code); if((file=nopen(str,O_RDWR))==-1) return(errno); length=(long)filelength(file); if(length%F_IXBSIZE) { close(file); return(-1); } SAFECOPY(fname,f->name); for(i=8;i<12;i++) /* Turn FILENAME.EXT into FILENAMEEXT */ fname[i]=fname[i+1]; for(l=0;l<length;l+=F_IXBSIZE) { read(file,str,F_IXBSIZE); /* Look for the filename in the IXB file */ str[11]=0; if(!stricmp(fname,str)) break; } if(l>=length) { close(file); return(-2); } lseek(file,l+14,SEEK_SET); write(file,&f->dateuled,4); close(file); /*******************************************/ /* Update last upload date/time stamp file */ /*******************************************/ SAFEPRINTF2(str,"%s%s.dab",cfg->dir[f->dir]->data_dir,cfg->dir[f->dir]->code); if((file=nopen(str,O_WRONLY|O_CREAT))==-1) return(errno); write(file,&f->dateuled,4); close(file); return(0); }
int sbbs_t::show_atcode(const char *instr) { char str[128],str2[128],*tp,*sp,*p; int len; int disp_len; bool padded_left=false; bool padded_right=false; const char *cp; SAFECOPY(str,instr); tp=strchr(str+1,'@'); if(!tp) /* no terminating @ */ return(0); sp=strchr(str+1,' '); if(sp && sp<tp) /* space before terminating @ */ return(0); len=(tp-str)+1; (*tp)=0; sp=(str+1); disp_len=len; if((p=strstr(sp,"-L"))!=NULL) padded_left=true; else if((p=strstr(sp,"-R"))!=NULL) padded_right=true; if(p!=NULL) { if(*(p+2) && isdigit(*(p+2))) disp_len=atoi(p+2); *p=0; } cp=atcode(sp,str2,sizeof(str2)); if(cp==NULL) return(0); if(padded_left) bprintf("%-*.*s",disp_len,disp_len,cp); else if(padded_right) bprintf("%*.*s",disp_len,disp_len,cp); else bputs(cp); return(len); }
static JSBool js_gettemplate(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { char str[128]; long mode=0; uintN i; sbbs_t* sbbs; JSString* js_str=NULL; JSString* js_fmt=NULL; if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL) return(JS_FALSE); for(i=0;i<argc;i++) { if(JSVAL_IS_STRING(argv[i])) { if(js_fmt==NULL) js_fmt = JS_ValueToString(cx, argv[i]); else js_str = JS_ValueToString(cx, argv[i]); } else if(JSVAL_IS_NUMBER(argv[i])) JS_ValueToInt32(cx,argv[i],(int32*)&mode); } if(js_fmt==NULL) return(JS_FALSE); if(js_str==NULL) str[0]=0; else SAFECOPY(str,JS_GetStringBytes(js_str)); sbbs->gettmplt(str,JS_GetStringBytes(js_fmt),mode); if((js_str=JS_NewStringCopyZ(cx, str))==NULL) return(JS_FALSE); *rval = STRING_TO_JSVAL(js_str); return(JS_TRUE); }
char* dszlog_filename(char* str) { char* p=str; static char path[MAX_PATH+1]; #ifdef _WIN32 char sfpath[MAX_PATH+1]; if(dszlog_short) { SAFECOPY(sfpath,str); GetShortPathName(str,sfpath,sizeof(sfpath)); p=sfpath; } #endif if(!dszlog_path) p=getfname(p); if(!dszlog_quotes) return(p); SAFEPRINTF(path,"\"%s\"",p); return(path); }
BOOL DLLCALL findfile(scfg_t* cfg, uint dirnum, char *filename) { char str[MAX_PATH+1],fname[13],*ixbbuf; int i,file; long length,l; SAFECOPY(fname,filename); strupr(fname); for(i=8;i<12;i++) /* Turn FILENAME.EXT into FILENAMEEXT */ fname[i]=fname[i+1]; SAFEPRINTF2(str,"%s%s.ixb",cfg->dir[dirnum]->data_dir,cfg->dir[dirnum]->code); if((file=sopen(str,O_RDONLY|O_BINARY,SH_DENYWR))==-1) return(FALSE); length=(long)filelength(file); if(!length) { close(file); return(FALSE); } if((ixbbuf=(char *)malloc(length))==NULL) { close(file); return(FALSE); } if(lread(file,ixbbuf,length)!=length) { close(file); free((char *)ixbbuf); return(FALSE); } close(file); for(l=0;l<length;l+=F_IXBSIZE) { for(i=0;i<11;i++) if(toupper(fname[i])!=toupper(ixbbuf[l+i])) break; if(i==11) break; } free((char *)ixbbuf); if(l!=length) return(TRUE); return(FALSE); }
int removecase(const char *path) { char inpath[MAX_PATH+1]; char fname[MAX_PATH*4+1]; char tmp[5]; char *p; int i; if(strchr(path,'?') || strchr(path,'*')) return(-1); SAFECOPY(inpath,path); p=getfname(inpath); fname[0]=0; for(i=0;p[i];i++) { if(isalpha(p[i])) sprintf(tmp,"[%c%c]",toupper(p[i]),tolower(p[i])); else sprintf(tmp,"%c",p[i]); strncat(fname,tmp,MAX_PATH*4); } *p=0; return(delfiles(inpath,fname)?-1:0); }
int fixsmb(char* sub) { char* p; char* text; char c; int i,w; ulong l,length,size,n; smbmsg_t msg; memset(&smb,0,sizeof(smb)); SAFECOPY(smb.file,sub); if((p=getfext(smb.file))!=NULL && stricmp(p,".shd")==0) *p=0; /* Chop off .shd extension, if supplied on command-line */ printf("Opening %s\n",smb.file); if((i=smb_open(&smb))!=0) { printf("smb_open returned %d: %s\n",i,smb.last_error); exit(1); } if((i=smb_lock(&smb))!=0) { printf("smb_lock returned %d: %s\n",i,smb.last_error); exit(1); } if((i=smb_locksmbhdr(&smb))!=0) { smb_close(&smb); printf("smb_locksmbhdr returned %d: %s\n",i,smb.last_error); exit(1); } if((i=smb_getstatus(&smb))!=0) { smb_unlocksmbhdr(&smb); smb_close(&smb); printf("smb_getstatus returned %d: %s\n",i,smb.last_error); exit(1); } if(!(smb.status.attr&SMB_HYPERALLOC)) { if((i=smb_open_ha(&smb))!=0) { smb_close(&smb); printf("smb_open_ha returned %d: %s\n",i,smb.last_error); exit(1); } if((i=smb_open_da(&smb))!=0) { smb_close(&smb); printf("smb_open_da returned %d: %s\n",i,smb.last_error); exit(1); } rewind(smb.sha_fp); chsize(fileno(smb.sha_fp),0L); /* Truncate the header allocation file */ rewind(smb.sda_fp); chsize(fileno(smb.sda_fp),0L); /* Truncate the data allocation file */ } rewind(smb.sid_fp); chsize(fileno(smb.sid_fp),0L); /* Truncate the index */ if(!(smb.status.attr&SMB_HYPERALLOC)) { length=filelength(fileno(smb.sdt_fp)); w=0; for(l=0;l<length;l+=SDT_BLOCK_LEN) /* Init .SDA file to NULL */ fwrite(&w,2,1,smb.sda_fp); length=filelength(fileno(smb.shd_fp)); c=0; for(l=0;l<length;l+=SHD_BLOCK_LEN) /* Init .SHD file to NULL */ fwrite(&c,1,1,smb.sha_fp); } else length=filelength(fileno(smb.shd_fp)); n=0; /* messsage offset */ for(l=smb.status.header_offset;l<length;l+=size) { size=SHD_BLOCK_LEN; printf("\r%2lu%% ",(long)(100.0/((float)length/l))); msg.idx.offset=l; if((i=smb_lockmsghdr(&smb,&msg))!=0) { printf("\n(%06lX) smb_lockmsghdr returned %d:\n%s\n",l,i,smb.last_error); continue; } i=smb_getmsghdr(&smb,&msg); smb_unlockmsghdr(&smb,&msg); if(i!=0) { printf("\n(%06lX) smb_getmsghdr returned %d:\n%s\n",l,i,smb.last_error); continue; } size=smb_hdrblocks(smb_getmsghdrlen(&msg))*SHD_BLOCK_LEN; printf("#%-5lu (%06lX) %-25.25s ",msg.hdr.number,l,msg.from); /* Create hash record */ if(msg.hdr.attr&MSG_DELETE) text=NULL; else text=smb_getmsgtxt(&smb,&msg,GETMSGTXT_BODY_ONLY); i=smb_hashmsg(&smb,&msg,text,TRUE /* update */); if(i!=SMB_SUCCESS) printf("!ERROR %d hashing message\n", i); if(text!=NULL) free(text); /* Index the header */ if(msg.hdr.attr&MSG_DELETE) printf("Not indexing deleted message\n"); else if(msg.hdr.number==0) printf("Not indexing invalid message number (0)!\n"); else { msg.offset=n; if(renumber) msg.hdr.number=n+1; if(msg.hdr.netattr&MSG_INTRANSIT) { printf("Removing 'in transit' attribute\n"); msg.hdr.netattr&=~MSG_INTRANSIT; } if((i=smb_putmsg(&smb,&msg))!=0) { printf("\nsmb_putmsg returned %d: %s\n",i,smb.last_error); continue; } n++; } if(!(smb.status.attr&SMB_HYPERALLOC)) { /**************************/ /* Allocate header blocks */ /**************************/ fseek(smb.sha_fp,(l-smb.status.header_offset)/SHD_BLOCK_LEN,SEEK_SET); if(msg.hdr.attr&MSG_DELETE) c=0; /* mark as free */ else c=1; /* or allocated */ for(i=0;i<(int)(size/SHD_BLOCK_LEN);i++) fputc(c,smb.sha_fp); /************************/ /* Allocate data blocks */ /************************/ if(!(msg.hdr.attr&MSG_DELETE)) smb_incmsg_dfields(&smb,&msg,1); } smb_freemsgmem(&msg); } printf("\r%79s\r100%%\n",""); smb.status.total_msgs=n; if(renumber) smb.status.last_msg=n; else sort_index(&smb); printf("Saving message base status (%lu total messages).\n",n); if((i=smb_putstatus(&smb))!=0) printf("\nsmb_putstatus returned %d: %s\n",i,smb.last_error); smb_unlocksmbhdr(&smb); printf("Closing message base.\n"); smb_close(&smb); unlock_msgbase(); printf("Done.\n"); return(0); }
long sbbs_t::getkeys(char *keys, ulong max) { char str[81]; uchar ch,n=0,c=0; ulong i=0; SAFECOPY(str,keys); strupr(str); while(online) { ch=getkey(K_UPPER); if(max && ch>0x7f) /* extended ascii chars are digits to isdigit() */ continue; if(sys_status&SS_ABORT) { /* return -1 if Ctrl-C hit */ attr(LIGHTGRAY); CRLF; lncntr=0; return(-1); } if(ch && !n && (strchr(str,ch))) { /* return character if in string */ outchar(ch); if(useron.misc&COLDKEYS && ch>' ') { while(online && !(sys_status&SS_ABORT)) { c=getkey(0); if(c==CR || c==BS || c==DEL) break; } if(sys_status&SS_ABORT) { CRLF; return(-1); } if(c==BS || c==DEL) { backspace(); continue; } } attr(LIGHTGRAY); CRLF; lncntr=0; return(ch); } if(ch==CR && max) { /* return 0 if no number */ attr(LIGHTGRAY); CRLF; lncntr=0; if(n) return(i|0x80000000L); /* return number plus high bit */ return(0); } if((ch==BS || ch==DEL) && n) { backspace(); i/=10; n--; } else if(max && isdigit(ch) && (i*10)+(ch&0xf)<=max && (ch!='0' || n)) { i*=10; n++; i+=ch&0xf; outchar(ch); if(i*10>max && !(useron.misc&COLDKEYS)) { attr(LIGHTGRAY); CRLF; lncntr=0; return(i|0x80000000L); } } } return(-1); }
BOOL DLLCALL fexistcase(char *path) { #if defined(_WIN32) char* fname; long handle; struct _finddata_t f; if(access(path,0)==-1 && !strchr(path,'*') && !strchr(path,'?')) return(FALSE); if((handle=_findfirst((char*)path,&f))==-1) return(FALSE); _findclose(handle); if(f.attrib&_A_SUBDIR) return(FALSE); fname=getfname(path); /* Find filename in path */ strcpy(fname,f.name); /* Correct filename */ return(TRUE); #else /* Unix or OS/2 */ char globme[MAX_PATH*4+1]; char fname[MAX_PATH+1]; char tmp[5]; char *p; int i; glob_t glb; if(path[0]==0) /* work around glibc bug 574274 */ return FALSE; if(!strchr(path,'*') && !strchr(path,'?') && fnameexist(path)) return(TRUE); SAFECOPY(globme,path); p=getfname(globme); SAFECOPY(fname,p); *p=0; for(i=0;fname[i];i++) { if(isalpha(fname[i])) sprintf(tmp,"[%c%c]",toupper(fname[i]),tolower(fname[i])); else sprintf(tmp,"%c",fname[i]); strncat(globme,tmp,MAX_PATH*4); } #if 0 if(strcspn(path,"?*")!=strlen(path)) { sprintf(path,"%.*s",MAX_PATH,globme); return(fexist(path)); } #endif if(glob(globme,GLOB_MARK,NULL,&glb) != 0) return(FALSE); if(glb.gl_pathc>0) { for(i=0;i<glb.gl_pathc;i++) { if(*lastchar(glb.gl_pathv[i]) != '/') break; } if(i<glb.gl_pathc) { sprintf(path,"%.*s",MAX_PATH,glb.gl_pathv[i]); globfree(&glb); return TRUE; } } globfree(&glb); return FALSE; #endif }
BOOL wait_for_call(COM_HANDLE com_handle) { char str[128]; char* p; BOOL result=TRUE; DWORD events=0; time_t start=time(NULL); ZERO_VAR(cid_name); ZERO_VAR(cid_number); if(!comRaiseDTR(com_handle)) lprintf(LOG_ERR,"ERROR %u raising DTR", COM_ERROR_VALUE); if(com_alreadyconnected) return TRUE; if(!mdm_null) { if(mdm_init[0]) { lprintf(LOG_INFO,"Initializing modem:"); if(!modem_command(com_handle, mdm_init)) return FALSE; } if(!mdm_manswer && mdm_autoans[0]) { lprintf(LOG_INFO,"Setting modem to auto-answer:"); if(!modem_command(com_handle, mdm_autoans)) return FALSE; } if(mdm_cid[0]) { lprintf(LOG_INFO,"Enabling modem Caller-ID:"); if(!modem_command(com_handle, mdm_cid)) return FALSE; } } lprintf(LOG_INFO,"Waiting for incoming call (%s) ...", mdm_manswer ? "Ring Indication" : "Carrier Detect"); while(1) { if(terminated) return FALSE; if(comReadLine(com_handle, str, sizeof(str), /* timeout (ms): */250) > 0) { truncsp(str); if(str[0]==0) continue; lprintf(LOG_DEBUG,"Received from modem: '%s'", str); p=str; SKIP_WHITESPACE(p); if(*p) { lprintf(LOG_INFO, "Modem Message: %s", p); if(strncmp(p,"CONNECT ",8)==0) { long rate=atoi(p+8); if(rate) SAFEPRINTF2(termspeed,"%u,%u", rate, rate); } else if(strncmp(p,"NMBR",4)==0 || strncmp(p,"MESG",4)==0) { p+=4; FIND_CHAR(p,'='); SKIP_CHAR(p,'='); SKIP_WHITESPACE(p); if(cid_number[0]==0) /* Don't overwrite, if multiple messages received */ SAFECOPY(cid_number, p); } else if(strncmp(p,"NAME",4)==0) { p+=4; FIND_CHAR(p,'='); SKIP_CHAR(p,'='); SKIP_WHITESPACE(p); SAFECOPY(cid_name, p); } else if(strcmp(p,"NO CARRIER")==0) { ZERO_VAR(cid_name); ZERO_VAR(cid_number); } else if(mdm_ring[0] && strcmp(p,mdm_ring)==0 && mdm_manswer && mdm_answer[0]) { if(!modem_send(com_handle, mdm_answer)) { lprintf(LOG_ERR,"ERROR %u sending modem command (%s) on %s" ,COM_ERROR_VALUE, mdm_answer, com_dev); } } } continue; /* don't check DCD until we've received all the modem msgs */ } if(carrier_detect(com_handle)) break; if(mdm_reinit && (time(NULL)-start)/60 >= mdm_reinit) { lprintf(LOG_INFO,"Re-initialization timer elapsed: %u minutes", mdm_reinit); return TRUE; } } if(strcmp(cid_name,"P")==0) SAFECOPY(cid_name,"Private"); else if(strcmp(cid_name,"O")==0) SAFECOPY(cid_name,"Out-of-area"); if(strcmp(cid_number,"P")==0) SAFECOPY(cid_number,"Private"); else if(strcmp(cid_number,"O")==0) SAFECOPY(cid_number,"Out-of-area"); lprintf(LOG_INFO,"Carrier detected"); return TRUE; }
int main(int argc, char** argv) { int argn; char* arg; char* p; char path[MAX_PATH+1]; char fname[MAX_PATH+1]; char ini_fname[MAX_PATH+1]; /*******************************/ /* Generate and display banner */ /*******************************/ sscanf("$Revision$", "%*s %s", revision); sprintf(banner,"\n%s v%s-%s" " Copyright %s Rob Swindell" ,TITLE ,revision ,PLATFORM_DESC ,__DATE__+7 ); fprintf(stdout,"%s\n\n", banner); /**********************/ /* Parse command-line */ /**********************/ for(argn=1; argn<argc; argn++) { arg=argv[argn]; while(*arg=='-') arg++; if(stricmp(arg,"help")==0 || *arg=='?') return usage(argv[0]); #ifdef _WIN32 else if(stricmp(arg,"service")==0) daemonize=TRUE; else if(stricmp(arg,"install")==0) return install(); else if(stricmp(arg,"remove")==0) return uninstall(); else if(stricmp(arg,"disable")==0) return enable(FALSE); else if(stricmp(arg,"enable")==0) return enable(TRUE); #endif } /******************/ /* Read .ini file */ /******************/ /* Generate path/sexpots[.host].ini from path/sexpots[.exe] */ SAFECOPY(path,argv[0]); p=getfname(path); SAFECOPY(fname,p); *p=0; if((p=getfext(fname))!=NULL) *p=0; strcat(fname,".ini"); iniFileName(ini_fname,sizeof(ini_fname),path,fname); parse_ini_file(ini_fname); #if defined(_WIN32) if(daemonize) { SERVICE_TABLE_ENTRY ServiceDispatchTable[] = { { NAME, (void(WINAPI*)(DWORD, char**))service_loop }, { NULL, NULL } /* Terminator */ }; printf("Starting service control dispatcher.\n" ); printf("This may take several seconds. Please wait.\n" ); if(!StartServiceCtrlDispatcher(ServiceDispatchTable)) { lprintf(LOG_ERR,"StartServiceCtrlDispatcher ERROR %d",GetLastError()); return -1; } return 0; } SetConsoleCtrlHandler(ControlHandler, TRUE /* Add */); #endif service_loop(argc,argv); return 0; }
static void #if defined(_WIN32) WINAPI #endif service_loop(int argc, char** argv) { int argn; char* arg; char str[128]; char compiler[128]; for(argn=1; argn<(int)argc; argn++) { arg=argv[argn]; if(*arg!='-') { /* .ini file specified */ if(!fexist(arg)) { lprintf(LOG_ERR,"Initialization file does not exist: %s", arg); exit(usage(argv[0])); } parse_ini_file(arg); continue; } while(*arg=='-') arg++; if(stricmp(arg,"null")==0) mdm_null=TRUE; else if(stricmp(arg,"com")==0 && argc > argn+1) SAFECOPY(com_dev, argv[++argn]); else if(stricmp(arg,"baud")==0 && argc > argn+1) com_baudrate = (ulong)strtol(argv[++argn],NULL,0); else if(stricmp(arg,"host")==0 && argc > argn+1) SAFECOPY(host, argv[++argn]); else if(stricmp(arg,"port")==0 && argc > argn+1) port = (ushort)strtol(argv[++argn], NULL, 0); else if(stricmp(arg,"live")==0) { if(argc > argn+1 && (com_handle = (COM_HANDLE)strtol(argv[argn+1], NULL, 0)) != 0) { argn++; com_handle_passed=TRUE; } com_alreadyconnected=TRUE; terminate_after_one_call=TRUE; mdm_null=TRUE; } else if(stricmp(arg,"nohangup")==0) { com_hangup=FALSE; } else if(stricmp(arg,"debug")==0) { log_level=LOG_DEBUG; } else if(stricmp(arg,"help")==0 || *arg=='?') exit(usage(argv[0])); else { fprintf(stderr,"Invalid option: %s\n", arg); exit(usage(argv[0])); } } #if defined(_WIN32) /* Convert "1" to "COM1" for Windows */ { int i; if((i=atoi(com_dev)) != 0) SAFEPRINTF(com_dev, "COM%d", i); } if(daemonize) { if((svc_status_handle = RegisterServiceCtrlHandler(NAME, ServiceControlHandler))==0) { lprintf(LOG_ERR,"!ERROR %d registering service control handler",GetLastError()); return; } svc_status.dwServiceType=SERVICE_WIN32_OWN_PROCESS; svc_status.dwControlsAccepted=SERVICE_ACCEPT_SHUTDOWN; svc_status.dwWaitHint=NTSVC_TIMEOUT_STARTUP; svc_status.dwCurrentState=SERVICE_START_PENDING; SetServiceStatus(svc_status_handle, &svc_status); } #endif lprintf(LOG_INFO,"%s", comVersion(str,sizeof(str))); DESCRIBE_COMPILER(compiler); lprintf(LOG_INFO,"Build %s %s %s", __DATE__, __TIME__, compiler); /************************************/ /* Inititalize WinSock and COM Port */ /************************************/ if(!winsock_startup()) exit(1); /* Install clean-up callback */ atexit(cleanup); lprintf(LOG_INFO,"TCP Host: %s", host); lprintf(LOG_INFO,"TCP Port: %u", port); if(!com_handle_passed) { lprintf(LOG_INFO,"Opening Communications Device (COM Port): %s", com_dev); if((com_handle=comOpen(com_dev)) == COM_HANDLE_INVALID) { lprintf(LOG_ERR,"ERROR %u opening communications device/port: '%s'", COM_ERROR_VALUE, com_dev); exit(1); } } lprintf(LOG_INFO,"COM Port device handle: %u", com_handle); if(com_baudrate!=0) { if(!comSetBaudRate(com_handle,com_baudrate)) lprintf(LOG_ERR,"ERROR %u setting DTE rate to %lu bps" ,COM_ERROR_VALUE, com_baudrate); } lprintf(LOG_INFO,"COM Port DTE rate: %ld bps", comGetBaudRate(com_handle)); if(ident) _beginthread(ident_server_thread, 0, NULL); #if defined(_WIN32) if(daemonize) { svc_status.dwCurrentState=SERVICE_RUNNING; svc_status.dwControlsAccepted|=SERVICE_ACCEPT_STOP; SetServiceStatus(svc_status_handle, &svc_status); } #endif /***************************/ /* Initialization Complete */ /***************************/ /* Main service loop: */ while(!terminated && wait_for_call(com_handle)) { if(!carrier_detect(com_handle)) /* re-initialization timer time-out? */ continue; comWriteByte(com_handle,'\r'); comWriteString(com_handle, banner); comWriteString(com_handle, "\r\n"); if((sock=connect_socket(host, port)) == INVALID_SOCKET) { comWriteString(com_handle,"\7\r\n!ERROR connecting to TCP port\r\n"); } else { handle_call(); close_socket(&sock); total_calls++; lprintf(LOG_INFO,"Call completed (%lu total)", total_calls); } if(com_hangup && !hangup_call(com_handle)) break; if(terminate_after_one_call) break; } exit(0); }
void guru_cfg() { static int guru_dflt,guru_bar,opt_dflt; char str[128],code[128],done=0; int j,k; uint i; static guru_t savguru; while(1) { for(i=0;i<cfg.total_gurus && i<MAX_OPTS;i++) sprintf(opt[i],"%-25s",cfg.guru[i]->name); opt[i][0]=0; j=WIN_ACT|WIN_SAV|WIN_RHT|WIN_BOT; if(cfg.total_gurus) j|=WIN_DEL|WIN_GET; if(cfg.total_gurus<MAX_OPTS) j|=WIN_INS|WIN_INSACT|WIN_XTR; if(savguru.name[0]) j|=WIN_PUT; uifc.helpbuf= "`Gurus:`\n" "\n" "This is a list of the configured Gurus.\n" "\n" "To add a Guru, select the desired location with the arrow keys and\n" "hit ~ INS ~.\n" "\n" "To delete a Guru, select it with the arrow keys and hit ~ DEL ~.\n" "\n" "To configure a Guru, select it with the arrow keys and hit ~ ENTER ~.\n" ; i=uifc.list(j,0,0,45,&guru_dflt,&guru_bar,"Artificial Gurus",opt); if((signed)i==-1) return; if((i&MSK_ON)==MSK_INS) { i&=MSK_OFF; uifc.helpbuf= "`Guru Name:`\n" "\n" "This is the name of the selected Guru.\n" ; if(uifc.input(WIN_MID|WIN_SAV,0,0,"Guru Name",str,25 ,0)<1) continue; SAFECOPY(code,str); prep_code(code,/* prefix: */NULL); uifc.helpbuf= "`Guru Internal Code:`\n" "\n" "Every Guru must have its own unique code for Synchronet to refer to\n" "it internally. This code is usually an abreviation of the Guru name.\n" ; if(uifc.input(WIN_MID|WIN_SAV,0,0,"Internal Code" ,code,LEN_CODE,K_EDIT|K_UPPER)<1) continue; if(!code_ok(code)) { uifc.helpbuf=invalid_code; uifc.msg("Invalid Code"); uifc.helpbuf=0; continue; } if((cfg.guru=(guru_t **)realloc(cfg.guru,sizeof(guru_t *)*(cfg.total_gurus+1))) ==NULL) { errormsg(WHERE,ERR_ALLOC,nulstr,cfg.total_gurus+1); cfg.total_gurus=0; bail(1); continue; } if(cfg.total_gurus) for(j=cfg.total_gurus;j>i;j--) cfg.guru[j]=cfg.guru[j-1]; if((cfg.guru[i]=(guru_t *)malloc(sizeof(guru_t)))==NULL) { errormsg(WHERE,ERR_ALLOC,nulstr,sizeof(guru_t)); continue; } memset((guru_t *)cfg.guru[i],0,sizeof(guru_t)); strcpy(cfg.guru[i]->name,str); strcpy(cfg.guru[i]->code,code); cfg.total_gurus++; uifc.changes=1; continue; } if((i&MSK_ON)==MSK_DEL) { i&=MSK_OFF; free(cfg.guru[i]); cfg.total_gurus--; for(j=i;j<cfg.total_gurus;j++) cfg.guru[j]=cfg.guru[j+1]; uifc.changes=1; continue; } if((i&MSK_ON)==MSK_GET) { i&=MSK_OFF; savguru=*cfg.guru[i]; continue; } if((i&MSK_ON)==MSK_PUT) { i&=MSK_OFF; *cfg.guru[i]=savguru; uifc.changes=1; continue; } j=0; done=0; while(!done) { k=0; sprintf(opt[k++],"%-27.27s%s","Guru Name",cfg.guru[i]->name); sprintf(opt[k++],"%-27.27s%s","Guru Internal Code",cfg.guru[i]->code); sprintf(opt[k++],"%-27.27s%.40s","Access Requirements",cfg.guru[i]->arstr); opt[k][0]=0; uifc.helpbuf= "`Guru Configuration:`\n" "\n" "This menu is for configuring the selected Guru.\n" ; switch(uifc.list(WIN_ACT|WIN_MID|WIN_SAV,0,0,60,&opt_dflt,0,cfg.guru[i]->name ,opt)) { case -1: done=1; break; case 0: uifc.helpbuf= "`Guru Name:`\n" "\n" "This is the name of the selected Guru.\n" ; strcpy(str,cfg.guru[i]->name); if(!uifc.input(WIN_MID|WIN_SAV,0,10,"Guru Name" ,cfg.guru[i]->name,sizeof(cfg.guru[i]->name)-1,K_EDIT)) strcpy(cfg.guru[i]->name,str); break; case 1: uifc.helpbuf= "`Guru Internal Code:`\n" "\n" "Every Guru must have its own unique code for Synchronet to refer to\n" "it internally. This code is usually an abreviation of the Guru name.\n" ; strcpy(str,cfg.guru[i]->code); if(!uifc.input(WIN_MID|WIN_SAV,0,0,"Guru Internal Code" ,str,LEN_CODE,K_EDIT|K_UPPER)) break; if(code_ok(str)) strcpy(cfg.guru[i]->code,str); else { uifc.helpbuf=invalid_code; uifc.msg("Invalid Code"); uifc.helpbuf=0; } break; case 2: getar(cfg.guru[i]->name,cfg.guru[i]->arstr); break; } } } }
void chan_cfg() { static int chan_dflt,chan_bar,opt_dflt; char str[128],code[128],done=0; int j,k; uint i; static chan_t savchan; while(1) { for(i=0;i<cfg.total_chans && i<MAX_OPTS;i++) sprintf(opt[i],"%-25s",cfg.chan[i]->name); opt[i][0]=0; j=WIN_ACT|WIN_SAV|WIN_BOT|WIN_RHT; if(cfg.total_chans) j|=WIN_DEL|WIN_GET; if(cfg.total_chans<MAX_OPTS) j|=WIN_INS|WIN_INSACT|WIN_XTR; if(savchan.name[0]) j|=WIN_PUT; uifc.helpbuf= "`Multinode Chat Channels:`\n" "\n" "This is a list of the configured multinode chat channels.\n" "\n" "To add a channel, select the desired location with the arrow keys and\n" "hit ~ INS ~.\n" "\n" "To delete a channel, select it with the arrow keys and hit ~ DEL ~.\n" "\n" "To configure a channel, select it with the arrow keys and hit ~ ENTER ~.\n" ; i=uifc.list(j,0,0,45,&chan_dflt,&chan_bar,"Multinode Chat Channels",opt); if((signed)i==-1) return; if((i&MSK_ON)==MSK_INS) { i&=MSK_OFF; strcpy(str,"Open"); uifc.helpbuf= "`Channel Name:`\n" "\n" "This is the name or description of the chat channel.\n" ; if(uifc.input(WIN_MID|WIN_SAV,0,0,"Chat Channel Name",str,25 ,K_EDIT)<1) continue; SAFECOPY(code,str); prep_code(code,/* prefix: */NULL); uifc.helpbuf= "`Chat Channel Internal Code:`\n" "\n" "Every chat channel must have its own unique code for Synchronet to refer\n" "to it internally. This code is usually an abreviation of the chat\n" "channel name.\n" ; if(uifc.input(WIN_MID|WIN_SAV,0,0,"Internal Code" ,code,LEN_CODE,K_EDIT|K_UPPER)<1) continue; if(!code_ok(code)) { uifc.helpbuf=invalid_code; uifc.msg("Invalid Code"); uifc.helpbuf=0; continue; } if((cfg.chan=(chan_t **)realloc(cfg.chan,sizeof(chan_t *)*(cfg.total_chans+1))) ==NULL) { errormsg(WHERE,ERR_ALLOC,nulstr,cfg.total_chans+1); cfg.total_chans=0; bail(1); continue; } if(cfg.total_chans) for(j=cfg.total_chans;j>i;j--) cfg.chan[j]=cfg.chan[j-1]; if((cfg.chan[i]=(chan_t *)malloc(sizeof(chan_t)))==NULL) { errormsg(WHERE,ERR_ALLOC,nulstr,sizeof(chan_t)); continue; } memset((chan_t *)cfg.chan[i],0,sizeof(chan_t)); strcpy(cfg.chan[i]->name,str); strcpy(cfg.chan[i]->code,code); cfg.total_chans++; uifc.changes=1; continue; } if((i&MSK_ON)==MSK_DEL) { i&=MSK_OFF; free(cfg.chan[i]); cfg.total_chans--; for(j=i;j<cfg.total_chans;j++) cfg.chan[j]=cfg.chan[j+1]; uifc.changes=1; continue; } if((i&MSK_ON)==MSK_GET) { i&=MSK_OFF; savchan=*cfg.chan[i]; continue; } if((i&MSK_ON)==MSK_PUT) { i&=MSK_OFF; *cfg.chan[i]=savchan; uifc.changes=1; continue; } j=0; done=0; while(!done) { k=0; sprintf(opt[k++],"%-27.27s%s","Name",cfg.chan[i]->name); sprintf(opt[k++],"%-27.27s%s","Internal Code",cfg.chan[i]->code); sprintf(opt[k++],"%-27.27s%"PRIu32,"Cost in Credits",cfg.chan[i]->cost); sprintf(opt[k++],"%-27.27s%.40s","Access Requirements" ,cfg.chan[i]->arstr); sprintf(opt[k++],"%-27.27s%s","Password Protection" ,cfg.chan[i]->misc&CHAN_PW ? "Yes" : "No"); sprintf(opt[k++],"%-27.27s%s","Guru Joins When Empty" ,cfg.chan[i]->misc&CHAN_GURU ? "Yes" : "No"); sprintf(opt[k++],"%-27.27s%s","Channel Guru" ,cfg.chan[i]->guru<cfg.total_gurus ? cfg.guru[cfg.chan[i]->guru]->name : ""); sprintf(opt[k++],"%-27.27s%s","Channel Action Set" ,cfg.actset[cfg.chan[i]->actset]->name); opt[k][0]=0; uifc.helpbuf= "`Chat Channel Configuration:`\n" "\n" "This menu is for configuring the selected chat channel.\n" ; sprintf(str,"%s Chat Channel",cfg.chan[i]->name); switch(uifc.list(WIN_ACT|WIN_MID|WIN_SAV,0,0,60,&opt_dflt,0,str,opt)) { case -1: done=1; break; case 0: uifc.helpbuf= "`Chat Channel Name:`\n" "\n" "This is the name or description of the chat channel.\n" ; strcpy(str,cfg.chan[i]->name); if(!uifc.input(WIN_MID|WIN_SAV,0,10,"Chat Channel Name" ,cfg.chan[i]->name,sizeof(cfg.chan[i]->name)-1,K_EDIT)) strcpy(cfg.chan[i]->name,str); break; case 1: uifc.helpbuf= "`Chat Channel Internal Code:`\n" "\n" "Every chat channel must have its own unique code for Synchronet to refer\n" "to it internally. This code is usually an abreviation of the chat\n" "channel name.\n" ; strcpy(str,cfg.chan[i]->code); if(!uifc.input(WIN_MID|WIN_SAV,0,10,"Internal Code" ,str,LEN_CODE,K_UPPER|K_EDIT)) break; if(code_ok(str)) strcpy(cfg.chan[i]->code,str); else { uifc.helpbuf=invalid_code; uifc.msg("Invalid Code"); uifc.helpbuf=0; } break; case 2: ultoa(cfg.chan[i]->cost,str,10); uifc.helpbuf= "`Chat Channel Cost to Join:`\n" "\n" "If you want users to be charged credits to join this chat channel, set\n" "this value to the number of credits to charge. If you want this channel\n" "to be free, set this value to `0`.\n" ; uifc.input(WIN_MID|WIN_SAV,0,0,"Cost to Join (in Credits)" ,str,10,K_EDIT|K_NUMBER); cfg.chan[i]->cost=atol(str); break; case 3: sprintf(str,"%s Chat Channel",cfg.chan[i]->name); getar(str,cfg.chan[i]->arstr); break; case 4: k=1; uifc.helpbuf= "`Allow Channel to be Password Protected:`\n" "\n" "If you want to allow the first user to join this channel to password\n" "protect it, set this option to `Yes`.\n" ; k=uifc.list(WIN_MID|WIN_SAV,0,0,0,&k,0 ,"Allow Channel to be Password Protected" ,uifcYesNoOpts); if(!k && !(cfg.chan[i]->misc&CHAN_PW)) { cfg.chan[i]->misc|=CHAN_PW; uifc.changes=1; } else if(k==1 && cfg.chan[i]->misc&CHAN_PW) { cfg.chan[i]->misc&=~CHAN_PW; uifc.changes=1; } break; case 5: k=1; uifc.helpbuf= "`Guru Joins This Channel When Empty:`\n" "\n" "If you want the system guru to join this chat channel when there is\n" "only one user, set this option to `Yes`.\n" ; k=uifc.list(WIN_MID|WIN_SAV,0,0,0,&k,0 ,"Guru Joins This Channel When Empty" ,uifcYesNoOpts); if(!k && !(cfg.chan[i]->misc&CHAN_GURU)) { cfg.chan[i]->misc|=CHAN_GURU; uifc.changes=1; } else if(k==1 && cfg.chan[i]->misc&CHAN_GURU) { cfg.chan[i]->misc&=~CHAN_GURU; uifc.changes=1; } break; case 6: uifc.helpbuf= "`Channel Guru:`\n" "\n" "This is a list of available chat Gurus. Select the one that you wish\n" "to have available in this channel.\n" ; k=0; for(j=0;j<cfg.total_gurus && j<MAX_OPTS;j++) sprintf(opt[j],"%-25s",cfg.guru[j]->name); opt[j][0]=0; k=uifc.list(WIN_SAV|WIN_RHT,0,0,25,&j,0 ,"Available Chat Gurus",opt); if(k==-1) break; cfg.chan[i]->guru=k; break; case 7: uifc.helpbuf= "`Channel Action Set:`\n" "\n" "This is a list of available chat action sets. Select the one that you\n" "wish to have available in this channel.\n" ; k=0; for(j=0;j<cfg.total_actsets && j<MAX_OPTS;j++) sprintf(opt[j],"%-25s",cfg.actset[j]->name); opt[j][0]=0; k=uifc.list(WIN_SAV|WIN_RHT,0,0,25,&j,0 ,"Available Chat Action Sets",opt); if(k==-1) break; uifc.changes=1; cfg.chan[i]->actset=k; break; } } } }