88 lines
2.7 KiB
C
88 lines
2.7 KiB
C
/* *****************************************************************************
|
|
* usage/mcs/list.c -- list the elements on the main memory.
|
|
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
|
*
|
|
* This file is part of libp7.
|
|
* libp7 is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation; either version 3.0 of the License,
|
|
* or (at your option) any later version.
|
|
*
|
|
* libp7 is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
* See the GNU Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
* along with libp7; if not, see <http://www.gnu.org/licenses/>.
|
|
* ************************************************************************** */
|
|
#include <libp7/internals.h>
|
|
|
|
/**
|
|
* p7_mcs_list:
|
|
* List files on the main memory.
|
|
*
|
|
* @arg handle the libp7 handle.
|
|
* @arg callback the callback.
|
|
* @arg cookie something to send to the callback.
|
|
* @return if it worked.
|
|
*/
|
|
|
|
p7_define_ufunc(p7_mcs_list, p7_attrs_mcs_list,
|
|
p7_handle_t *handle, p7_mcslist_t *callback, void *cookie)
|
|
{
|
|
int err;
|
|
|
|
/* make checks */
|
|
chk_handle(handle);
|
|
chk_seven(handle);
|
|
chk_active(handle);
|
|
|
|
/* send command packet */
|
|
log_info("sending file transfer request");
|
|
if ((err = p7_seven_send_cmdmcs_reqallinfo(handle))) {
|
|
log_fatal("couldn't send transfer request");
|
|
return (err);
|
|
} else if (response.p7_seven_packet_type != p7_seven_type_ack) {
|
|
log_fatal("didn't receive ack...");
|
|
return (p7_error_unknown);
|
|
}
|
|
|
|
/* swap roles */
|
|
log_info("sending roleswap");
|
|
if ((err = p7_seven_send_swp(handle))) {
|
|
log_fatal("couldn't swap roles");
|
|
return (err);
|
|
}
|
|
|
|
/* - Note: we are now in passive mode - */
|
|
g1m_mcshead_t head;
|
|
while (1) switch (response.p7_seven_packet_type) {
|
|
/* if answer is roleswap, we are done */
|
|
case p7_seven_type_swp: return (0);
|
|
|
|
/* if it is command, should be another file info */
|
|
case p7_seven_type_cmd:
|
|
/* check args */
|
|
if (g1m_decode_mcsfile_head(&head, response.p7_seven_packet_mcstype,
|
|
(unsigned char*)response.p7_seven_packet_args[2],
|
|
(unsigned char*)response.p7_seven_packet_args[0],
|
|
(unsigned char*)response.p7_seven_packet_args[1],
|
|
response.p7_seven_packet_filesize))
|
|
continue;
|
|
(*callback)(cookie, &head);
|
|
|
|
/* send ack to continue */
|
|
log_info("sending ack to continue");
|
|
if ((err = p7_seven_send_ack(handle, 1))) {
|
|
log_fatal("unable to send ack");
|
|
return (err);
|
|
}
|
|
break;
|
|
|
|
default: /* wtf? */
|
|
log_fatal("wtf?!");
|
|
return (p7_error_unknown);
|
|
}
|
|
}
|