inline int avp_handle_recv_win_size( struct tunnel *t, struct buffer *buf ) { //struct bit16_ptr *ptr; struct avp_hdr *hdr = (struct avp_hdr *) buf->current; UNUSED_ARGUMENT(t); if( !IS_M_SET(hdr->head_node) ) { #ifdef DEBUG_AVP msg_log( LEVEL_ERR, "%s: M bit not set for msg-type-avp which is required!\n", __func__ ); #endif /* DEBUG_AVP */ return -1; } if( GET_AVP_LEN(hdr->head_node) != 8 ) { #ifdef DEBUG_AVP msg_log( LEVEL_ERR, "%s: %x caps-type-avp is not 10\n", __func__, hdr->attribute_type); #endif /* DEBUG_AVP */ return -1; } buf->current += 8; return 0; }
inline int avp_handle_hostname( struct tunnel *t, struct buffer *buf ) { //struct bit16_ptr *ptr; struct avp_hdr *hdr = (struct avp_hdr *) buf->current; UNUSED_ARGUMENT(t); if( !IS_M_SET(hdr->head_node) ) { #ifdef DEBUG_AVP msg_log( LEVEL_ERR, "%s: M bit not set for msg-type-avp which is required!\n", __func__ ); #endif /* DEBUG_AVP */ return -1; } if( IS_H_SET(hdr->head_node) ) { #ifdef DEBUG_AVP msg_log( LEVEL_ERR, "%s: H bit cannot be set for %x type avp!\n", __func__, hdr->attribute_type ); #endif /* DEBUG_AVP */ return -1; } buf->current += GET_AVP_LEN(hdr->head_node); return 0; }
/* print the packet in hex and readable char for debugging */ void print_packet( const char *buf, int len ) { __u8 *end = (__u8 *)buf + len; __u8 *p8 = (__u8 *) buf; /* hex */ while( p8 < end ) { msg_log( L_NOR, "%.2x ", *p8++ ); } msg_log( L_NOR, "\n" ); p8 = (__u8 *) buf; /* readable char */ while( p8 < end ) { if( isprint(*p8) ) { msg_log( L_NOR, "%c", *p8++ ); } else { msg_log( L_NOR, "." ); p8++; } } msg_log( L_NOR, "\n" ); }
inline int avp_handle_ass_sid( struct tunnel *t, struct buffer *buf ) { struct bit16_ptr *ptr; struct avp_hdr *hdr = (struct avp_hdr *) buf->current; if( !IS_M_SET(hdr->head_node) ) { #ifdef DEBUG_AVP msg_log( LEVEL_ERR, "%s: M bit not set for msg-type-avp which is required!\n", __func__ ); #endif /* DEBUG_AVP */ return -1; } if( GET_AVP_LEN(hdr->head_node) != 8 ) { #ifdef DEBUG_AVP msg_log( LEVEL_ERR, "%s: %x ass_sid-type-avp is not 10\n", __func__, hdr->attribute_type); #endif /* DEBUG_AVP */ return -1; } ptr = (struct bit16_ptr *) buf->current; ptr->b3 = ntohs( ptr->b3 ); t->call.peer_sid = ptr->b3; buf->current += 8; return 0; }
inline int avp_handle_frame_caps( struct tunnel *t, struct buffer *buf ) { //_u32 *ptr; struct avp_hdr *hdr = (struct avp_hdr *) buf->current; UNUSED_ARGUMENT(t); if( !IS_M_SET(hdr->head_node) ) { #ifdef DEBUG_AVP msg_log( LEVEL_ERR, "%s: M bit not set for msg-type-avp which is required!\n", __func__ ); #endif /* DEBUG_AVP */ return -1; } if( GET_AVP_LEN(hdr->head_node) != 10 ) { #ifdef DEBUG_AVP msg_log( LEVEL_ERR, "%s: frame_caps-type-avp is not 10\n", __func__ ); #endif /* DEBUG_AVP */ return -1; } // ptr = ( _u8 * )&hdr->attribute_type + 1; // t->call.peer_frame_cap = *ptr; buf->current += 10; return 0; }
extern int network_tcp_listen(const char *nodename, const char *servname, int backlog) { int sd = 0; int reuseaddr = 0; int status = 0; struct addrinfo hints, *ai, *aptr; /* init hints address structure */ memset(&hints, 0, sizeof(hints)); hints.ai_flags = AI_PASSIVE; hints.ai_family = AF_UNSPEC; /* works with both, IPv4 and IPv6 */ hints.ai_socktype = SOCK_STREAM; /* the function's called _tcp_... - ain't it? */ /* determine address structure for passive socket */ if (0 == (status = getaddrinfo(nodename, servname, &hints, &ai))) { for (aptr = ai; NULL != aptr; aptr = aptr->ai_next) { if (0 > (sd = socket(aptr->ai_family, aptr->ai_socktype, aptr->ai_protocol))) continue; /* in case of error try next address structure */ /* try to avoid "address already in use" errors */ reuseaddr = 1; setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, sizeof(int)); /* finally, bind socket */ if (0 == (bind(sd, aptr->ai_addr, aptr->ai_addrlen))) /* convert socket from active to passive */ if (0 <= (listen(sd, backlog))) break; /* if everything's fine, get out of the loop */ /* in case of error, close the socket */ close(sd); } freeaddrinfo(ai); /* check for errors */ if (NULL == aptr) { msg_log(LOG_ERR, "Can't listen on port %s: %s\n", servname, strerror(errno)); return(-1); } } else { msg_log(LOG_ERR, "getaddrinfo() failed: %s\n", gai_strerror(status)); return(-1); } return(sd); }
/* Show Screen of Game. */ void show_game(void) { int level; register int i, j; char direction[2]; printf("\n\t\t%s\n\t\t\t%s\n", game_name, author); //if(config.snake_direction == 0) direction if(config.game_level == N3) level = 3; else if(config.game_level == N2) level = 2; else level = 1; printf("\n\t\t\tLevel: %d | Points: %d\n\n", level, config.points_user); for(i = 0; i < ROW; i++) { printf("\t\t%c%c%c%c%c", M, M, M, M, M); for(j = 0; j < COLUMN; j++) printf(" %c",map[i][j]); printf("\n"); } msg_log(config.log); printf("\t\tApple Count: %d / Snake Direction: %s\n", config.count, direct_msg()); printf("\n\t\tPlease access: http://GCoders.wordpress.com\n"); }
/* ======================================== * void create_mesh(obj_file* objdata, meshdata* mesh) * ======================================== * Parses the vertex and face data for a given object file * and fills out a meshdata struct. */ void create_mesh(obj_file* objdata, meshdata* mesh) { if(mesh == NULL || objdata == NULL) { msg_log(LOG_ERROR, "create_mesh: Bad parameters!"); } memset(mesh, 0, sizeof(meshdata)); parse_faces(&objdata->faces, mesh); }
extern int network_tcp_connect(const char *nodename, const char *servname) { int sd = 0; int status = 0; struct addrinfo hints, *ai, *aptr; /* init hints address structure */ memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; /* works with both, IPv4 and IPv6 */ hints.ai_socktype = SOCK_STREAM; /* the function's called _tcp_... - ain't it? */ /* determine address structure for active socket */ if (0 == (status = getaddrinfo(nodename, servname, &hints, &ai))) { for (aptr = ai; NULL != aptr; aptr = aptr->ai_next) { if (0 > (sd = socket(aptr->ai_family, aptr->ai_socktype, aptr->ai_protocol))) continue; /* in case of error try next address structure */ /* connect socket to socket address */ if (0 > (connect(sd, aptr->ai_addr, aptr->ai_addrlen))) { close(sd); continue; /* in case of error try next address structure */ } break; /* if everything's fine, get out of the loop */ } freeaddrinfo(ai); /* check for errors */ if (NULL == aptr) { msg_log(LOG_ERR, "Cannot connect to %s, port %s: %s\n", nodename, servname, strerror(errno)); return(-1); } } else { msg_log(LOG_ERR, "getaddrinfo() failed: %s\n", gai_strerror(status)); return(-1); } return(sd); }
/** * This callback is called when an incomming message from the serial line is * received. The message will be forwarded to the extOnIncommingMsg() handler * of class RouteConnection. * * @param[in] message Received message. The message is only valid * during the lifetime of this function. */ void RConnSerial::OnIncommingMessage(msg_t* message) { log_msg(LOG_VERBOSE1, "%6s --> message received", this->GetName()); msg_log("SERIALRECV", *message); if (this->extOnIncommingMsg != NULL) { this->extOnIncommingMsg(message, this, this->extOnIncommingMsgArg); } }
void cleanup(void) { msg_log(MSG_MESSAGE, "Cleanup...\n"); session_cleanup(); dish_file_state_cleanup(); midi_stop(); driver_stop(); patch_shutdown(); mixer_shutdown(); settings_write(); settings_free(); free_instance_name(); mod_src_destroy(); msg_log(MSG_MESSAGE, "Goodbye!\n"); exit(0); }
char* file_ops_hash_mkdir(const char* path, const char* parent) { char* hash = 0; char* hash_dir = 0; struct stat st; if (!path || !parent) return 0; if ((hash = file_ops_dir_to_hash(path))) { debug("hash:'%s' path:'%s'\n", hash, path); if ((hash_dir = file_ops_join_path(parent, hash))) { debug("hash dir path:'%s'\n", hash_dir); if (mkdir(hash_dir, 0777) == 0) { char* dfilename; FILE* dfile; if ((dfilename = file_ops_join_path(hash_dir, "pathinfo.txt"))) { if ((dfile = fopen(dfilename, "w"))) { debug("writing '%s' as path to pathinfo.txt\n", path); fprintf(dfile, "%s\n", path); fclose(dfile); } free(dfilename); } } else if (errno != EEXIST) { debug("failed to create hash dir\n");} if (stat(hash_dir, &st) == 0) { free(hash); return hash_dir; } free(hash_dir); } free(hash); } msg_log(MSG_ERROR, "failed to create hash dir in '%s' for '%s'\n", parent, path); return 0; }
/* * handle avp mesage */ int handle_avp( struct tunnel *t, struct buffer *buf ) { struct avp_hdr *hdr; if( t->tunnel_state == StopCCN && t->close_state == 2 ) { if( t->nr < buf->ns + 1 ) { t->nr = buf->ns + 1; } return -1; } for(;;) { if( buf->current >= buf->end ) { break; } avp_ntoh_hdr( buf ); hdr = (struct avp_hdr *) buf->current; if( hdr->attribute_type > 0x0027 ) { #ifdef DEBUG_AVP msg_log ( LEVEL_ERR, "%s: unknown avp type %x\n", __func__, hdr->attribute_type ); #endif /* DEBUG_AVP */ return -1; } if( avp_handler[hdr->attribute_type].handler( t, buf ) == -1 ) { t->close_state = 1; return -1; } } if( t->nr < buf->ns + 1 ) { t->nr = buf->ns + 1; } return 0; }
/* start timer in special interval */ int start_timer( double interval ) { struct itimerval itv; if( interval <= EPSINON ) { msg_log( L_ERR, "%s: timer interval is zero\n", __func__); return -1; } double2tv( &itv.it_interval, interval ); bcopy( &itv.it_interval, &itv.it_value, sizeof( struct timeval ) ); //msg_log( L_ERR, "%d.%d\n", sec, usec ); /* * start a ITIMER_REAL timer. * ITIMER_VIRTUAL and ITIMER_PROF timer is not update its value * when this process is not run by CPU, * and if we call resvmsg then CPU queue this process in block-state, * until packet come and change to running -state. * so ITIMER_VIRTUAL and ITIMER_PROF timer will not expire when we expected */ if( setitimer( ITIMER_REAL, &itv, NULL ) == -1 ) { msg_log( L_ERR, "%s: %s\n", __func__, strerror(errno) ); return -1; } return 0; }
char* file_ops_mkdir(const char* dir, const char* parent) { char* newdir = file_ops_join_path(parent, dir); if (newdir) { if (mkdir(newdir, 0777) == 0 || errno == EEXIST) return newdir; } msg_log(MSG_ERROR, "failed to create dir '%s' within '%s'\n", dir, parent); free(newdir); return 0; }
/* stop the timer */ int stop_timer() { struct itimerval itv; itv.it_interval.tv_sec = 0; itv.it_interval.tv_usec = 0; itv.it_value.tv_sec = 0; itv.it_value.tv_usec = 0; if( setitimer( ITIMER_REAL, &itv, NULL ) == -1 ) { msg_log( L_ERR, "%s: %s\n", __func__, strerror(errno) ); return -1; } return 0; }
inline int avp_handle_vendor_name( struct tunnel *t, struct buffer *buf ) { //struct bit16_ptr *ptr; struct avp_hdr *hdr = (struct avp_hdr *) buf->current; UNUSED_ARGUMENT(t); if( IS_M_SET(hdr->head_node) ) { #ifdef DEBUG_AVP msg_log( LEVEL_ERR, "%s: M bit cannot set for msg-type-avp!\n", __func__ ); #endif /* DEBUG_AVP */ return -1; } buf->current += GET_AVP_LEN(hdr->head_node); return 0; }
void parse_faces(obj_face* oface, meshdata* mesh) { obj_face* cur = oface; char* facedata; mesh->num_indx = 0; while(cur->next != NULL) { mesh->num_indx += num_inds(cur); cur = cur->next; } msg_log(LOG_INFO, "%d Triangle Indices", mesh->num_indx); mesh->indx = malloc(mesh->num_indx * sizeof(int)); cur = oface; /* while(cur->next != NULL) { facedata = cur->face; while(*facedata != '\n') { facedata++; } cur = cur->next; }*/ }
static void cb_cancel(void) { mixer_flush_preview(); if (!last_sample->filename) { patch_sample_unload(patch); return; } if (strcmp(patch_get_sample_name(patch), last_sample->filename) != 0) { msg_log(MSG_MESSAGE, "Restoring sample:%s\n", last_sample->filename); patch_sample_load(patch, last_sample->filename, last_sample->raw_samplerate, last_sample->raw_channels, last_sample->sndfile_format); } return; }
extern void daemon_init(msg_dest_t log_dest, const char *program, int facility, const char *pidfile, const char *username, const char *groupname) { pid_t pid; int i; FILE *pid_fp; int sigs[] = { SIGHUP, SIGINT, SIGQUIT, SIGTSTP, SIGTTIN, SIGTTOU }; struct passwd *pw; struct group *grp; /* make sure all those nice signals are going to be ignored */ for (i = 0; i < sizeof(sigs) / sizeof(int); i++) { if (!_daemon_handle_signal(sigs[i], SIG_IGN)) { msg_log(LOG_ERR, "Fatal error in daemon_init(): %s\n", strerror(errno)); exit(EXIT_FAILURE); } } /* stalking off to background... */ switch (pid = fork()) { case -1: msg_log(LOG_ERR, "Fatal error in fork(): %s\n", strerror(errno)); exit(EXIT_FAILURE); break; case 0: msg_close(); msg_open(log_dest, program, LOG_PID, facility); break; default: exit(EXIT_SUCCESS); break; } /* get rid of the associated terminal */ if (setsid() < 0) { msg_log(LOG_ERR, "Fatal error in setsid(): %s\n", strerror(errno)); exit(EXIT_FAILURE); } /* make sure we cannot be prosecuted by a not yet controlling terminal */ switch (pid = fork()) { case -1: msg_log(LOG_ERR, "Fatal error in fork(): %s\n", strerror(errno)); exit(EXIT_FAILURE); break; case 0: break; default: exit(EXIT_SUCCESS); break; } /* close unnecessary file descriptors */ close(STDIN_FILENO); close(STDOUT_FILENO); close(STDERR_FILENO); /* change working directory */ chdir("/"); /* set default file mode creation mask */ umask(0); /* write PID to pidfile */ if (NULL != pidfile) { pid_fp = fopen(pidfile, "w"); if (NULL == pid_fp) { msg_log(LOG_ERR, "Fatal error in fopen(): %s\n", strerror(errno)); exit(EXIT_FAILURE); } fprintf(pid_fp, "%d", (int)getpid()); fclose(pid_fp); } /* change user and group id */ if (NULL != groupname) { grp = getgrnam(groupname); /* using a non-threadsafe function is ok here */ if (0 != setgid(grp->gr_gid)) msg_log(LOG_WARNING, "Unable to change GID to %d (%s): %s\n", (int)grp->gr_gid, groupname, strerror(errno)); else msg_log(LOG_INFO, "Changed GID to %d (%s)\n", (int)grp->gr_gid, groupname); } if (NULL != username) { pw = getpwnam(username); /* using a non-threadsafe function is ok here */ if (0 != setuid(pw->pw_uid)) msg_log(LOG_WARNING, "Unable to change UID to %d (%s): %s\n", (int)pw->pw_uid, username, strerror(errno)); else msg_log(LOG_INFO, "Changed UID to %d (%s)\n", (int)pw->pw_uid, username); } }
int bank_ops_new(void) { msg_log(MSG_MESSAGE, "all patches destroyed\n"); patch_destroy_all(); return 0; }
int settings_write() { int rc; char* config_dir; char buf[CHARBUFSIZE]; xmlDocPtr doc; xmlNodePtr noderoot; xmlNodePtr node1; xmlNodePtr node2; msg_log(MSG_MESSAGE, "Writing global settings to: %s\n", gbl_settings->filename); doc = xmlNewDoc(BAD_CAST "1.0"); if (!doc) { msg_log(MSG_ERROR, "XML error!\n"); return -1; } config_dir = (char*) g_build_filename(g_get_user_config_dir(), g_get_prgname(), NULL); if (mkdir(config_dir, S_IRWXU) != 0) { if (errno != EEXIST) { msg_log(MSG_ERROR, "Could not create config directory: %s.\n", config_dir); free(config_dir); return -1; } } free(gbl_settings->filename); gbl_settings->filename = (char*) g_build_filename(config_dir, SETTINGS_BASENAME, NULL); free(config_dir); noderoot = xmlNewDocNode(doc, NULL, BAD_CAST "Petri-Foo-Settings",NULL); if (!noderoot) { msg_log(MSG_ERROR, "XML error!\n"); return -1; } xmlDocSetRootElement(doc, noderoot); node1 = xmlNewTextChild(noderoot, NULL, BAD_CAST "global", NULL); node2 = xmlNewTextChild(node1, NULL, BAD_CAST "property", NULL); xmlNewProp(node2, BAD_CAST "name", BAD_CAST "last-sample-directory"); xmlNewProp(node2, BAD_CAST "type", BAD_CAST "string"); xmlNewProp(node2, BAD_CAST "value", BAD_CAST gbl_settings->last_sample_dir); node2 = xmlNewTextChild(node1, NULL, BAD_CAST "property", NULL); xmlNewProp(node2, BAD_CAST "name", BAD_CAST "last-bank-directory"); xmlNewProp(node2, BAD_CAST "type", BAD_CAST "string"); xmlNewProp(node2, BAD_CAST "value", BAD_CAST gbl_settings->last_bank_dir); node2 = xmlNewTextChild(node1, NULL, BAD_CAST "property", NULL); xmlNewProp(node2, BAD_CAST "name", BAD_CAST "sliders-use-fans"); xmlNewProp(node2, BAD_CAST "type", BAD_CAST "boolean"); xmlNewProp(node2, BAD_CAST "value", BAD_CAST (phin_fan_slider_get_fans_active() ? "true" : "false")); node2 = xmlNewTextChild(node1, NULL, BAD_CAST "property", NULL); xmlNewProp(node2, BAD_CAST "name", BAD_CAST "last-bank-directory"); xmlNewProp(node2, BAD_CAST "type", BAD_CAST "string"); xmlNewProp(node2, BAD_CAST "value", BAD_CAST gbl_settings->last_bank_dir); node2 = xmlNewTextChild(node1, NULL, BAD_CAST "property", NULL); xmlNewProp(node2, BAD_CAST "name", BAD_CAST "log-lines"); xmlNewProp(node2, BAD_CAST "type", BAD_CAST "int"); snprintf(buf, CHARBUFSIZE, "%d", gbl_settings->log_lines); xmlNewProp(node2, BAD_CAST "value", BAD_CAST buf); debug("attempting to write file:%s\n",gbl_settings->filename); rc = xmlSaveFormatFile(gbl_settings->filename, doc, 1); xmlFreeDoc(doc); return rc; }
void sigterm_handler() { puts("\n"); msg_log(MSG_MESSAGE, "Caught SIGTERM signal\n"); cleanup(); }
void sigint_handler() { puts("\n"); msg_log(MSG_MESSAGE, "Caught SIGINT signal\n"); cleanup(); }
inline int avp_handle_result_code( struct tunnel *t, struct buffer *buf ) { //_u16 *ptr; struct avp_hdr *hdr = (struct avp_hdr *) buf->current; UNUSED_ARGUMENT(t); if( !IS_M_SET(hdr->head_node) ) { #ifdef DEBUG_AVP msg_log( LEVEL_ERR, "%s: M bit not set for msg-type-avp which is required!\n", __func__ ); #endif /* DEBUG_AVP */ return -1; } if( IS_H_SET(hdr->head_node) ) { #ifdef DEBUG_AVP msg_log( LEVEL_ERR, "%s: H bit cannot be set for %x type avp!\n", __func__, hdr->attribute_type ); #endif /* DEBUG_AVP */ return -1; } if( GET_AVP_LEN(hdr->head_node) < 0x0008 ) { #ifdef DEBUG_AVP msg_log( LEVEL_ERR, "%s: result_code-type-avp's length is less 8\n", __func__ ); #endif /* DEBUG_AVP */ return -1; } // ptr = (_u16 *)&hdr->attribute_type + 1; // if( t->tunnel_state == StopCCN ) // { // t->result_code = *ptr; // if( GET_AVP_LEN(hdr->head_node) >= 10 // && (*ptr == 2 || *ptr == 5) ) // { // t->error_code = *++ptr; // } // if( GET_AVP_LEN(hdr->head_node) > 10 ) // { /* bcopy( ptr + 1, t->err_msg, GET_AVP_LEN(hdr->head_node) - 10 >= MAX_ERR_MSG_LEN ? \ MAX_ERR_MSG_LEN : GET_AVP_LEN(hdr->head_node) - 10 ); */ // t->err_msg[MAX_ERR_MSG_LEN - 1] = '\0'; // } // } // else if( t->call.call_state == CDN ) // { // t->call.result_code = *ptr; // if( GET_AVP_LEN(hdr->head_node) >= 10 // && *ptr == 2 ) // { // t->call.error_code = *++ptr; // } // if( GET_AVP_LEN(hdr->head_node) > 10 ) // { /* bcopy( ptr + 1, t->call.err_msg, GET_AVP_LEN(hdr->head_node) - 10 >= MAX_ERR_MSG_LEN ? \ MAX_ERR_MSG_LEN : GET_AVP_LEN(hdr->head_node) - 10 ); */ // t->call.err_msg[MAX_ERR_MSG_LEN - 1] = '\0'; // } // } buf->current += GET_AVP_LEN(hdr->head_node); return 0; }
static void cb_load(raw_box* rb) { GtkWidget *msg; GtkFileFilter* filter; int err; char *name = (char *) gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(rb->dialog)); global_settings* settings = settings_get(); const char* filtername; mixer_flush_preview(); if (!name) goto fail; if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(rb->check))) { int samplerate = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(rb->samplerate)); if (patch_sample_load(patch, name, samplerate, rb->channels, get_format(rb)) < 0) { err = pf_error_get(); goto fail; } } else { /* don't repeat load sample */ const Sample* s = patch_sample_data(patch); if (s->filename && strcmp(name, s->filename) == 0) return; if (patch_sample_load(patch, name, 0, 0, 0)) { err = pf_error_get(); goto fail; } } msg_log(MSG_MESSAGE, "loaded sample '%s' for patch %d '%s'\n", name, patch, patch_get_name(patch)); if (name) { char* dirname = g_path_get_dirname(name); if (dirname) { if (settings->last_sample_dir) free(settings->last_sample_dir); settings->last_sample_dir = strdup(dirname); free(dirname); } } /* propagate certain user-set characteristics of the chooser * into the global settings */ filter = gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(rb->dialog)); filtername = gtk_file_filter_get_name(filter); if (filtername != 0) { if (settings->sample_file_filter) free(settings->sample_file_filter); settings->sample_file_filter = strdup(filtername); } /* the main menu not the chooser sets the global auto-preview on/off settings->sample_auto_preview = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(rb->auto_preview)); */ return; fail: if (!name) { /* I don't really think this is possible, but hey. */ msg_log(MSG_ERROR, "no file selected\n"); msg = gtk_message_dialog_new(GTK_WINDOW(rb->dialog), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "No file selected"); } else { msg_log(MSG_ERROR, "Failed to load sample %s for patch %d (%s)\n", name, patch, pf_error_str(err)); /* do our own notification here: */ msg = gtk_message_dialog_new(GTK_WINDOW(rb->dialog), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "Failed to load sample %s", name); } gtk_dialog_run (GTK_DIALOG(msg)); gtk_widget_destroy(msg); }
char* file_ops_sample_path_mangle( const char* samplepath, const char* bank_dir, const char* samples_dir) { char* sdir; /* sample dir */ char* sfile; /* sample filename */ char* hash_dir; /* full path of hash dir */ if (strstr(samplepath, bank_dir) == samplepath) { /* sample is located inline within bank_dir */ return file_ops_make_relative(samplepath, bank_dir); } file_ops_split_path(samplepath, &sdir, &sfile); if (!sdir || !sfile) { free(sdir); free(sfile); msg_log(MSG_ERROR, "non archivable sample path '%s'\n", samplepath); return 0; } if ((hash_dir = file_ops_hash_mkdir(sdir, samples_dir))) { char* link = file_ops_join_path(hash_dir, sfile); if (link) { struct stat st; if (stat(link, &st) != 0) symlink(samplepath, link); if (stat(link, &st) == 0) { char* link_rel = file_ops_make_relative(link, bank_dir); if (link_rel) { free(sdir); free(sfile); free(hash_dir); free(link); return link_rel; } } free(link); } free(hash_dir); } msg_log(MSG_ERROR, "symlinking sample '%s' failed\n", samplepath); free(sdir); free(sfile); return 0; }
inline int avp_handle_msg_type( struct tunnel *t, struct buffer *buf ) { struct bit16_ptr *ptr; struct avp_hdr *hdr = (struct avp_hdr *) buf->current; if( buf->current - buf->packet != sizeof( struct l2tp_ctl_hdr ) ) { #ifdef DEBUG_AVP msg_log( LEVEL_ERR, "%s: avp message type is not the first avp!\n", __func__ ); #endif /* DEBUG_AVP */ return -1; } if( !IS_M_SET(hdr->head_node) ) { #ifdef DEBUG_AVP msg_log( LEVEL_ERR, "%s: M bit not set for msg-type-avp which is required!\n", __func__ ); #endif /* DEBUG_AVP */ return -1; } if( GET_AVP_LEN(hdr->head_node) != 0x0008 ) { #ifdef DEBUG_AVP msg_log( LEVEL_ERR, "%s: msg-type-avp length is %x\n", __func__, GET_AVP_LEN(hdr->head_node)); #endif /* DEBUG_AVP */ return -1; } /* translate to host order */ ptr = (struct bit16_ptr *) buf->current; ptr->b3 = ntohs( ptr->b3 ); /* parase received control message type */ switch( ptr->b3 ) { case SCCRP: { if( t->tunnel_state != 0 ) { #ifdef DEBUG_STATE msg_log( LEVEL_ERR, "%s: wrong state %x response to current %x\n", __func__, ptr->b3, t->tunnel_state ); #endif /* DEBUG_STATE */ return -1; } t->tunnel_state = SCCRQ; t->need_control = 1; } break; case ICRP: { if( t->tunnel_state != SCCCN && !t->call.call_state ) { #ifdef DEBUG_STATE msg_log( LEVEL_ERR, "%s: wrong state %x response to current %x\n", __func__, ptr->b3, t->tunnel_state ); #endif /* DEBUG_STATE */ return -1; } t->call.call_state = ICRQ; t->need_control = 1; } break; case HELLO: { t->need_send_ack = 1; } break; case StopCCN: { t->need_send_ack = 1; t->tunnel_state = StopCCN; } break; case CDN: { //t->need_send_ack = 1; t->need_control = 1; t->call.call_state = CDN; } break; default: /* to simplify test, so far just deal above state */ break; } buf->current += 8; return 0; }
int settings_read(const char* path) { xmlDocPtr doc; xmlNodePtr noderoot; xmlNodePtr node1; xmlNodePtr node2; xmlChar* prop; msg_log(MSG_MESSAGE, "Reading global settings from: %s\n",path); doc = xmlParseFile (path); if (doc == NULL) { msg_log(MSG_ERROR, "Failed to parse %s\n", path); return -1; } noderoot = xmlDocGetRootElement(doc); if (noderoot == NULL) { msg_log(MSG_WARNING, "%s is empty\n", path); xmlFreeDoc(doc); return -1; } if (xmlStrcmp(noderoot->name, BAD_CAST "Petri-Foo-Settings") != 0) { msg_log(MSG_ERROR, "%s is not a valid 'Petri-Foo-Settings' file\n", path); xmlFreeDoc(doc); return -1; } for (node1 = noderoot->children; node1 != NULL; node1 = node1->next) { if (node1->type != XML_ELEMENT_NODE) continue; for ( node2 = node1->children; node2 != NULL; node2 = node2->next) { int n; if (xmlStrcmp(node2->name, BAD_CAST "property") == 0) { prop = BAD_CAST xmlGetProp(node2, BAD_CAST "name"); if (xmlStrcmp(prop, BAD_CAST "last-sample-directory") == 0) { free(gbl_settings->last_sample_dir); gbl_settings->last_sample_dir = (char*) xmlGetProp(node2, BAD_CAST "value"); } if (xmlStrcmp(prop, BAD_CAST "last-bank-directory") == 0) { free(gbl_settings->last_bank_dir); gbl_settings->last_bank_dir = (char*) xmlGetProp(node2, BAD_CAST "value"); } if (xmlStrcmp(prop, BAD_CAST "sliders-use-fans") == 0) { phin_fan_slider_set_fans_active( xmlstr_to_gboolean(xmlGetProp(node2, BAD_CAST "value"))); } if (xmlStrcmp(prop, BAD_CAST "log-lines") == 0) { xmlChar* vprop = xmlGetProp(node2, BAD_CAST "value"); if (sscanf((const char*)vprop, "%d", &n) == 1) gbl_settings->log_lines = n; } } } } return 0; }
void sighup_handler() { puts("\n"); msg_log(MSG_MESSAGE, "Caught SIGHUP signal\n"); cleanup(); }