ソースを参照

Unfinished srp_edit()

Serj Kalichev 1 年間 前
コミット
2c3cfec89a
1 ファイル変更68 行追加0 行削除
  1. 68 0
      src/syms.c

+ 68 - 0
src/syms.c

@@ -278,3 +278,71 @@ cleanup:
 
 	return ret;
 }
+
+
+int srp_edit(kcontext_t *context)
+{
+	int ret = 0;
+	faux_argv_t *args = NULL;
+	pline_t *pline = NULL;
+	sr_conn_ctx_t *conn = NULL;
+	sr_session_ctx_t *sess = NULL;
+	pexpr_t *expr = NULL;
+	size_t err_num = 0;
+	faux_argv_t *cur_path = NULL;
+
+	assert(context);
+
+	if (sr_connect(SR_CONN_DEFAULT, &conn))
+		return -1;
+	if (sr_session_start(conn, SR_DS_RUNNING, &sess)) {
+		sr_disconnect(conn);
+		return -1;
+	}
+
+	cur_path = (faux_argv_t *)kplugin_udata(kcontext_plugin(context));
+
+	args = param2argv(kcontext_pargv(context), "path");
+	pline = pline_parse(sess, args, 0);
+
+	if (pline->invalid) {
+		fprintf(stderr, "Invalid 'edit' request\n");
+		ret = -1;
+		goto cleanup;
+	}
+
+	if (faux_list_len(pline->exprs) > 1) {
+		fprintf(stderr, "Can't process more than one object\n");
+		ret = -1;
+		goto cleanup;
+	}
+
+	expr = (pexpr_t *)faux_list_data(faux_list_head(pline->exprs));
+
+	if (!(expr->pat & PT_EDIT)) {
+		fprintf(stderr, "Illegal expression for 'edit' operation\n");
+		ret = -1;
+		goto cleanup;
+	}
+
+	if (sr_set_item_str(sess, expr->xpath, NULL, NULL, 0) != SR_ERR_OK) {
+		fprintf(stderr, "Can't set editing data\n");
+		ret = -1;
+		goto cleanup;
+	}
+	sr_apply_changes(sess, 0);
+
+	if (sr_delete_item(sess, expr->xpath, 0) != SR_ERR_OK) {
+		fprintf(stderr, "Can't delete data\n");
+		ret = -1;
+		goto cleanup;
+	}
+
+cleanup:
+	if (ret < 0)
+		faux_argv_free(args);
+	pline_free(pline);
+	sr_disconnect(conn);
+
+	return ret;
+}