1#include "dmt.hpp"
2
3#include <stdlib.h>
4#include <stdio.h>
5#include <unistd.h>
6
7
8#include "plugin/dmtPlugin.hpp"
9
10#define Debug printf
11//#define Debug //
12
13//---------------------------Declaration----------------------
14
15extern "C"
16SYNCML_DM_RET_STATUS_T DMT_PluginLib_Execute2(
17	const char * path,
18	DMMap<DMString, DMString> & mapParameters,
19	const char * args,
20   CPCHAR szCorrelator,
21	PDmtTree tree,
22	DMString & results
23)
24{
25   if (args==NULL || strlen(args)==0 )
26   {
27      Debug("No arguments\n");
28      results += ("No argument specified");
29      return SYNCML_DM_SUCCESS;
30   }
31
32   Debug("execute path=%s args=%s\n", path, args);
33
34   DMString cmd;
35   cmd=args;
36   cmd += " > ";
37
38   //cmd += "/tmp/dmt_execute_result.txt";
39   char tmpn[100]="/tmp/dmt_execute_";
40   //strcat(tmpn,tmpnam(NULL));
41   tmpnam(tmpn);
42   //Debug("tmpn=%s\n", tmpn);
43
44   cmd += tmpn;
45
46   //int res=system(args);
47   int res=system(cmd.c_str());
48   //Debug("res=%d\n", res);
49
50   //char  resstr[20];
51   //sprintf(resstr, "res=%d\n", res);
52   //results.append(resstr);
53
54   FILE * fp=fopen(tmpn, "r+b");
55   if (fp!=NULL)
56   {
57      //Debug("fp=0x%x\n", fp);
58      char buf[1024];
59      int n=fread(buf, 1, sizeof(buf)-1, fp);
60      buf[n]=0;
61      //Debug("bytes read=%d\n", n);
62      if (n>=0)
63      {
64         results += (buf);
65         //std::string s(buf);
66         //results=s;
67      }
68      fclose(fp);
69
70      //
71      unlink(tmpn);
72   } else
73   {
74      results += ("No result");
75   }
76   return SYNCML_DM_SUCCESS;
77
78}
79
80
81extern "C"
82int DMT_PluginLib_GetAPIVersion(void)
83{
84   return DMT_PLUGIN_VERSION_1_1;
85}
86
87