int sendmail (const char *to, const char *subject, const char *body) { CURL *curl; CURLcode res = CURLE_FAILED_INIT; struct curl_slist *recipients = NULL; struct upload_status upload_ctx; upload_ctx.lines_read = 0; curl = curl_easy_init(); if (curl) { /* From & To must include '<>' */ payload_text[0] = strdup_printf ("To: <%s>\n", to); payload_text[1] = strdup_printf ("From: <%s> (%s)\n", smtp_username, fullname); payload_text[2] = strdup_printf ("Subject: %s\n", subject); /* empty line to divide headers from body, see RFC5322 */ payload_text[3] = "\n"; payload_text[4] = strdup_printf ("%s\n", body); payload_text[5] = NULL; curl_easy_setopt(curl, CURLOPT_URL, smtp_server); curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0); curl_easy_setopt(curl, CURLOPT_USERNAME, smtp_username); curl_easy_setopt(curl, CURLOPT_PASSWORD, smtp_password); /* value for envelope reverse-path */ curl_easy_setopt(curl, CURLOPT_MAIL_FROM, smtp_username); recipients = curl_slist_append(recipients, to); curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients); curl_easy_setopt(curl, CURLOPT_READFUNCTION, payload_source); curl_easy_setopt(curl, CURLOPT_READDATA, &upload_ctx); /* Since the traffic will be encrypted, it is very useful * to turn on debug information within libcurl to see what * is happening during the transfer. */ curl_easy_setopt(curl, CURLOPT_VERBOSE, 0); res = curl_easy_perform(curl); curl_slist_free_all(recipients); curl_easy_cleanup(curl); free (payload_text[0]); free (payload_text[1]); free (payload_text[2]); free (payload_text[4]); } return res; }
void info(char *name, int options) { char *reponame, *path, *pkgfile_path; struct repolist *repo; pkglist *p; reponame = pkglist_get_newer_favorite(name, options); if (reponame == NULL) error("%s not found!", name); repo = repolist_find(reponame, ilenia_repos); p = pkglist_select_from_repo(repo->name, ilenia_ports); p = pkglist_find(name, p); path = strdup_printf("%s/%s/%s", repo->path, repo->name, name); pkgfile_path = strdup_printf("%s/%s/%s/Pkgfile", repo->path, repo->name, name); FILE *f; f = fopen(pkgfile_path, "r"); if(!f) exit(1); printf("Name: %s\nVersion: %s\n", p->name, p->version); char *line = NULL; size_t n; int nread; while((nread = getline(&line, &n, f)) > 0) { char *_line = strdup(line); trim(_line); if(*_line != '#') continue; _line++; trim(_line); while(strstr(_line, " ")) strreplaceall(_line, " ", " "); printf("%s\n", _line); free(_line); } free(line); fclose(f); printf("Repository: %s\n", repo->name); printf("Path: %s\n", path); printf("Installed: %s\n", (pkglist_exists(p->name, ilenia_pkgs) == EXIT_SUCCESS) ? "yes" : "no"); printf("README: %s\n", (is_file(path, "README") == EXIT_SUCCESS) ? "yes" : "no"); printf("pre-install: %s\n", (is_file(path, "pre-install") == EXIT_SUCCESS) ? "yes" : "no"); printf("post-install: %s\n", (is_file(path, "post-install") == EXIT_SUCCESS) ? "yes" : "no"); free(pkgfile_path); free(path); }
int statusline_askchoice(const char *msg, const char *choices, short dflt) { char *s; int ch; assert((dflt >= 0) && (dflt <= strlen(choices))); if(dflt) { s = strdup_printf("%s [%c]", msg, choices[dflt - 1]); statusline_addhlstr(s); free(s); } else statusline_addhlstr(msg); while(1) { ch = tolower(getch()); if(ch == 7) /* ctrl+G */ return 0; if(dflt && (ch == '\r')) /* default choice */ return dflt; if((s = strchr(choices, ch))) return (s - choices + 1); } }
int mfshell_cmd_pwd(mfshell * mfshell, int argc, char *const argv[]) { (void)argv; const char *folder_name; char *folder_name_tmp = NULL; if (mfshell == NULL) return -1; if (mfshell->folder_curr == NULL) return -1; if (argc != 1) { fprintf(stderr, "Invalid number of arguments\n"); return -1; } folder_name = folder_get_name(mfshell->folder_curr); if (folder_name[0] == '\0') return -1; folder_name_tmp = strdup_printf("< %s >", folder_name); printf("%-15.13s %-50.50s\n\r", folder_get_key(mfshell->folder_curr), folder_name_tmp); free(folder_name_tmp); return 0; }
void ui_print_number_of_items() { char *str = strdup_printf(" " "|%3d/%3d", selected_items(), db_n_items()); mvaddstr(0, COLS-strlen(str), str); free(str); }
void ui_read_database() { char *msg; if(!list_is_empty()) { msg = strdup_printf(_("Your current data will be lost - " "Press '%c' to continue"), *(S_("keybinding for yes|y"))); if(!statusline_ask_boolean(msg, FALSE)) { free(msg); return; } free(msg); } load_database(datafile); refresh_list(); }
/* It's a bit slow, because it has to call fork() internally */ static int check_binary_to_be_stripped(const char *path) { FILE *pipe = NULL; int bytes = 0; char dummy_buf = 0, * cmd = NULL, * escaped = NULL; if(path == NULL) { return 0; } /* Escape ' so the shell does not get confused */ escaped = strsubs(path,"'","'\"'\"'"); /* The command we're using */ cmd = strdup_printf("file '%s' | grep 'not stripped'", escaped); if(escaped) { free(escaped); } /* Pipe */ pipe = popen(cmd,"re"); if(pipe == NULL) { return 0; } /* If one byte can be read, the file is a nonstripped binary */ bytes = fread(&dummy_buf, sizeof(char), 1, pipe); /* close pipe */ pclose(pipe); /* clean up */ if(cmd) { free(cmd); } if(bytes) { return 1; } /* not a nsb */ return 0; }
/* Channel history. Records the last MAX_CHANHISTORY messages to channels which keep historys */ void update_channel_history( char_data * ch, mud_channel * channel, const string & argument, bool emote ) { int type = 0; const string newarg = add_percent( argument ); chan_history *entry = new chan_history; if( !ch ) entry->name = "System"; else if( ch->isnpc() ) entry->name = ch->short_descr; else entry->name = ch->name; strdup_printf( &entry->format, " &R[%%s] &G%%s%s %s\r\n", emote ? "" : ":", newarg.c_str( ) ); entry->timestamp = current_time; if( ch && ch->has_aflag( AFF_INVISIBLE ) ) type = 1; if( ch && ch->has_pcflag( PCFLAG_WIZINVIS ) ) { type = 2; entry->invis = ch->pcdata->wizinvis; } entry->level = type; channel->history.push_back( entry ); if( channel->history.size() > MAX_CHANHISTORY ) { chan_history *oldentry = channel->history.front(); channel->history.pop_front(); deleteptr( oldentry ); } }
int upload_filedrop(CURL *curl_handle, char *api_root, char *endpoint, char *filepath, char *filedrop) { FILE *fh = NULL; struct curl_slist *custom_headers = NULL; uint64_t l_file_size; int retval; char *url; char *api_call; double upload_speed; double upload_time; char *tmpstr = NULL; fprintf(stderr, "[II] opening %s\n", filepath); fh = fopen(filepath, "r"); if(fh == NULL) { fprintf(stderr, "[EE] couldn't open specified file!\n"); return -1; } // get the size of the file and then rewind retval = fseek(fh, 0, SEEK_END); l_file_size = ftell(fh); rewind(fh); curl_handle = curl_init_set(curl_handle); url = strdup_printf("%s%s", api_root, endpoint); api_call = strdup_printf("%s?action_on_duplicate=replace" "&filedrop_key=%s", url, filedrop); custom_headers = curl_slist_append(custom_headers, "Content-Type: application/octet-stream"); custom_headers = curl_slist_append(custom_headers, "Expect:"); tmpstr = strdup_printf("x-filesize: %zd", l_file_size); custom_headers = curl_slist_append(custom_headers, tmpstr); free(tmpstr); tmpstr = strdup_printf("x-filename: %s", filepath); custom_headers = curl_slist_append(custom_headers, tmpstr); free(tmpstr); curl_easy_setopt(curl_handle, CURLOPT_POST, 1); curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, custom_headers); curl_easy_setopt(curl_handle, CURLOPT_URL, api_call); curl_easy_setopt(curl_handle, CURLOPT_READFUNCTION, http_read_file_cb); curl_easy_setopt(curl_handle, CURLOPT_READDATA, (void *)fh); curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDSIZE, l_file_size); curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L); retval = curl_easy_perform(curl_handle); curl_easy_getinfo(curl_handle, CURLINFO_SPEED_UPLOAD, &upload_speed); curl_easy_getinfo(curl_handle, CURLINFO_TOTAL_TIME, &upload_time); fprintf(stderr, "Speed: %.3f bytes/sec during %.3f seconds\n", upload_speed, upload_time); curl_slist_free_all(custom_headers); custom_headers = NULL; fclose(fh); return 0; }
static int _eXosip_retry_with_auth (eXosip_dialog_t * jd, osip_transaction_t ** ptr, int *retry) { osip_transaction_t *out_tr = NULL; osip_transaction_t *tr = NULL; osip_message_t *msg = NULL; osip_event_t *sipevent; jinfo_t *ji = NULL; int cseq; osip_via_t *via; int i; if (!ptr) return -1; if (jd != NULL) { if (jd->d_out_trs == NULL) return -1; } out_tr = *ptr; if (out_tr == NULL || out_tr->orig_request == NULL || out_tr->last_response == NULL) return -1; if (retry && (*retry >= 3)) return -1; osip_message_clone (out_tr->orig_request, &msg); if (msg == NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: could not clone msg for authentication\n")); return -1; } via = (osip_via_t *) osip_list_get (&msg->vias, 0); if (via == NULL || msg->cseq == NULL || msg->cseq->number == NULL) { osip_message_free (msg); OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: missing via or cseq header\n")); return -1; } /* increment cseq */ cseq = atoi (msg->cseq->number); osip_free (msg->cseq->number); msg->cseq->number = strdup_printf ("%i", cseq + 1); if (jd != NULL && jd->d_dialog != NULL) { jd->d_dialog->local_cseq++; } i = eXosip_update_top_via(msg); if (i!=0) { osip_message_free (msg); OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: unsupported protocol\n")); return -1; } if (eXosip_add_authentication_information (msg, out_tr->last_response) < 0) { osip_message_free (msg); return -1; } osip_message_force_update (msg); if (MSG_IS_INVITE (msg)) i = _eXosip_transaction_init (&tr, ICT, eXosip.j_osip, msg); else i = _eXosip_transaction_init (&tr, NICT, eXosip.j_osip, msg); if (i != 0) { osip_message_free (msg); return -1; } /* replace with the new tr */ if (MSG_IS_PUBLISH(msg)) { /* old transaction is put in the garbage list */ osip_list_add (eXosip.j_transactions, out_tr, 0); /* new transaction is put in the publish context */ *ptr = tr; } else osip_list_add (eXosip.j_transactions, tr, 0); sipevent = osip_new_outgoing_sipmessage (msg); ji = osip_transaction_get_your_instance (out_tr); osip_transaction_set_your_instance (out_tr, NULL); osip_transaction_set_your_instance (tr, ji); osip_transaction_add_event (tr, sipevent); if (retry) (*retry)++; eXosip_update (); /* fixed? */ __eXosip_wakeup (); return 0; }
int _eXosip_call_retry_request (eXosip_call_t * jc, eXosip_dialog_t * jd, osip_transaction_t * out_tr) { osip_transaction_t *tr = NULL; osip_message_t *msg = NULL; osip_event_t *sipevent; int cseq; osip_via_t *via; osip_contact_t *co; int pos; int i; int protocol = IPPROTO_UDP; if (jc == NULL) return OSIP_BADPARAMETER; if (jd != NULL) { if (jd->d_out_trs == NULL) return OSIP_BADPARAMETER; } if (out_tr == NULL || out_tr->orig_request == NULL || out_tr->last_response == NULL) return OSIP_BADPARAMETER; i = osip_message_clone (out_tr->orig_request, &msg); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: could not clone msg for authentication\n")); return i; } via = (osip_via_t *) osip_list_get (&msg->vias, 0); if (via == NULL || msg->cseq == NULL || msg->cseq->number == NULL) { osip_message_free (msg); OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: missing via or cseq header\n")); return OSIP_SYNTAXERROR; } if (MSG_IS_STATUS_3XX (out_tr->last_response)) { co = NULL; pos = 0; while (!osip_list_eol (&out_tr->last_response->contacts, pos)) { co = (osip_contact_t *) osip_list_get (&out_tr->last_response->contacts, pos); if (co != NULL && co->url != NULL) { /* check tranport? Only allow UDP, right now */ osip_uri_param_t *u_param; int pos2; u_param = NULL; pos2 = 0; while (!osip_list_eol (&co->url->url_params, pos2)) { u_param = (osip_uri_param_t *) osip_list_get (&co->url->url_params, pos2); if (u_param == NULL || u_param->gname == NULL || u_param->gvalue == NULL) { u_param = NULL; /* skip */ } else if (0 == osip_strcasecmp (u_param->gname, "transport")) { if (0 == osip_strcasecmp (u_param->gvalue, "udp")) { u_param = NULL; protocol = IPPROTO_UDP; break; /* ok */ } else if (0 == osip_strcasecmp (u_param->gvalue, "tcp")) { protocol = IPPROTO_TCP; u_param = NULL; } break; } pos2++; } if (u_param == NULL || u_param->gname == NULL || u_param->gvalue == NULL) { break; /* default is udp! */ } } pos++; co = NULL; } if (co == NULL || co->url == NULL) { osip_message_free (msg); OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: contact header\n")); return OSIP_SYNTAXERROR; } /* TODO: remove extra parameter from new request-uri check usual parameter like "transport" */ if (msg->req_uri != NULL && msg->req_uri->host != NULL && co->url->host != NULL && 0 == osip_strcasecmp (co->url->host, msg->req_uri->host)) { osip_uri_param_t *maddr_param = NULL; osip_uri_uparam_get_byname (co->url, "maddr", &maddr_param); if (maddr_param != NULL && maddr_param->gvalue != NULL) { /* This is a redirect server, the route should probably be removed? */ osip_route_t *route = NULL; osip_generic_param_t *tag = NULL; osip_message_get_route (msg, 0, &route); if (route != NULL) { osip_to_get_tag (msg->to, &tag); if (tag == NULL && route != NULL && route->url != NULL) { osip_list_remove (&msg->routes, 0); osip_route_free (route); } } } } /* replace request-uri with NEW contact address */ osip_uri_free (msg->req_uri); msg->req_uri = NULL; osip_uri_clone (co->url, &msg->req_uri); /* support for diversions headers/draft! */ { int count = 0; pos = 0; while (!osip_list_eol (&out_tr->last_response->headers, pos)) { osip_header_t *copy = NULL; osip_header_t *head = osip_list_get (&out_tr->last_response->headers, pos); if (head != NULL && 0 == osip_strcasecmp (head->hname, "diversion")) { i = osip_header_clone (head, ©); if (i == 0) { osip_list_add (&msg->headers, copy, count); count++; } } pos++; } } } /* remove all previous authentication headers */ osip_list_special_free (&msg->authorizations, (void *(*)(void *)) &osip_authorization_free); osip_list_special_free (&msg->proxy_authorizations, (void *(*)(void *)) &osip_proxy_authorization_free); /* increment cseq */ cseq = atoi (msg->cseq->number); osip_free (msg->cseq->number); msg->cseq->number = strdup_printf ("%i", cseq + 1); if (jd != NULL && jd->d_dialog != NULL) { jd->d_dialog->local_cseq++; } i = eXosip_update_top_via (msg); if (i != 0) { osip_message_free (msg); return i; } if (out_tr->last_response->status_code == 401 || out_tr->last_response->status_code == 407) eXosip_add_authentication_information (msg, out_tr->last_response); else eXosip_add_authentication_information (msg, NULL); osip_message_force_update (msg); if (0 != osip_strcasecmp (msg->sip_method, "INVITE")) { i = _eXosip_transaction_init (&tr, NICT, eXosip.j_osip, msg); } else { i = _eXosip_transaction_init (&tr, ICT, eXosip.j_osip, msg); } if (i != 0) { osip_message_free (msg); return i; } if (out_tr == jc->c_out_tr) { /* replace with the new tr */ osip_list_add (&eXosip.j_transactions, jc->c_out_tr, 0); jc->c_out_tr = tr; /* fix dialog issue */ if (jd != NULL) { REMOVE_ELEMENT (jc->c_dialogs, jd); eXosip_dialog_free (jd); jd = NULL; } } else { /* add the new tr for the current dialog */ osip_list_add (jd->d_out_trs, tr, 0); } sipevent = osip_new_outgoing_sipmessage (msg); #ifndef MINISIZE osip_transaction_set_your_instance (tr, __eXosip_new_jinfo (jc, jd, NULL, NULL)); #else osip_transaction_set_your_instance (tr, __eXosip_new_jinfo (jc, jd)); #endif osip_transaction_add_event (tr, sipevent); eXosip_update (); /* fixed? */ __eXosip_wakeup (); return OSIP_SUCCESS; }
int _eXosip_insubscription_send_request_with_credential (eXosip_notify_t * jn, eXosip_dialog_t * jd, osip_transaction_t * out_tr) { osip_transaction_t *tr = NULL; osip_message_t *msg = NULL; osip_event_t *sipevent; char locip[256]; int cseq; char tmp[256]; osip_via_t *via; int i; if (jn == NULL) return -1; if (jd != NULL) { if (jd->d_out_trs == NULL) return -1; } if (out_tr == NULL) { out_tr = eXosip_find_last_out_notify (jn, jd); } if (out_tr == NULL || out_tr->orig_request == NULL || out_tr->last_response == NULL) return -1; osip_message_clone (out_tr->orig_request, &msg); if (msg == NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: could not clone msg for authentication\n")); return -1; } via = (osip_via_t *) osip_list_get (msg->vias, 0); if (via == NULL || msg->cseq == NULL || msg->cseq->number == NULL) { osip_message_free (msg); OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: missing via or cseq header\n")); return -1; } /* increment cseq */ cseq = atoi (msg->cseq->number); osip_free (msg->cseq->number); msg->cseq->number = strdup_printf ("%i", cseq + 1); if (jd != NULL && jd->d_dialog != NULL) { jd->d_dialog->local_cseq++; } osip_list_remove (msg->vias, 0); osip_via_free (via); i = _eXosip_find_protocol (out_tr->orig_request); if (i == IPPROTO_UDP) { eXosip_guess_ip_for_via (eXosip.net_interfaces[0].net_ip_family, locip, sizeof (locip)); if (eXosip.net_interfaces[0].net_ip_family == AF_INET6) snprintf (tmp, 256, "SIP/2.0/UDP [%s]:%s;branch=z9hG4bK%u", locip, eXosip.net_interfaces[0].net_port, via_branch_new_random ()); else snprintf (tmp, 256, "SIP/2.0/UDP %s:%s;rport;branch=z9hG4bK%u", locip, eXosip.net_interfaces[0].net_port, via_branch_new_random ()); } else if (i == IPPROTO_TCP) { eXosip_guess_ip_for_via (eXosip.net_interfaces[1].net_ip_family, locip, sizeof (locip)); if (eXosip.net_interfaces[1].net_ip_family == AF_INET6) snprintf (tmp, 256, "SIP/2.0/TCP [%s]:%s;branch=z9hG4bK%u", locip, eXosip.net_interfaces[1].net_port, via_branch_new_random ()); else snprintf (tmp, 256, "SIP/2.0/TCP %s:%s;rport;branch=z9hG4bK%u", locip, eXosip.net_interfaces[1].net_port, via_branch_new_random ()); } else { /* tls? */ osip_message_free (msg); OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: unsupported protocol\n")); return -1; } osip_via_init (&via); osip_via_parse (via, tmp); osip_list_add (msg->vias, via, 0); eXosip_add_authentication_information (msg, out_tr->last_response); osip_message_force_update (msg); i = osip_transaction_init (&tr, NICT, eXosip.j_osip, msg); if (i != 0) { osip_message_free (msg); return -1; } /* add the new tr for the current dialog */ osip_list_add (jd->d_out_trs, tr, 0); sipevent = osip_new_outgoing_sipmessage (msg); osip_transaction_set_your_instance (tr, __eXosip_new_jinfo (NULL, jd, NULL, jn)); osip_transaction_add_event (tr, sipevent); eXosip_update (); /* fixed? */ __eXosip_wakeup (); return 0; }
/* * Callbock from nftw() * If the file given from nftw by "path": * - is a directory: recurs into it and catch the files there, * as long the depth doesnt get bigger than max_depth and contains the pattern cmp_pattern * - a file: Push it back to the list, if it has "cmp_pattern" in it. (if --regex was given) * If the user interrupts, nftw() stops, and the program will do it'S magic. * * Not many comments, because man page of nftw will explain everything you'll need to understand * * Appendum: rmlint uses the inode to sort the contents before doing any I/O to speed up things. * This is nevertheless limited to Unix filesystems like ext*, reiserfs.. (might work in MacOSX - don't know) * If someone likes to port this to Windows he would to replace the inode number by the MFT entry point, or simply disable it * I personally don't have a win comp and won't port it, as I don't found many users knowing what that black window with white * white letters can do ;-) */ static int eval_file(const char *path, const struct stat *ptr, int flag, struct FTW *ftwbuf) { if(set->depth && ftwbuf->level > set->depth) { /* Do not recurse in this subdir */ return FTW_SKIP_SIBLINGS; } if(iAbort) { return FTW_STOP; } if(flag == FTW_SLN) { list_append(path, 0,ptr->st_dev,ptr->st_ino,TYPE_BLNK); return FTW_CONTINUE; } if(path) { if(!dir_done) { char *orig_path = set->paths[get_cpindex()]; size_t orig_path_len = strlen(set->paths[get_cpindex()]); if(orig_path[orig_path_len - 1] == '/') { orig_path_len -= 1; } if(!strncmp(set->paths[get_cpindex()], path, orig_path_len)) { dir_done = true; return FTW_CONTINUE; } } if(flag == FTW_F && (set->minsize <= ptr->st_size || set->minsize < 0) && (set->maxsize >= ptr->st_size || set->maxsize < 0)) { if(regfilter(path, set->fpattern)) { return FTW_CONTINUE; } if(junkinstr(rmlint_basename(path))) { list_append(path, 0,ptr->st_dev,ptr->st_ino,TYPE_JNK_FILENAME); if(set->collide) { return FTW_CONTINUE; } } if(set->findbadids) { bool has_gid, has_uid; if(userlist_contains(global_ug_list,ptr->st_uid,ptr->st_gid,&has_uid,&has_gid) == false) { if(has_gid == false) list_append(path,0,ptr->st_dev,ptr->st_ino,TYPE_BADGID); if(has_uid == false) list_append(path,0,ptr->st_dev,ptr->st_ino,TYPE_BADUID); if(set->collide) { return FTW_CONTINUE; } } } if(set->nonstripped) { if(check_binary_to_be_stripped(path)) { list_append(path, 0,ptr->st_dev,ptr->st_ino,TYPE_NBIN); if(set->collide) { return FTW_CONTINUE; } } } if(set->doldtmp) { /* This checks only for *~ and .*.swp */ size_t len = strlen(path); if(path[len-1] == '~' || (len>3&&path[len-1] == 'p'&&path[len-2] == 'w'&&path[len-3] == 's'&&path[len-4] == '.')) { char *cpy = NULL; struct stat stat_buf; if(path[len - 1] == '~') { cpy = strndup(path,len-1); } else { char * p = strrchr(path,'/'); size_t p_len = p-path; char * front = alloca(p_len+1); memset(front, '\0', p_len+1); strncpy(front, path, p_len); cpy = strdup_printf("%s/%s",front,p+2); cpy[strlen(cpy)-4] = 0; } if(!stat(cpy, &stat_buf)) { if(ptr->st_mtime - stat_buf.st_mtime >= set->oldtmpdata) { list_append(path, 0,ptr->st_dev,ptr->st_ino,TYPE_OTMP); } } if(cpy) { free(cpy); } if(set->collide) { return FTW_CONTINUE; } } } /* Check this to be a valid file and NOT a blockfile (reading /dev/null does funny things) */ if(flag == FTW_F && !(S_ISCHR(ptr->st_mode) || S_ISBLK(ptr->st_mode)) && (set->listemptyfiles || ptr->st_size != 0)) { if(!access(path,R_OK)) { if(set->ignore_hidden) { char *base = rmlint_basename(path); if(*base != '.') { dircount++; list_append(path, ptr->st_size,ptr->st_dev,ptr->st_ino,1); } } else { dircount++; list_append(path, ptr->st_size,ptr->st_dev,ptr->st_ino,1); } } return FTW_CONTINUE; } } if(flag == FTW_D) { if(regfilter(path, set->dpattern) && dir_done) { return FTW_SKIP_SUBTREE; } if(junkinstr(rmlint_basename(path))) { list_append(path, 0,ptr->st_dev,ptr->st_ino,TYPE_JNK_DIRNAME); if(set->collide) { return FTW_SKIP_SUBTREE; } } if(set->findemptydirs) { int dir_counter = 0; DIR *dir_e = opendir(path); struct dirent *dir_p = NULL; if(dir_e) { while((dir_p=readdir(dir_e)) && dir_counter < 2) { dir_counter++; } closedir(dir_e); if(dir_counter == 2 && dir_p == NULL) { list_append(path, 0,ptr->st_dev,ptr->st_ino,TYPE_EDIR); return FTW_SKIP_SUBTREE; } } } if(set->ignore_hidden && path) { char *base = rmlint_basename(path); if(*base == '.' && dir_done) { return FTW_SKIP_SUBTREE; } } } } return FTW_CONTINUE; }
int parse_pkgfile(char *filename, char *repo) { FILE *file; size_t n = 0; char *line = NULL; ssize_t nread; struct deplist *d = NULL; char *name = NULL, *version = NULL, *release = NULL; file = fopen(filename, "r"); if (file == NULL) return (EXIT_FAILURE); while ((nread = getline(&line, &n, file)) != -1) { trim(line); if (line[0] == '#') { line = mid(line, 1, END); trim(line); if (strstr(line, "Depends") == NULL) continue; if (strstr(line, ":") == NULL) continue; line = strstr(line, ":"); line = mid(line, 1, END); trim(line); d = deplist_from_deprow(line); line = NULL; } else if (strncmp(line, "name", 4) == 0) name = get_value(line, "name"); else if (strncmp(line, "version", 7) == 0) version = get_value(line, "version"); else if (strncmp(line, "release", 7) == 0) release = get_value(line, "release"); } if (!(name && version && release)) return (EXIT_FAILURE); version = sedchr(version, ' ', '_'); char *dirname = filename; *(strrchr(dirname, '/')) = 0; dirname = strrchr(filename, '/'); ++dirname; if(strcmp(name, dirname)) return EXIT_FAILURE; char *tmp = strdup_printf("%s %s-%s %s", name, version, release, repo); if(sscanf(tmp, "%s %s %s", name, version, repo)!=3) { free(tmp); return EXIT_FAILURE; } fprintf(cachefile, "%s", tmp); free(tmp); while (d != NULL) { fprintf(cachefile, " %s", d->name); d = d->next; } fprintf(cachefile, "\n"); if (line) free(line); fclose(file); return (EXIT_SUCCESS); }
int _eXosip_insubscription_send_request_with_credential (eXosip_notify_t * jn, eXosip_dialog_t * jd, osip_transaction_t * out_tr) { osip_transaction_t *tr = NULL; osip_message_t *msg = NULL; osip_event_t *sipevent; int cseq; osip_via_t *via; int i; if (jn == NULL) return OSIP_BADPARAMETER; if (jd != NULL) { if (jd->d_out_trs == NULL) return OSIP_BADPARAMETER; } if (out_tr == NULL) { out_tr = eXosip_find_last_out_notify (jn, jd); } if (out_tr == NULL || out_tr->orig_request == NULL || out_tr->last_response == NULL) return OSIP_NOTFOUND; i = osip_message_clone (out_tr->orig_request, &msg); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: could not clone msg for authentication\n")); return i; } via = (osip_via_t *) osip_list_get (&msg->vias, 0); if (via == NULL || msg->cseq == NULL || msg->cseq->number == NULL) { osip_message_free (msg); OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: missing via or cseq header\n")); return OSIP_SYNTAXERROR; } /* increment cseq */ cseq = atoi (msg->cseq->number); osip_free (msg->cseq->number); msg->cseq->number = strdup_printf ("%i", cseq + 1); if (msg->cseq->number == NULL) { osip_message_free (msg); return OSIP_NOMEM; } if (jd != NULL && jd->d_dialog != NULL) { jd->d_dialog->local_cseq++; } i = eXosip_update_top_via (msg); if (i != 0) { osip_message_free (msg); OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: unsupported protocol\n")); return i; } if (out_tr->last_response->status_code == 401 || out_tr->last_response->status_code == 407) eXosip_add_authentication_information (msg, out_tr->last_response); else eXosip_add_authentication_information (msg, NULL); osip_message_force_update (msg); i = _eXosip_transaction_init (&tr, NICT, eXosip.j_osip, msg); if (i != 0) { osip_message_free (msg); return i; } /* add the new tr for the current dialog */ osip_list_add (jd->d_out_trs, tr, 0); sipevent = osip_new_outgoing_sipmessage (msg); osip_transaction_set_your_instance (tr, __eXosip_new_jinfo (NULL, jd, NULL, jn)); osip_transaction_add_event (tr, sipevent); eXosip_update (); /* fixed? */ __eXosip_wakeup (); return OSIP_SUCCESS; }