aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2010-05-14 00:51:08 +0200
committerAris Adamantiadis <aris@0xbadc0de.be>2010-05-14 00:51:08 +0200
commitb23b3f1d9951df3ea7cc074de40db04bdf0d3a1c (patch)
treed4fe8f4c4aa71c6cebe7d1d92dc25ea145d98cd1 /examples
parent46b249f5ce552bba2e0a170cb0b8052b1419924b (diff)
downloadlibssh-b23b3f1d9951df3ea7cc074de40db04bdf0d3a1c.tar.gz
libssh-b23b3f1d9951df3ea7cc074de40db04bdf0d3a1c.tar.xz
libssh-b23b3f1d9951df3ea7cc074de40db04bdf0d3a1c.zip
Sanitize libssh namespace + legacy wrappers
Diffstat (limited to 'examples')
-rw-r--r--examples/exec.c18
-rw-r--r--examples/sample.c82
-rw-r--r--examples/scp_download.c14
3 files changed, 57 insertions, 57 deletions
diff --git a/examples/exec.c b/examples/exec.c
index bff49fd..1f6fa29 100644
--- a/examples/exec.c
+++ b/examples/exec.c
@@ -15,41 +15,41 @@ int main(void) {
return 1;
}
- channel = channel_new(session);;
+ channel = ssh_channel_new(session);;
if (channel == NULL) {
ssh_disconnect(session);
return 1;
}
- rc = channel_open_session(channel);
+ rc = ssh_channel_open_session(channel);
if (rc < 0) {
- channel_close(channel);
+ ssh_channel_close(channel);
ssh_disconnect(session);
return 1;
}
- rc = channel_request_exec(channel, "ps aux");
+ rc = ssh_channel_request_exec(channel, "ps aux");
if (rc < 0) {
- channel_close(channel);
+ ssh_channel_close(channel);
ssh_disconnect(session);
return 1;
}
- while ((rc = channel_read(channel, buffer, sizeof(buffer), 0)) > 0) {
+ while ((rc = ssh_channel_read(channel, buffer, sizeof(buffer), 0)) > 0) {
if (fwrite(buffer, 1, rc, stdout) != (unsigned int) rc) {
return 1;
}
}
if (rc < 0) {
- channel_close(channel);
+ ssh_channel_close(channel);
ssh_disconnect(session);
return 1;
}
- channel_send_eof(channel);
- channel_close(channel);
+ ssh_channel_send_eof(channel);
+ ssh_channel_close(channel);
ssh_disconnect(session);
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;
}
diff --git a/examples/scp_download.c b/examples/scp_download.c
index b178757..b6f16af 100644
--- a/examples/scp_download.c
+++ b/examples/scp_download.c
@@ -56,29 +56,29 @@ static int opts(int argc, char **argv){
}
static void create_files(ssh_session session){
- ssh_channel channel=channel_new(session);
+ ssh_channel channel=ssh_channel_new(session);
char buffer[1];
if(channel == NULL){
fprintf(stderr,"Error creating channel: %s\n",ssh_get_error(session));
exit(EXIT_FAILURE);
}
- if(channel_open_session(channel) != SSH_OK){
+ if(ssh_channel_open_session(channel) != SSH_OK){
fprintf(stderr,"Error creating channel: %s\n",ssh_get_error(session));
exit(EXIT_FAILURE);
}
- if(channel_request_exec(channel,createcommand) != SSH_OK){
+ if(ssh_channel_request_exec(channel,createcommand) != SSH_OK){
fprintf(stderr,"Error executing command: %s\n",ssh_get_error(session));
exit(EXIT_FAILURE);
}
- while(!channel_is_eof(channel)){
- channel_read(channel,buffer,1,1);
+ while(!ssh_channel_is_eof(channel)){
+ ssh_channel_read(channel,buffer,1,1);
if (write(1,buffer,1) < 0) {
fprintf(stderr, "Error writing to buffer\n");
return;
}
}
- channel_close(channel);
- channel_free(channel);
+ ssh_channel_close(channel);
+ ssh_channel_free(channel);
}