File:  [ELWIX - Embedded LightWeight unIX -] / mqtt / src / Attic / mqtt.c
Revision 1.1.1.1.2.19: download - view: text, annotated - select for diffs - revision graph
Thu Dec 8 17:02:25 2011 UTC (12 years, 6 months ago) by misho
Branches: mqtt1_0
Diff to: branchpoint 1.1.1.1: preferred, unified
add new fields in db
patch modules for use it
and patch tests

    1: #include "global.h"
    2: #include "rtlm.h"
    3: 
    4: 
    5: sl_config cfg;
    6: 
    7: 
    8: int
    9: main(int argc, char **argv)
   10: {
   11: 	sqlite3 *acc = NULL, *pub = NULL;
   12: 	FILE *logg = NULL;
   13: 	int ret = 0;
   14: 	mqtt_subscr_t *s, *p;
   15: 
   16: 	if (LoadConfig("/etc/mqtt.conf", &cfg)) {
   17: 		printf("Error:: Load config #%d - %s\n", cfg_GetErrno(), cfg_GetError());
   18: 		return 1;
   19: 	}
   20: 	if (!mqttLoadRTLM(&cfg, 0)) {
   21: 		printf("Error:: Can't load RTL ACC module\n");
   22: 		UnloadConfig(&cfg);
   23: 		return 2;
   24: 	}
   25: 	if (!mqttLoadRTLM(&cfg, 1)) {
   26: 		printf("Error:: Can't load RTL PUB module\n");
   27: 		mqttUnloadRTLM(0);
   28: 		UnloadConfig(&cfg);
   29: 		return 2;
   30: 	}
   31: 	if (!mqttLoadRTLM(&cfg, 2)) {
   32: 		printf("Error:: Can't load RTL LOG module\n");
   33: 		mqttUnloadRTLM(1);
   34: 		mqttUnloadRTLM(0);
   35: 		UnloadConfig(&cfg);
   36: 		return 2;
   37: 	}
   38: 
   39: 	acc = call.OpenACC(&cfg);
   40: 	if (!acc)
   41: 		goto end;
   42: 	pub = call.OpenPUB(&cfg);
   43: 	if (!pub)
   44: 		goto end;
   45: 	logg = call.OpenLOG(&cfg);
   46: 	if (!logg)
   47: 		goto end;
   48: 
   49: 	if (mqttMkDir(&cfg)) {
   50: 		printf("Error:: in statedir #%d - %s\n", errno, strerror(errno));
   51: 		goto end;
   52: 	}
   53: 
   54: 	call.LOG(logg, "success!\n");
   55: 	if ((ret = call.LoginACC(&cfg, acc, "misho", "test123")) == -1) {
   56: 		printf("Error:: Authentication problem\n");
   57: 		goto end;
   58: 	} else
   59: 		call.LOG(logg, "Login: %s\n", ret ? "ALLOW" : "DENIED");
   60: 
   61: 	if ((ret = call.InitSessPUB(&cfg, pub, "misho", "doophenschmerz", "127.0.0.1", 12345, 1, 
   62: 					"Topic43", "mmm", 2, 0)) == -1) {
   63: 		printf("Error:: Session init problem\n");
   64: 		goto end;
   65: 	} else
   66: 		call.LOG(logg, "InitSess: %d\n", ret);
   67: 
   68: 	if ((ret = call.ChkSessPUB(&cfg, pub, "misho", "doophenschmerz", "127.0._.%")) == -1) {
   69: 		printf("Error:: Session check problem\n");
   70: 		goto end;
   71: 	} else
   72: 		call.LOG(logg, "ChkSess: %d\n", ret);
   73: 
   74: 	if ((ret = call.DeletePUB(&cfg, pub, 10, "%", "%", "%", -1)) == -1) {
   75: 		printf("Error:: Clear problem\n");
   76: 		goto end;
   77: 	} else
   78: 		call.LOG(logg, "Clear: %d\n", ret);
   79: 
   80: 	if ((ret = call.WritePUB(&cfg, pub, 10, "oho/boho", "MRYN    \n tryn brymbryn", "misho", "1.1.1.1", 1)) == -1) {
   81: 		printf("Error:: Publish problem\n");
   82: 		goto end;
   83: 	} else
   84: 		call.LOG(logg, "Publish: %d\n", ret);
   85: 	if ((ret = call.WritePUB(&cfg, pub, 11, "boh", "testing", "misho", "1.1.1.2", 0)) == -1) {
   86: 		printf("Error:: Publish problem\n");
   87: 		goto end;
   88: 	} else
   89: 		call.LOG(logg, "Publish: %d\n", ret);
   90: 	if (!(s = call.ReadPUB(&cfg, pub, 10, "%", -1))) {
   91: 		printf("Error:: Subscribe problem\n");
   92: 		goto end;
   93: 	} else {
   94: 		call.LOG(logg, "Subscribe: %p\n", s);
   95: 		for (p = s; p->sub_topic._base; p++) {
   96: 			printf("Retain=%d Topic(%d)=%s Value(%d)=%s\n", p->sub_ret, 
   97: 					p->sub_topic._size, p->sub_topic._base, 
   98: 					p->sub_value._size, p->sub_value._base);
   99: 		}
  100: 		mqtt_subFree(&s);
  101: 	}
  102: 	if ((ret = call.DeletePUB(&cfg, pub, 11, "boh", "misho", "1.1.1._", 0)) == -1) {
  103: 		printf("Error:: Delete problem\n");
  104: 		goto end;
  105: 	} else
  106: 		call.LOG(logg, "Delete: %d\n", ret);
  107: 
  108: 	if ((ret = call.FiniSessPUB(&cfg, pub, "misho", "doophenschmerz", "127.0._.1%")) == -1) {
  109: 		printf("Error:: Session fini problem\n");
  110: 		goto end;
  111: 	} else
  112: 		call.LOG(logg, "FiniSess: %d\n", ret);
  113: 
  114: end:
  115: 	call.CloseLOG(logg);
  116: 	call.ClosePUB(pub);
  117: 	call.CloseACC(acc);
  118: 	mqttUnloadRTLM(2);
  119: 	mqttUnloadRTLM(1);
  120: 	mqttUnloadRTLM(0);
  121: 	UnloadConfig(&cfg);
  122: 	return 0;
  123: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>