aboutsummaryrefslogtreecommitdiff
path: root/examples/sample.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/sample.c')
-rw-r--r--examples/sample.c82
1 files changed, 41 insertions, 41 deletions
diff --git a/examples/sample.c b/examples/sample.c
index b7f6074..8f86f56 100644
--- a/examples/sample.c
+++ b/examples/sample.c
@@ -173,7 +173,7 @@ static void setsignal(void){
static void sizechanged(void){
struct winsize win = { 0, 0, 0, 0 };
ioctl(1, TIOCGWINSZ, &win);
- channel_change_pty_size(chan,win.ws_col, win.ws_row);
+ ssh_channel_change_pty_size(chan,win.ws_col, win.ws_row);
// printf("Changed pty size\n");
setsignal();
}
@@ -196,7 +196,7 @@ static void select_loop(ssh_session session,ssh_channel channel){
fd_set fds;
struct timeval timeout;
char buffer[4096];
- ssh_buffer readbuf=buffer_new();
+ ssh_buffer readbuf=ssh_buffer_new();
ssh_channel channels[2];
int lus;
int eof=0;
@@ -224,10 +224,10 @@ static void select_loop(ssh_session session,ssh_channel channel){
if(FD_ISSET(0,&fds)){
lus=read(0,buffer,sizeof(buffer));
if(lus)
- channel_write(channel,buffer,lus);
+ ssh_channel_write(channel,buffer,lus);
else {
eof=1;
- channel_send_eof(channel);
+ ssh_channel_send_eof(channel);
}
}
if(FD_ISSET(ssh_get_fd(session),&fds)){
@@ -235,22 +235,22 @@ static void select_loop(ssh_session session,ssh_channel channel){
}
channels[0]=channel; // set the first channel we want to read from
channels[1]=NULL;
- ret=channel_select(channels,NULL,NULL,NULL); // no specific timeout - just poll
+ ret=ssh_channel_select(channels,NULL,NULL,NULL); // no specific timeout - just poll
if(signal_delayed)
sizechanged();
} while (ret==EINTR || ret==SSH_EINTR);
// we already looked for input from stdin. Now, we are looking for input from the channel
- if(channel && channel_is_closed(channel)){
- ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",channel_get_exit_status(channel));
+ if(channel && ssh_channel_is_closed(channel)){
+ ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",ssh_channel_get_exit_status(channel));
- channel_free(channel);
+ ssh_channel_free(channel);
channel=NULL;
channels[0]=NULL;
}
if(channels[0]){
- while(channel && channel_is_open(channel) && channel_poll(channel,0)>0){
+ while(channel && ssh_channel_is_open(channel) && ssh_channel_poll(channel,0)>0){
lus=channel_read_buffer(channel,readbuf,0,0);
if(lus==-1){
fprintf(stderr, "Error reading channel: %s\n",
@@ -259,17 +259,17 @@ static void select_loop(ssh_session session,ssh_channel channel){
}
if(lus==0){
ssh_log(session,SSH_LOG_RARE,"EOF received\n");
- ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",channel_get_exit_status(channel));
+ ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",ssh_channel_get_exit_status(channel));
- channel_free(channel);
+ ssh_channel_free(channel);
channel=channels[0]=NULL;
} else
- if (write(1,buffer_get(readbuf),lus) < 0) {
+ if (write(1,ssh_buffer_get_begin(readbuf),lus) < 0) {
fprintf(stderr, "Error writing to buffer\n");
return;
}
}
- while(channel && channel_is_open(channel) && channel_poll(channel,1)>0){ /* stderr */
+ while(channel && ssh_channel_is_open(channel) && ssh_channel_poll(channel,1)>0){ /* stderr */
lus=channel_read_buffer(channel,readbuf,0,1);
if(lus==-1){
fprintf(stderr, "Error reading channel: %s\n",
@@ -278,22 +278,22 @@ static void select_loop(ssh_session session,ssh_channel channel){
}
if(lus==0){
ssh_log(session,SSH_LOG_RARE,"EOF received\n");
- ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",channel_get_exit_status(channel));
- channel_free(channel);
+ ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",ssh_channel_get_exit_status(channel));
+ ssh_channel_free(channel);
channel=channels[0]=NULL;
} else
- if (write(2,buffer_get(readbuf),lus) < 0) {
+ if (write(2,ssh_buffer_get_begin(readbuf),lus) < 0) {
fprintf(stderr, "Error writing to buffer\n");
return;
}
}
}
- if(channel && channel_is_closed(channel)){
- channel_free(channel);
+ if(channel && ssh_channel_is_closed(channel)){
+ ssh_channel_free(channel);
channel=NULL;
}
}
- buffer_free(readbuf);
+ ssh_buffer_free(readbuf);
}
#else /* CHANNEL_SELECT */
@@ -328,22 +328,22 @@ static void select_loop(ssh_session session,ssh_channel channel){
if(FD_ISSET(0,&fds)){
lus=read(0,buffer,sizeof(buffer));
if(lus)
- channel_write(channel,buffer,lus);
+ ssh_channel_write(channel,buffer,lus);
else {
eof=1;
- channel_send_eof(channel);
+ ssh_channel_send_eof(channel);
}
}
- if(channel && channel_is_closed(channel)){
- ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",channel_get_exit_status(channel));
+ if(channel && ssh_channel_is_closed(channel)){
+ ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",ssh_channel_get_exit_status(channel));
- channel_free(channel);
+ ssh_channel_free(channel);
channel=NULL;
channels[0]=NULL;
}
if(outchannels[0]){
- while(channel && channel_is_open(channel) && channel_poll(channel,0)!=0){
- lus=channel_read(channel,buffer,sizeof(buffer),0);
+ while(channel && ssh_channel_is_open(channel) && ssh_channel_poll(channel,0)!=0){
+ lus=ssh_channel_read(channel,buffer,sizeof(buffer),0);
if(lus==-1){
fprintf(stderr, "Error reading channel: %s\n",
ssh_get_error(session));
@@ -351,9 +351,9 @@ static void select_loop(ssh_session session,ssh_channel channel){
}
if(lus==0){
ssh_log(session,SSH_LOG_RARE,"EOF received\n");
- ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",channel_get_exit_status(channel));
+ ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",ssh_channel_get_exit_status(channel));
- channel_free(channel);
+ ssh_channel_free(channel);
channel=channels[0]=NULL;
} else
if (write(1,buffer,lus) < 0) {
@@ -361,8 +361,8 @@ static void select_loop(ssh_session session,ssh_channel channel){
return;
}
}
- while(channel && channel_is_open(channel) && channel_poll(channel,1)!=0){ /* stderr */
- lus=channel_read(channel,buffer,sizeof(buffer),1);
+ while(channel && ssh_channel_is_open(channel) && ssh_channel_poll(channel,1)!=0){ /* stderr */
+ lus=ssh_channel_read(channel,buffer,sizeof(buffer),1);
if(lus==-1){
fprintf(stderr, "Error reading channel: %s\n",
ssh_get_error(session));
@@ -370,8 +370,8 @@ static void select_loop(ssh_session session,ssh_channel channel){
}
if(lus==0){
ssh_log(session,SSH_LOG_RARE,"EOF received\n");
- ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",channel_get_exit_status(channel));
- channel_free(channel);
+ ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",ssh_channel_get_exit_status(channel));
+ ssh_channel_free(channel);
channel=channels[0]=NULL;
} else
if (write(2,buffer,lus) < 0) {
@@ -380,8 +380,8 @@ static void select_loop(ssh_session session,ssh_channel channel){
}
}
}
- if(channel && channel_is_closed(channel)){
- channel_free(channel);
+ if(channel && ssh_channel_is_closed(channel)){
+ ssh_channel_free(channel);
channel=NULL;
}
} while (ret==EINTR || ret==SSH_EINTR);
@@ -395,21 +395,21 @@ static void shell(ssh_session session){
ssh_channel channel;
struct termios terminal_local;
int interactive=isatty(0);
- channel = channel_new(session);
+ channel = ssh_channel_new(session);
if(interactive){
tcgetattr(0,&terminal_local);
memcpy(&terminal,&terminal_local,sizeof(struct termios));
}
- if(channel_open_session(channel)){
+ if(ssh_channel_open_session(channel)){
printf("error opening channel : %s\n",ssh_get_error(session));
return;
}
chan=channel;
if(interactive){
- channel_request_pty(channel);
+ ssh_channel_request_pty(channel);
sizechanged();
}
- if(channel_request_shell(channel)){
+ if(ssh_channel_request_shell(channel)){
printf("Requesting shell : %s\n",ssh_get_error(session));
return;
}
@@ -430,9 +430,9 @@ static void batch_shell(ssh_session session){
int i,s=0;
for(i=0;i<MAXCMD && cmds[i];++i)
s+=snprintf(buffer+s,sizeof(buffer)-s,"%s ",cmds[i]);
- channel=channel_new(session);
- channel_open_session(channel);
- if(channel_request_exec(channel,buffer)){
+ channel=ssh_channel_new(session);
+ ssh_channel_open_session(channel);
+ if(ssh_channel_request_exec(channel,buffer)){
printf("error executing \"%s\" : %s\n",buffer,ssh_get_error(session));
return;
}