static void command_dispatcher(const linkaddr_t *sender) { char *msg; int len; struct deluge_msg_profile *profile; msg = packetbuf_dataptr(); len = packetbuf_datalen(); if(len < 1) return; switch(msg[0]) { case DELUGE_CMD_SUMMARY: if(len >= sizeof(struct deluge_msg_summary)) handle_summary((struct deluge_msg_summary *)msg, sender); break; case DELUGE_CMD_REQUEST: if(len >= sizeof(struct deluge_msg_request)) handle_request((struct deluge_msg_request *)msg); break; case DELUGE_CMD_PACKET: if(len >= sizeof(struct deluge_msg_packet)) handle_packet((struct deluge_msg_packet *)msg); break; case DELUGE_CMD_PROFILE: profile = (struct deluge_msg_profile *)msg; if(len >= sizeof(*profile) && len >= sizeof(*profile) + profile->npages * profile->version_vector[0]) handle_profile((struct deluge_msg_profile *)msg); break; default: PRINTF("Incoming packet with unknown command: %d\n", msg[0]); } }
int main( int argc, char ** argv) { char *tmp; char *profile_pathname = 0; BOOLEAN using_stdin = false; exit_values_ty exit_status; #if defined (HAVE_SETLOCALE) setlocale(LC_ALL, ""); #endif bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); #if defined (_WIN32) && !defined (__CYGWIN__) /* wildcard expansion of commandline arguments, see wildexp.c */ extern void wildexp(int *argc, char ***argv); wildexp(&argc, &argv); #endif /* defined (_WIN32) && !defined (__CYGWIN__) */ #ifdef DEBUG if (debug) { debug_init(); } #endif /* 'size_t', 'wchar_t' and 'ptrdiff_t' are guarenteed to be * available in ANSI C. * * These pointers will be freed in cleanup_user_specials(). */ tmp = xmalloc(7); memcpy(tmp, "size_t", 7); addkey(tmp, rw_decl); tmp = xmalloc(8); memcpy(tmp, "wchar_t", 8); addkey(tmp, rw_decl); tmp = xmalloc(10); memcpy(tmp, "ptrdiff_t", 10); addkey(tmp, rw_decl); init_parser (); initialize_backups (); exit_status = total_success; input_files = 0; in_file_names = (char **) xmalloc(max_input_files * sizeof (char *)); set_defaults(); profile_pathname = handle_profile(argc, argv); exit_status = process_args(argc, argv, &using_stdin); if (exit_status == total_success) { if (settings.verbose && profile_pathname) { fprintf (stderr, _("Read profile %s\n"), profile_pathname); } set_defaults_after(); exit_status = indent_all(using_stdin); } if (profile_pathname) xfree(profile_pathname); xfree(in_file_names); uninit_parser(); cleanup_user_specials(); return exit_status; }