static bool update_settings(struct obs_x264 *obsx264, obs_data_t *settings) { char *preset = bstrdup(obs_data_get_string(settings, "preset")); char *profile = bstrdup(obs_data_get_string(settings, "profile")); char *tune = bstrdup(obs_data_get_string(settings, "tune")); const char *opts = obs_data_get_string(settings, "x264opts"); char **paramlist; bool success = true; paramlist = strlist_split(opts, ' ', false); blog(LOG_INFO, "---------------------------------"); if (!obsx264->context) { override_base_params(obsx264, paramlist, &preset, &profile, &tune); if (preset && *preset) info("preset: %s", preset); if (profile && *profile) info("profile: %s", profile); if (tune && *tune) info("tune: %s", tune); success = reset_x264_params(obsx264, preset, tune); } if (success) { update_params(obsx264, settings, paramlist); if (opts && *opts) info("custom settings: %s", opts); if (!obsx264->context) apply_x264_profile(obsx264, profile); } obsx264->params.b_repeat_headers = false; strlist_free(paramlist); bfree(preset); bfree(profile); bfree(tune); return success; }
/* retreive a simple list (.pool, .client) and store it into items */ void get_items(const char *what) { init_items(); UA_sock->fsend("%s", what); while (UA_sock->recv() > 0) { strip_trailing_junk(UA_sock->msg); items->list.append(bstrdup(UA_sock->msg)); } }
int do_shell_expansion(char *name, int name_len) { char *src = bstrdup(name); ExpandEnvironmentStrings(src, name, name_len); free(src); return 1; }
static void do_extract(char *devname) { struct stat statp; enable_backup_privileges(NULL, 1); jcr = setup_jcr("bextract", devname, bsr, director, VolumeName, 1); /* acquire for read */ if (!jcr) { exit(1); } dev = jcr->read_dcr->dev; if (!dev) { exit(1); } dcr = jcr->read_dcr; /* Make sure where directory exists and that it is a directory */ if (stat(where, &statp) < 0) { berrno be; Emsg2(M_ERROR_TERM, 0, _("Cannot stat %s. It must exist. ERR=%s\n"), where, be.bstrerror()); } if (!S_ISDIR(statp.st_mode)) { Emsg1(M_ERROR_TERM, 0, _("%s must be a directory.\n"), where); } free(jcr->where); jcr->where = bstrdup(where); attr = new_attr(jcr); compress_buf = get_memory(compress_buf_size); acl_data.last_fname = get_pool_memory(PM_FNAME); xattr_data.last_fname = get_pool_memory(PM_FNAME); read_records(dcr, record_cb, mount_next_read_volume); /* If output file is still open, it was the last one in the * archive since we just hit an end of file, so close the file. */ if (is_bopen(&bfd)) { set_attributes(jcr, attr, &bfd); } free_attr(attr); free_pool_memory(acl_data.last_fname); free_pool_memory(xattr_data.last_fname); clean_device(jcr->dcr); dev->term(); free_dcr(dcr); free_jcr(jcr); printf(_("%u files restored.\n"), num_files); return; }
char_t *umGetAccessLimit(char_t *url) { char_t *urlRet, *urlCheck, *lastChar; int len; a_assert(url && *url); urlRet = NULL; urlCheck = bstrdup(B_L, url); a_assert(urlCheck); len = gstrlen(urlCheck); /* * Scan back through URL to see if there is a "parent" access limit */ while (len && !urlRet) { if (umAccessLimitExists(urlCheck)) { urlRet = bstrdup(B_L, urlCheck); } else { /* * Trim the end portion of the URL to the previous directory marker */ lastChar = urlCheck + len; lastChar--; while ((lastChar >= urlCheck) && ((*lastChar == '/') || (*lastChar == '\\'))) { *lastChar = 0; lastChar--; } while ((lastChar >= urlCheck) && (*lastChar != '/') && (*lastChar != '\\')) { *lastChar = 0; lastChar--; } len = gstrlen(urlCheck); } } bfree (B_L, urlCheck); return urlRet; }
static inline IISQLDA *INGgetDescriptor(int numCols, const char *query) { /* # line 99 "myingres.sc" */ char *stmt; /* # line 101 "myingres.sc" */ int i; IISQLDA *sqlda; sqlda = (IISQLDA *)malloc(IISQDA_HEAD_SIZE + (numCols * IISQDA_VAR_SIZE)); memset(sqlda, 0, (IISQDA_HEAD_SIZE + (numCols * IISQDA_VAR_SIZE))); sqlda->sqln = numCols; stmt = bstrdup(query); /* # line 112 "myingres.sc" */ /* prepare */ { IIsqInit(&sqlca); IIsqPrepare(0,(char *)"s2",sqlda,0,stmt); } /* # line 114 "myingres.sc" */ /* host code */ for (i = 0; i < sqlda->sqld; ++i) { /* * Negative type indicates nullable columns, so an indicator * is allocated, otherwise it's null */ if (sqlda->sqlvar[i].sqltype > 0) { sqlda->sqlvar[i].sqlind = NULL; } else { sqlda->sqlvar[i].sqlind = (short *)malloc(sizeof(short)); } /* * Alloc space for variable like indicated in sqllen * for date types sqllen is always 0 -> allocate by type */ switch (abs(sqlda->sqlvar[i].sqltype)) { case IISQ_TSW_TYPE: sqlda->sqlvar[i].sqldata = (char *)malloc(IISQ_TSW_LEN); break; case IISQ_TSWO_TYPE: sqlda->sqlvar[i].sqldata = (char *)malloc(IISQ_TSWO_LEN); break; case IISQ_TSTMP_TYPE: sqlda->sqlvar[i].sqldata = (char *)malloc(IISQ_TSTMP_LEN); break; default: /* * plus one to avoid zero mem allocs */ sqlda->sqlvar[i].sqldata = (char *)malloc(sqlda->sqlvar[i].sqllen + 1); break; } } free(stmt); return sqlda; }
/* * This is where we pick up a client name to restore to. */ static int get_restore_client_name(UAContext *ua, RESTORE_CTX &rx) { int i; /* * Try command line argument */ i = find_arg_with_value(ua, NT_("restoreclient")); if (i >= 0) { if (!is_name_valid(ua->argv[i], &ua->errmsg)) { ua->error_msg("%s argument: %s", ua->argk[i], ua->errmsg); return 0; } rx.RestoreClientName = bstrdup(ua->argv[i]); return 1; } rx.RestoreClientName = bstrdup(rx.ClientName); return 1; }
char_t *websCalcOpaque(webs_t wp) { char_t *opaque; a_assert(wp); /* * Temporary stub! */ opaque = bstrdup(B_L, T("5ccc069c403ebaf9f0171e9517f40e41")); return opaque; }
int obs_open_module(obs_module_t **module, const char *path, const char *data_path) { struct obs_module mod = {0}; int errorcode; if (!module || !path || !obs) return MODULE_ERROR; blog(LOG_INFO, "---------------------------------"); mod.module = os_dlopen(path); if (!mod.module) { blog(LOG_WARNING, "Module '%s' not found", path); return MODULE_FILE_NOT_FOUND; } errorcode = load_module_exports(&mod, path); if (errorcode != MODULE_SUCCESS) return errorcode; mod.bin_path = bstrdup(path); mod.file = strrchr(mod.bin_path, '/'); mod.file = (!mod.file) ? mod.bin_path : (mod.file + 1); mod.mod_name = get_module_name(mod.file); mod.data_path = bstrdup(data_path); mod.next = obs->first_module; if (mod.file) { blog(LOG_INFO, "Loading module: %s", mod.file); } *module = bmemdup(&mod, sizeof(mod)); obs->first_module = (*module); mod.set_pointer(*module); if (mod.set_locale) mod.set_locale(obs->locale); return MODULE_SUCCESS; }
/* * Handle an event that was generated in Bareos */ static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value) { bRC retval; plugin_ctx *p_ctx = (plugin_ctx *)ctx->pContext; if (!p_ctx) { return bRC_Error; } switch (event->eventType) { case bEventLevel: p_ctx->backup_level = (int64_t)value; retval = bRC_OK; break; case bEventRestoreCommand: /* * Fall-through wanted */ case bEventBackupCommand: /* * Fall-through wanted */ case bEventPluginCommand: retval = parse_plugin_definition(ctx, value); break; case bEventNewPluginOptions: /* * Free any previous value. */ if (p_ctx->plugin_options) { free(p_ctx->plugin_options); p_ctx->plugin_options = NULL; } retval = parse_plugin_definition(ctx, value); /* * Save that we got a plugin override. */ p_ctx->plugin_options = bstrdup((char *)value); break; case bEventEndRestoreJob: retval = end_restore_job(ctx, value); break; default: Jmsg(ctx, M_FATAL, "mssqlvdi-fd: unknown event=%d\n", event->eventType); Dmsg(ctx, dbglvl, "mssqlvdi-fd: unknown event=%d\n", event->eventType); retval = bRC_Error; break; } return retval; }
/* * Check if volume name is on read volume list. */ bool is_on_read_volume_list(JCR *jcr, const char *VolumeName) { VOLRES vol, *fvol; lock_read_volumes(); vol.vol_name = bstrdup(VolumeName); fvol = (VOLRES *)read_vol_list->binary_search(&vol, compare_by_volumename); free(vol.vol_name); unlock_read_volumes(); return fvol != NULL; }
/* * curently it assigns argv[0] into program_name variable only, future enchancement possible */ void pgsqllibinit ( int argc, char * argv[] ){ char * prg; char * nprg; char * dirtmp; prg = bstrdup ( argv[0] ); nprg = basename ( prg ); program_name = bstrdup ( nprg ); FREE ( prg ); dirtmp = MALLOC ( PATH_MAX ); if ( realpath ( argv[0], dirtmp ) == NULL ){ /* error in resolving path */ FREE ( dirtmp ); dirtmp = argv[0]; } program_directory = bstrdup ( dirtmp ); FREE ( dirtmp ); }
/* ensures that names are never blank */ static inline char *dup_name(const char *name) { if (!name || !*name) { struct dstr unnamed = {0}; dstr_printf(&unnamed, "__unnamed%004lld", obs->data.unnamed_index++); return unnamed.array; } else { return bstrdup(name); } }
/* * Handle an event that was generated in Bareos */ static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value) { bRC retval = bRC_OK; struct plugin_ctx *p_ctx = (struct plugin_ctx *)ctx->pContext; if (!p_ctx) { return bRC_Error; } switch (event->eventType) { case bEventJobStart: Dmsg(ctx, dbglvl, "bpipe-fd: JobStart=%s\n", (char *)value); break; case bEventRestoreCommand: /* * Fall-through wanted */ case bEventBackupCommand: /* * Fall-through wanted */ case bEventEstimateCommand: /* * Fall-through wanted */ case bEventPluginCommand: retval = parse_plugin_definition(ctx, value); break; case bEventNewPluginOptions: /* * Free any previous value. */ if (p_ctx->plugin_options) { free(p_ctx->plugin_options); p_ctx->plugin_options = NULL; } retval = parse_plugin_definition(ctx, value); /* * Save that we got a plugin override. */ p_ctx->plugin_options = bstrdup((char *)value); break; default: Jmsg(ctx, M_FATAL, "bpipe-fd: unknown event=%d\n", event->eventType); Dmsg(ctx, dbglvl, "bpipe-fd: unknown event=%d\n", event->eventType); retval = bRC_Error; break; } return retval; }
/* Initialize internal socket structure. * This probably should be done in net_open */ BSOCK *init_bsock(JCR * jcr, int sockfd, const char *who, const char *host, int port, struct sockaddr *client_addr) { Dmsg3(100, "who=%s host=%s port=%d\n", who, host, port); BSOCK *bsock = (BSOCK *)malloc(sizeof(BSOCK)); memset(bsock, 0, sizeof(BSOCK)); bsock->m_fd = sockfd; bsock->tls = NULL; bsock->errors = 0; bsock->m_blocking = 1; bsock->msg = get_pool_memory(PM_BSOCK); bsock->errmsg = get_pool_memory(PM_MESSAGE); bsock->set_who(bstrdup(who)); bsock->set_host(bstrdup(host)); bsock->set_port(port); memset(&bsock->peer_addr, 0, sizeof(bsock->peer_addr)); memcpy(&bsock->client_addr, client_addr, sizeof(bsock->client_addr)); bsock->timeout = BSOCK_TIMEOUT; bsock->set_jcr(jcr); return bsock; }
/* Store reader info */ static void store_plugin(LEX *lc, RES_ITEM *item, int index, int pass) { lex_get_token(lc, T_NAME); if (pass == 1) { /* * Pickup plugin command */ res_incexe.current_opts->plugin = bstrdup(lc->str); } scan_to_eol(lc); }
/* Store Base info */ static void store_base(LEX *lc, RES_ITEM *item, int index, int pass) { lex_get_token(lc, T_NAME); if (pass == 1) { /* * Pickup Base Job Name */ res_incexe.current_opts->base.append(bstrdup(lc->str)); } scan_to_eol(lc); }
/* * Build or rebuild whitelist */ int websBuildWhitelist(void) { if (websDefaultDir == NULL || *websDefaultDir == '\0') { return -1; } websDeleteWhitelistRecursive(whitelist); whitelist = balloc(B_L, sizeof(fileNode_t)); memset(whitelist, 0x0, sizeof(fileNode_t)); whitelist->name = bstrdup(B_L, "/"); whitelist->flags |= WHITELIST_DIR; return websBuildWhitelistRecursive(websDefaultDir, whitelist, 0); }
/* * Store a directory name at specified address. Note, we do * shell expansion except if the string begins with a vertical * bar (i.e. it will likely be passed to the shell later). */ void store_dir(LEX *lc, RES_ITEM *item, int index, int pass) { lex_get_token(lc, T_STRING); if (pass == 1) { if (lc->str[0] != '|') { do_shell_expansion(lc->str, sizeof(lc->str)); } *(item->value) = bstrdup(lc->str); } scan_to_eol(lc); set_bit(index, res_all.hdr.item_present); }
/** * Update an entry in the cache. * This function should be called with a write lock on the mntent_cache. */ static mntent_cache_entry_t *update_mntent_mapping(uint32_t dev, const char *special, const char *mountpoint, const char *fstype, const char *mntopts) { mntent_cache_entry_t lookup, *mce; lookup.dev = dev; mce = (mntent_cache_entry_t *)mntent_cache_entries->binary_search(&lookup, compare_mntent_mapping); if (mce) { /* * See if the info changed. */ if (!bstrcmp(mce->special, special)) { free(mce->special); mce->special = bstrdup(special); } if (!bstrcmp(mce->mountpoint, mountpoint)) { free(mce->mountpoint); mce->mountpoint = bstrdup(mountpoint); } if (!bstrcmp(mce->fstype, fstype)) { free(mce->fstype); mce->fstype = bstrdup(fstype); } if (!bstrcmp(mce->mntopts, mntopts)) { free(mce->mntopts); mce->mntopts = bstrdup(mntopts); } } else { mce = add_mntent_mapping(dev, special, mountpoint, fstype, mntopts); } mce->validated = true; return mce; }
/** * Update the capture with changed settings */ static void xshm_update(void *vptr, obs_data_t *settings) { XSHM_DATA(vptr); xshm_capture_stop(data); data->screen_id = obs_data_get_int(settings, "screen"); data->show_cursor = obs_data_get_bool(settings, "show_cursor"); data->advanced = obs_data_get_bool(settings, "advanced"); data->server = bstrdup(obs_data_get_string(settings, "server")); xshm_capture_start(data); }
int main() { FILESET *fileset; char buf[30]; alist *mlist; fileset = (FILESET *)malloc(sizeof(FILESET)); memset(fileset, 0, sizeof(FILESET)); fileset->mylist.init(); printf("Manual allocation/destruction of list:\n"); for (int i=0; i<20; i++) { sprintf(buf, "This is item %d", i); fileset->mylist.append(bstrdup(buf)); } for (int i=0; i< fileset->mylist.size(); i++) { printf("Item %d = %s\n", i, (char *)fileset->mylist[i]); } fileset->mylist.destroy(); free(fileset); printf("Allocation/destruction using new delete\n"); mlist = new alist(10); for (int i=0; i<20; i++) { sprintf(buf, "This is item %d", i); mlist->append(bstrdup(buf)); } for (int i=0; i< mlist->size(); i++) { printf("Item %d = %s\n", i, (char *)mlist->get(i)); } delete mlist; sm_dump(false); /* test program */ }
char *GetProduct(void) { char *product; product = strrchr(GetCommandLine(), ' '); if (product && strlen(product + 1) > 0) return bstrdup(++product); else { DisplayError("This program should be called with a product ID", FALSE, TRUE); ExitProcess(1); } }
/** * Add a new entry to the cache. * This function should be called with a write lock on the mntent_cache. */ static mntent_cache_entry_t *add_mntent_mapping(uint32_t dev, const char *special, const char *mountpoint, const char *fstype, const char *mntopts) { mntent_cache_entry_t *mce; mce = (mntent_cache_entry_t *)malloc(sizeof(mntent_cache_entry_t)); memset(mce, 0, sizeof(mntent_cache_entry_t)); mce->dev = dev; mce->special = bstrdup(special); mce->mountpoint = bstrdup(mountpoint); mce->fstype = bstrdup(fstype); if (mntopts) { mce->mntopts = bstrdup(mntopts); } mntent_cache_entries->binary_insert(mce, compare_mntent_mapping); return mce; }
/* Store exclude directory containing info */ static void store_excludedir(LEX *lc, RES_ITEM2 *item, int index, int pass, bool exclude) { if (exclude) { scan_err0(lc, _("ExcludeDirContaining directive not permitted in Exclude.\n")); /* NOT REACHED */ } lex_get_token(lc, T_NAME); if (pass == 1) { res_incexe.ignoredir = bstrdup(lc->str); } scan_to_eol(lc); }
static int control(stream_t *s, int cmd, void *arg) { struct priv *p = s->priv; switch(cmd) { case STREAM_CTRL_SET_CONTENTS: ; bstr *data = (bstr *)arg; talloc_free(p->data.start); p->data = bstrdup(s, *data); s->end_pos = p->data.len; return 1; } return STREAM_UNSUPPORTED; }
/* * Store a password at specified address in MD5 coding */ static void store_md5password(LEX *lc, RES_ITEM *item, int index, int pass) { s_password *pwd; URES *res_all = (URES *)my_config->m_res_all; lex_get_token(lc, T_STRING); if (pass == 1) { pwd = item->pwdvalue; if (pwd->value) { free(pwd->value); } /* * See if we are parsing an MD5 encoded password already. */ if (bstrncmp(lc->str, "[md5]", 5)) { pwd->encoding = p_encoding_md5; pwd->value = bstrdup(lc->str + 5); } else { unsigned int i, j; struct MD5Context md5c; unsigned char digest[CRYPTO_DIGEST_MD5_SIZE]; char sig[100]; MD5Init(&md5c); MD5Update(&md5c, (unsigned char *) (lc->str), lc->str_len); MD5Final(digest, &md5c); for (i = j = 0; i < sizeof(digest); i++) { sprintf(&sig[j], "%02x", digest[i]); j += 2; } pwd->encoding = p_encoding_md5; pwd->value = bstrdup(sig); } } scan_to_eol(lc); set_bit(index, res_all->hdr.item_present); }
/* * Add all possible FileIndexes to the list of BootStrap records. * Here we are only dealing with JobId's and the FileIndexes * associated with those JobIds. */ void add_findex_all(RBSR *bsr, uint32_t JobId) { RBSR *nbsr; RBSR_FINDEX *fi; if (bsr->fi == NULL) { /* if no FI add one */ /* This is the first FileIndex item in the chain */ bsr->fi = new_findex(); bsr->JobId = JobId; bsr->fi->findex = 1; bsr->fi->findex2 = INT32_MAX; return; } /* Walk down list of bsrs until we find the JobId */ if (bsr->JobId != JobId) { for (nbsr=bsr->next; nbsr; nbsr=nbsr->next) { if (nbsr->JobId == JobId) { bsr = nbsr; break; } } if (!nbsr) { /* Must add new JobId */ /* Add new JobId at end of chain */ for (nbsr=bsr; nbsr->next; nbsr=nbsr->next) { } nbsr->next = new_bsr(); nbsr->next->JobId = JobId; /* If we use regexp to restore, set it for each jobid */ if (bsr->fileregex) { nbsr->next->fileregex = bstrdup(bsr->fileregex); } nbsr->next->fi = new_findex(); nbsr->next->fi->findex = 1; nbsr->next->fi->findex2 = INT32_MAX; return; } } /* * At this point, bsr points to bsr containing this JobId, * and we are sure that there is at least one fi record. */ fi = bsr->fi; fi->findex = 1; fi->findex2 = INT32_MAX; return; }
/* * This gets the client name from which the backup was made */ static bool get_client_name(UAContext *ua, RESTORE_CTX *rx) { int i; CLIENT_DBR cr; memset(&cr, 0, sizeof(cr)); /* * If no client name specified yet, get it now */ if (!rx->ClientName) { /* * Try command line argument */ i = find_arg_with_value(ua, NT_("client")); if (i < 0) { i = find_arg_with_value(ua, NT_("backupclient")); } if (i >= 0) { if (!is_name_valid(ua->argv[i], ua->errmsg)) { ua->error_msg("%s argument: %s", ua->argk[i], ua->errmsg); return false; } bstrncpy(cr.Name, ua->argv[i], sizeof(cr.Name)); if (!db_get_client_record(ua->jcr, ua->db, &cr)) { ua->error_msg("invalid %s argument: %s\n", ua->argk[i], ua->argv[i]); return false; } rx->ClientName = bstrdup(ua->argv[i]); return true; } if (!get_client_dbr(ua, &cr)) { return false; } rx->ClientName = bstrdup(cr.Name); } return true; }
int websUrlHandlerDefine(char_t *urlPrefix, char_t *webDir, int arg, int (*handler)(webs_t wp, char_t *urlPrefix, char_t *webdir, int arg, char_t *url, char_t *path, char_t *query), int flags) { websUrlHandlerType *sp; int len; a_assert(urlPrefix); a_assert(handler); /* * Grow the URL handler array to create a new slot */ len = (websUrlHandlerMax + 1) * sizeof(websUrlHandlerType); if ((websUrlHandler = brealloc(B_L, websUrlHandler, len)) == NULL) { return -1; } sp = &websUrlHandler[websUrlHandlerMax++]; memset(sp, 0, sizeof(websUrlHandlerType)); sp->urlPrefix = bstrdup(B_L, urlPrefix); sp->len = gstrlen(sp->urlPrefix); if (webDir) { sp->webDir = bstrdup(B_L, webDir); } else { sp->webDir = bstrdup(B_L, T("")); } sp->handler = handler; sp->arg = arg; sp->flags = flags; /* * Sort in decreasing URL length order observing the flags for first and last */ qsort(websUrlHandler, websUrlHandlerMax, sizeof(websUrlHandlerType), websUrlHandlerSort); return 0; }