moved
This commit is contained in:
parent
1e8f318637
commit
9e5f59649f
@ -27,28 +27,37 @@
|
||||
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
# SUCH DAMAGE.
|
||||
#
|
||||
# $Amigan: phoned/xfone/maindlg.tcl,v 1.2 2005/06/26 16:51:00 dcp1990 Exp $
|
||||
# $Amigan: phoned/xfone/maindlg.tcl,v 1.3 2005/06/27 00:08:47 dcp1990 Exp $
|
||||
# vars
|
||||
proc logindlg {} {
|
||||
toplevel .login
|
||||
frame .login.m -width 5c -height 2c
|
||||
grid .m -row 0 -column 0
|
||||
label .login.m.lo -text "Login:"
|
||||
entry .login.m.loge
|
||||
grid .login.m.lo .login.m.loge -row 0
|
||||
label .login.m.pa -text "Pass:"
|
||||
entry .login.m.pase -show "*"
|
||||
grid .login.m.pa .login.m.pase -row 1
|
||||
button .login.m.log -text "Login" -command {loginProc [.login.m.loge get] [.login.m.pase get]}
|
||||
button .login.m.cancel -text "Cancel" -command {destroy .login}
|
||||
grid .login.m.log -row 0 -column 0 -sticky ew
|
||||
grid .login.m.cancel -row 0 -column 1 -sticky ew
|
||||
label .login.lo -text "Login:"
|
||||
entry .login.loge
|
||||
grid .login.lo -row 0 -column 0
|
||||
grid .login.loge -row 0 -column 1
|
||||
label .login.pa -text "Pass:"
|
||||
entry .login.pase -show "*"
|
||||
grid .login.pa -row 1 -column 0
|
||||
grid .login.pase -row 1 -column 1
|
||||
button .login.log -text "Login" -command {login [.login.loge get] [.login.pase get] ; grab release .login; destroy .login}
|
||||
button .login.cancel -text "Cancel" -command {grab release .login; destroy .login}
|
||||
grid .login.log -row 2 -column 0 -sticky ew
|
||||
grid .login.cancel -row 2 -column 1 -sticky ew
|
||||
grab set .login
|
||||
focus .login
|
||||
wm resizable .login 0 0
|
||||
wm title .login "Login"
|
||||
}
|
||||
set prj .mbar.project
|
||||
set phdm .mbar.phoned
|
||||
#frame
|
||||
frame .m -borderwidth 2 -width 20c -height 10c
|
||||
grid .m -sticky wn -row 0 -column 0
|
||||
grid .m -sticky nsew -row 0 -column 0
|
||||
grid columnconfigure .m 0 -weight 1 -uniform 1
|
||||
grid columnconfigure .m 1 -weight 1 -uniform 1
|
||||
grid rowconfigure .m 0 -weight 1 -uniform 1
|
||||
grid rowconfigure .m 1 -weight 1 -uniform 1
|
||||
grid rowconfigure .m 2 -weight 1 -uniform 1
|
||||
#menu
|
||||
menu .mbar -tearoff no
|
||||
menu $prj -tearoff no
|
||||
@ -56,8 +65,35 @@ menu $prj -tearoff no
|
||||
$prj add command -label "Quit" -command "exit"
|
||||
menu $phdm -tearoff no
|
||||
.mbar add cascade -label "PhoneD" -menu $phdm -underline 1
|
||||
$phdm add command -label "Login"
|
||||
$phdm add command -label "Login" -command logindlg
|
||||
menu .mbar.help -tearoff no
|
||||
.mbar add cascade -label "Help" -menu .mbar.help -underline 1
|
||||
.mbar.help add command -label "About Xfone"
|
||||
. configure -menu .mbar
|
||||
|
||||
|
||||
# main widgets
|
||||
set w .m.calls
|
||||
button .m.calls -text "Calls"
|
||||
$w configure -font "[font actual [$w cget -font]] -size 20"
|
||||
set w .m.msgs
|
||||
button .m.msgs -text "Messages"
|
||||
$w configure -font "[font actual [$w cget -font]] -size 20"
|
||||
set w .m.admin
|
||||
button .m.admin -text "Administration"
|
||||
$w configure -font "[font actual [$w cget -font]] -size 20"
|
||||
set w .m.dialer
|
||||
button .m.dialer -text Dialer
|
||||
$w configure -font "[font actual [$w cget -font]] -size 20"
|
||||
set w .m.utility
|
||||
button .m.utility -text "Utilities"
|
||||
$w configure -font "[font actual [$w cget -font]] -size 20"
|
||||
set w .m.logoi
|
||||
button .m.logoi -text Login
|
||||
$w configure -font "[font actual [$w cget -font]] -size 20"
|
||||
grid propagate .m false
|
||||
grid .m.calls .m.dialer -row 0 -sticky nesw
|
||||
grid .m.msgs .m.utility -row 1 -sticky nesw
|
||||
grid .m.admin .m.logoi -row 2 -sticky nesw
|
||||
wm resizable . 0 0
|
||||
wm title . "Xfone"
|
||||
|
@ -27,22 +27,40 @@
|
||||
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
# SUCH DAMAGE.
|
||||
#
|
||||
# $Amigan: phoned/xfone/phoned.tcl,v 1.4 2005/06/26 16:51:00 dcp1990 Exp $
|
||||
# $Amigan: phoned/xfone/phoned.tcl,v 1.5 2005/06/27 00:08:47 dcp1990 Exp $
|
||||
load ./udom.so
|
||||
|
||||
proc openSock {sfile} {
|
||||
set os [udom -file $sfile]
|
||||
fconfigure $os -buffering line
|
||||
fconfigure $os -buffering line -blocking false
|
||||
fileevent $os readable [list handleme $os]
|
||||
return $os
|
||||
}
|
||||
|
||||
proc handleme {fh} {
|
||||
parseres [gets $fh]
|
||||
}
|
||||
proc parseres {res} {
|
||||
# 501 = success, 514 = failure
|
||||
# tk_messageBox -message $res -type ok -title Result
|
||||
if {[regexp -- "^(\[0-9\]{3}) (\[A-Z\]+): (.*)$" $res a code msg english]} {
|
||||
switch $code {
|
||||
501 {
|
||||
tk_messageBox -message "Logged in!" -type ok -title "Login"
|
||||
}
|
||||
514 {
|
||||
set res [tk_messageBox -message "Login failure." -type retrycancel]
|
||||
switch $res { retry {logindlg} cancel {return} }
|
||||
}
|
||||
default {
|
||||
tk_messageBox -message [list Result was $res] -type ok -title "Result"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
proc login {user pass} {
|
||||
global sh
|
||||
puts $sh {login $user $pass}
|
||||
parseres [gets $sh]
|
||||
puts $sh [list login $user $pass]
|
||||
}
|
||||
|
||||
set $sh [openSock $sockfile]
|
||||
set sh [openSock $sockfile]
|
||||
|
@ -1,218 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2005, Dan Ponte
|
||||
*
|
||||
* sockstuff.c - Implement SOCK_STREAM AF_LOCAL sockets for Tcl
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
/* $Amigan: phoned/xfone/sockstuff.c,v 1.5 2005/06/26 16:22:54 dcp1990 Exp $ */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <signal.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/select.h>
|
||||
/* network stuff */
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/un.h>
|
||||
#include <errno.h>
|
||||
#include <tcl.h>
|
||||
#define mseterr(m) Udom_Error(interp, m)
|
||||
|
||||
#define CMD_ARGS (ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj *CONST objv[])
|
||||
typedef struct cdta {
|
||||
int fd;
|
||||
Tcl_Channel channel;
|
||||
} Udom_Cdata_t;
|
||||
|
||||
Udom_Error(interp, msg)
|
||||
Tcl_Interp *interp;
|
||||
char *msg;
|
||||
{
|
||||
Tcl_SetResult(interp, msg, TCL_STATIC);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
int Udom_Close(cdata, interp)
|
||||
ClientData cdata;
|
||||
Tcl_Interp *interp;
|
||||
{
|
||||
int rc;
|
||||
Udom_Cdata_t *idata = (Udom_Cdata_t*)cdata;
|
||||
rc = close(idata->fd);
|
||||
ckfree((char*)idata);
|
||||
return rc == 0 ? rc : errno;
|
||||
}
|
||||
int Udom_Input(cdata, buf, sizebuf, errorptr)
|
||||
ClientData cdata;
|
||||
char *buf;
|
||||
int sizebuf;
|
||||
int *errorptr;
|
||||
{
|
||||
int ec;
|
||||
Udom_Cdata_t *idata = (Udom_Cdata_t*)cdata;
|
||||
ec = read(idata->fd, buf, sizebuf);
|
||||
if(ec == -1) {
|
||||
*errorptr = errno;
|
||||
return -1;
|
||||
} else {
|
||||
return ec;
|
||||
}
|
||||
}
|
||||
|
||||
int Udom_Output(cdata, buf, towrite, ecptr)
|
||||
ClientData cdata;
|
||||
CONST char *buf;
|
||||
int towrite;
|
||||
int *ecptr;
|
||||
{
|
||||
int rc;
|
||||
Udom_Cdata_t *idata = (Udom_Cdata_t*)cdata;
|
||||
rc = write(idata->fd, buf, towrite);
|
||||
if(rc == -1) {
|
||||
*ecptr = errno;
|
||||
return -1;
|
||||
} else {
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
void Udom_Watch(cdata, mask)
|
||||
ClientData cdata;
|
||||
int mask;
|
||||
{
|
||||
Udom_Cdata_t *idata = (Udom_Cdata_t*)cdata;
|
||||
if(mask) {
|
||||
Tcl_CreateFileHandler(idata->fd, mask,
|
||||
(Tcl_FileProc*)Tcl_NotifyChannel,
|
||||
(ClientData)idata->channel);
|
||||
} else {
|
||||
Tcl_DeleteFileHandler(idata->fd);
|
||||
}
|
||||
}
|
||||
|
||||
int Udom_GetHandle(cdata, dir, handptr)
|
||||
ClientData cdata;
|
||||
int dir;
|
||||
ClientData *handptr;
|
||||
{
|
||||
Udom_Cdata_t *idata = (Udom_Cdata_t*)cdata;
|
||||
*handptr = (ClientData)idata->fd;
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/* write watcher */
|
||||
Tcl_ChannelType Udom_ChanType = {
|
||||
"udomain",
|
||||
TCL_CHANNEL_VERSION_3,
|
||||
&Udom_Close,
|
||||
&Udom_Input,
|
||||
&Udom_Output,
|
||||
NULL, /* seek */
|
||||
NULL, /* set and getoption, might do later */
|
||||
NULL,
|
||||
&Udom_Watch,
|
||||
&Udom_GetHandle,
|
||||
NULL, /* close2proc */
|
||||
NULL, /* block mode */
|
||||
NULL, /* flush */
|
||||
NULL, /* handler */
|
||||
NULL /* wideseek */
|
||||
};
|
||||
|
||||
|
||||
|
||||
Tcl_Channel Udom_CreateChannel(interp, sockfile, mask)
|
||||
Tcl_Interp *interp;
|
||||
CONST char *sockfile;
|
||||
int mask;
|
||||
{
|
||||
Udom_Cdata_t *cdt;
|
||||
int s;
|
||||
char chname[25];
|
||||
struct sockaddr_un them;
|
||||
cdt = (Udom_Cdata_t*)ckalloc(sizeof(Udom_Cdata_t));
|
||||
s = socket(AF_LOCAL, SOCK_STREAM, 0);
|
||||
strcpy(them.sun_path, sockfile);
|
||||
them.sun_family = AF_LOCAL;
|
||||
if(connect(s, (struct sockaddr *)&them, 1 + strlen(them.sun_path) + sizeof(them.sun_family)) == -1) {
|
||||
ckfree((char*)cdt);
|
||||
Tcl_SetResult(interp, strerror(errno), TCL_STATIC);
|
||||
return NULL;
|
||||
}
|
||||
cdt->fd = s;
|
||||
snprintf(chname, 24, "udom%d", cdt->fd);
|
||||
cdt->channel = Tcl_CreateChannel(&Udom_ChanType, chname, cdt, mask);
|
||||
return cdt->channel;
|
||||
}
|
||||
int Udom_Cmd (cdata, interp, argc, argv)
|
||||
ClientData cdata;
|
||||
Tcl_Interp *interp;
|
||||
int argc;
|
||||
Tcl_Obj *const argv[];
|
||||
{
|
||||
char *arg;
|
||||
char *sfl = NULL;
|
||||
int a, optind;
|
||||
Tcl_Channel res;
|
||||
const char *udomopt[] = {
|
||||
"-file", (char*)NULL
|
||||
};
|
||||
enum udomopt {
|
||||
UDOM_FILE
|
||||
};
|
||||
for(a = 1; a < argc; a++) {
|
||||
arg = Tcl_GetString(argv[a]);
|
||||
if(*arg != '-') break;
|
||||
if(Tcl_GetIndexFromObj(interp, argv[a], udomopt, "option", TCL_EXACT, &optind)
|
||||
!= TCL_OK) return mseterr("Getindex");
|
||||
switch((enum udomopt)optind) {
|
||||
case UDOM_FILE:
|
||||
if(a >= argc) return mseterr("needs file!");
|
||||
sfl = Tcl_GetString(argv[a + 1]);
|
||||
break;
|
||||
default:
|
||||
Tcl_Panic("udom: bad optind to opts");
|
||||
}
|
||||
}
|
||||
if(sfl == NULL) return mseterr("file argument REQUIRED.");
|
||||
res = Udom_CreateChannel(interp, sfl, TCL_READABLE | TCL_WRITABLE);
|
||||
if(res == NULL) return TCL_ERROR;
|
||||
Tcl_RegisterChannel(interp, res);
|
||||
Tcl_ResetResult(interp);
|
||||
Tcl_AppendResult(interp, Tcl_GetChannelName(res), (char*)NULL);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
int Udom_Init(interp)
|
||||
Tcl_Interp *interp;
|
||||
{
|
||||
Tcl_CreateObjCommand(interp, "udom", Udom_Cmd, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
return TCL_OK;
|
||||
}
|
Loading…
Reference in New Issue
Block a user